|
| 1 | +const yaml = require('js-yaml'); |
| 2 | +const rss = require('@11ty/eleventy-plugin-rss'); |
| 3 | +const { DateTime } = require('luxon'); |
| 4 | + |
| 5 | +module.exports = function(eleventyConfig) { |
| 6 | + const assets = ['js', 'css', 'fonts', 'img', 'odx-assets', 'admin']; |
| 7 | + |
| 8 | + for (const folder of assets) { |
| 9 | + eleventyConfig.addPassthroughCopy({ [`static/${folder}`]: folder }); |
| 10 | + } |
| 11 | + |
| 12 | + eleventyConfig.addPlugin(rss); |
| 13 | + |
| 14 | + eleventyConfig.addPassthroughCopy({ 'static/*.*': '.' }); |
| 15 | + |
| 16 | + eleventyConfig.addDataExtension('yaml', (contents) => |
| 17 | + yaml.safeLoad(contents), |
| 18 | + ); |
| 19 | + |
| 20 | + eleventyConfig.addNunjucksFilter('dateformat', (date, format) => { |
| 21 | + return DateTime.fromJSDate(date, { zone: 'utc' }).toFormat(format); |
| 22 | + }); |
| 23 | + |
| 24 | + eleventyConfig.addFilter('dateslug', (date) => { |
| 25 | + return DateTime.fromJSDate(date, { zone: 'utc' }).toFormat('yyyy/LL'); |
| 26 | + }); |
| 27 | + |
| 28 | + eleventyConfig.addNunjucksFilter('published', (posts) => { |
| 29 | + return posts.filter((post) => post.data.published); |
| 30 | + }); |
| 31 | + |
| 32 | + eleventyConfig.addNunjucksFilter('limit', (posts, num) => { |
| 33 | + return posts.slice(0, num); |
| 34 | + }); |
| 35 | + |
| 36 | + eleventyConfig.addNunjucksFilter('featuredEvent', (posts) => { |
| 37 | + // return a featured event or the first one |
| 38 | + return posts.find(({ data }) => data.featured) || posts[0]; |
| 39 | + }); |
| 40 | + |
| 41 | + // redirect collection |
| 42 | + eleventyConfig.addCollection('redirects', function(collection) { |
| 43 | + const redirs = collection.getAll().filter(({ data }) => data.redirect_from); |
| 44 | + const redirects = new Map(); |
| 45 | + for (item of redirs) { |
| 46 | + let { redirect_from } = item.data; |
| 47 | + if (!Array.isArray(redirect_from)) { |
| 48 | + redirect_from = [redirect_from]; |
| 49 | + } |
| 50 | + redirect_from.forEach((from) => { |
| 51 | + redirects.set(from, { |
| 52 | + from, |
| 53 | + to: item.url, |
| 54 | + }); |
| 55 | + }); |
| 56 | + } |
| 57 | + return [...redirects.values()]; |
| 58 | + }); |
| 59 | + |
| 60 | + return { |
| 61 | + htmlTemplateEngine: 'njk', |
| 62 | + dir: { |
| 63 | + includes: '_includes', |
| 64 | + layouts: '_layouts', |
| 65 | + input: 'src', |
| 66 | + output: '_site', |
| 67 | + }, |
| 68 | + }; |
| 69 | +}; |
0 commit comments