|
1 | 1 |
|
2 | 2 | module.exports = function (eleventyConfig) { |
3 | 3 |
|
| 4 | + |
| 5 | + const now = Date.now(); |
| 6 | + const livePosts = (post) => post.date <= now; |
| 7 | + |
| 8 | + eleventyConfig.addFilter("tagsList", (arr = []) => { |
| 9 | + const tagsSet = new Set(); |
| 10 | + arr.forEach((item) => item.data.tags?.forEach((tag) => tagsSet.add(tag))); |
| 11 | + return [...tagsSet].sort((b, a) => b.localeCompare(a)); |
| 12 | + }); |
| 13 | + |
| 14 | + eleventyConfig.addFilter("inspect", require("util").inspect); |
| 15 | + |
| 16 | + |
| 17 | + |
4 | 18 | // SIGHTS - custom collections |
5 | | - const nowsights = new Date(); |
6 | | - const sightslivePosts = (post) => post.date <= nowsights; |
| 19 | + |
7 | 20 | eleventyConfig.addCollection("sights", (collection) => { |
8 | | - return [ |
9 | | - ...collection.getFilteredByGlob("./sights/*.njk").filter(sightslivePosts), |
10 | | - ].reverse(); |
| 21 | + const posts = collection.getFilteredByGlob("./sights/*.njk"); |
| 22 | + return [...posts].filter(livePosts).reverse(); |
11 | 23 | }); |
12 | 24 |
|
13 | 25 | // SOUNDS - custom collections |
14 | | - const nowsounds = new Date(); |
15 | | - const soundslivePosts = (post) => post.date <= nowsounds; |
| 26 | + |
16 | 27 | eleventyConfig.addCollection("sounds", (collection) => { |
17 | | - return [ |
18 | | - ...collection.getFilteredByGlob("./sounds/*.njk").filter(soundslivePosts), |
19 | | - ].reverse(); |
| 28 | + const posts = collection.getFilteredByGlob("./sounds/*.njk"); |
| 29 | + return [...posts].filter(livePosts).reverse(); |
20 | 30 | }); |
21 | 31 |
|
22 | 32 | // generate a list of all tags collections |
23 | 33 | // with alphabetical sorting - had to invert to "b, a" because it was sorting upside down |
24 | | - eleventyConfig.addCollection('tagsList', (collectionApi) => { |
25 | | - const tagsSet = new Set() |
26 | | - collectionApi.getAll().forEach((item) => { |
27 | | - if (!item.data.tags) return |
28 | | - item.data.tags.forEach((tag) => tagsSet.add(tag)) |
29 | | - }) |
30 | | - return [...tagsSet].sort((b, a) => b.localeCompare(a)) |
| 34 | + eleventyConfig.addCollection("sightsTagsList", (collection) => { |
| 35 | + const tagsListFilter = eleventyConfig.getFilter("tagsList"); |
| 36 | + const items = collection |
| 37 | + .getFilteredByGlob("./sights/*.njk") |
| 38 | + .filter(livePosts); |
| 39 | + return tagsListFilter(items); |
31 | 40 | }); |
32 | 41 |
|
33 | 42 |
|
34 | | -// https://www.11ty.dev/docs/copy/#manual-passthrough-file-copy-(faster) |
35 | | -eleventyConfig.addPassthroughCopy('assets'); |
36 | | -eleventyConfig.addPassthroughCopy('sitemap.xml'); |
37 | | -eleventyConfig.addPassthroughCopy('robots.txt'); |
| 43 | + eleventyConfig.addCollection("soundsTagsList", (collection) => { |
| 44 | + const tagsListFilter = eleventyConfig.getFilter("tagsList"); |
| 45 | + const items = collection |
| 46 | + .getFilteredByGlob("./sounds/*.njk") |
| 47 | + .filter(livePosts); |
| 48 | + return tagsListFilter(items); |
| 49 | + }); |
38 | 50 |
|
39 | 51 |
|
40 | | -// format dates on SIGHTS and SOUNDS Articles |
41 | | -const dateformat = require('./lib/filters/dateformat'); |
42 | | -eleventyConfig.addFilter('datefriendly', dateformat.friendly); |
43 | | -eleventyConfig.addFilter('dateymd', dateformat.ymd); |
| 52 | + eleventyConfig.addFilter("head", (arr = [], idx = 0) => { |
| 53 | + if (idx < 0) { |
| 54 | + return arr.slice(idx); |
| 55 | + } |
| 56 | + return arr.slice(0, idx); |
| 57 | + }); |
44 | 58 |
|
45 | 59 |
|
46 | | -// "return" in order to keep the previously entered configuration values |
47 | | -// taken from: https://github.com/11ty/eleventy-base-blog/blob/master/.eleventy.js |
48 | | -return { |
49 | | - // Control which files Eleventy will process |
50 | | - // e.g.: *.md, *.njk, *.html, *.liquid |
51 | | - templateFormats: [ |
52 | | - "md", |
53 | | - "njk", |
54 | | - "html", |
55 | | - "liquid" |
56 | | - ], |
| 60 | + // https://www.11ty.dev/docs/copy/#manual-passthrough-file-copy-(faster) |
| 61 | + eleventyConfig.addPassthroughCopy("assets"); |
| 62 | + eleventyConfig.addPassthroughCopy("sitemap.xml"); |
| 63 | + eleventyConfig.addPassthroughCopy("robots.txt"); |
57 | 64 |
|
58 | | -// added |
59 | | - passthroughFileCopy: true, |
| 65 | + // format dates on SIGHTS and SOUNDS Articles |
| 66 | + const dateformat = require("./lib/filters/dateformat"); |
| 67 | + eleventyConfig.addFilter("datefriendly", dateformat.friendly); |
| 68 | + eleventyConfig.addFilter("dateymd", dateformat.ymd); |
60 | 69 |
|
61 | | - // ----------------------------------------------------------------- |
62 | | - // If your site deploys to a subdirectory, change `pathPrefix`. |
63 | | - // Don’t worry about leading and trailing slashes, we normalize these. |
| 70 | + // "return" in order to keep the previously entered configuration values |
| 71 | + // taken from: https://github.com/11ty/eleventy-base-blog/blob/master/.eleventy.js |
| 72 | + return { |
| 73 | + // Control which files Eleventy will process |
| 74 | + // e.g.: *.md, *.njk, *.html, *.liquid |
| 75 | + templateFormats: ["md", "njk", "html", "liquid"], |
64 | 76 |
|
65 | | - // If you don’t have a subdirectory, use "" or "/" (they do the same thing) |
66 | | - // This is only used for link URLs (it does not affect your file structure) |
67 | | - // Best paired with the `url` filter: https://www.11ty.dev/docs/filters/url/ |
| 77 | + // added |
| 78 | + passthroughFileCopy: true, |
68 | 79 |
|
69 | | - // You can also pass this in on the command line using `--pathprefix` |
| 80 | + // ----------------------------------------------------------------- |
| 81 | + // If your site deploys to a subdirectory, change `pathPrefix`. |
| 82 | + // Don’t worry about leading and trailing slashes, we normalize these. |
70 | 83 |
|
71 | | - // Optional (default is shown) |
72 | | - pathPrefix: "/", |
73 | | - // ----------------------------------------------------------------- |
| 84 | + // If you don’t have a subdirectory, use "" or "/" (they do the same thing) |
| 85 | + // This is only used for link URLs (it does not affect your file structure) |
| 86 | + // Best paired with the `url` filter: https://www.11ty.dev/docs/filters/url/ |
74 | 87 |
|
75 | | - // Pre-process *.md files with: (default: `liquid`) |
76 | | - markdownTemplateEngine: "njk", |
| 88 | + // You can also pass this in on the command line using `--pathprefix` |
77 | 89 |
|
78 | | - // Pre-process *.html files with: (default: `liquid`) |
79 | | - htmlTemplateEngine: "njk", |
| 90 | + // Optional (default is shown) |
| 91 | + pathPrefix: "/", |
| 92 | + // ----------------------------------------------------------------- |
80 | 93 |
|
81 | | - // Opt-out of pre-processing global data JSON files: (default: `liquid`) |
82 | | - dataTemplateEngine: false, |
| 94 | + // Pre-process *.md files with: (default: `liquid`) |
| 95 | + markdownTemplateEngine: "njk", |
83 | 96 |
|
84 | | - // These are all optional (defaults are shown): |
85 | | - dir: { |
86 | | - input: ".", |
87 | | - includes: "_includes", |
88 | | - data: "_data", |
89 | | - output: "_site" |
90 | | - } |
91 | | -}; |
| 97 | + // Pre-process *.html files with: (default: `liquid`) |
| 98 | + htmlTemplateEngine: "njk", |
| 99 | + |
| 100 | + // Opt-out of pre-processing global data JSON files: (default: `liquid`) |
| 101 | + dataTemplateEngine: false, |
| 102 | + |
| 103 | + // These are all optional (defaults are shown): |
| 104 | + dir: { |
| 105 | + input: ".", |
| 106 | + includes: "_includes", |
| 107 | + data: "_data", |
| 108 | + output: "_site", |
| 109 | + }, |
| 110 | + }; |
92 | 111 | }; |
0 commit comments