|
| 1 | +const { DateTime, Settings } = require("luxon"); |
| 2 | +const fs = require("fs"); |
| 3 | +const pluginRss = require("@11ty/eleventy-plugin-rss"); |
| 4 | +const readingTime = require('eleventy-plugin-reading-time'); |
| 5 | +const path = require("path"); |
| 6 | + |
| 7 | +Settings.defaultLocale = 'en-US'; |
| 8 | + |
| 9 | + |
| 10 | +module.exports = function (eleventyConfig) { |
| 11 | + eleventyConfig.addPlugin(pluginRss); |
| 12 | + eleventyConfig.addPlugin(readingTime); |
| 13 | + |
| 14 | + eleventyConfig.setDataDeepMerge(true); |
| 15 | + |
| 16 | + eleventyConfig.addFilter("readableDate", dateObj => { |
| 17 | + if (dateObj instanceof String) { |
| 18 | + dateObj = new Date(dateObj); |
| 19 | + } |
| 20 | + return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat("dd LLLL yyyy"); |
| 21 | + }); |
| 22 | + |
| 23 | + eleventyConfig.addFilter("toISOString", dateObj => { |
| 24 | + if (dateObj instanceof String) { |
| 25 | + dateObj = new Date(dateObj) |
| 26 | + } |
| 27 | + return dateObj.toISOString(); |
| 28 | + }); |
| 29 | + |
| 30 | + eleventyConfig.addFilter("getTime", dateObj => { |
| 31 | + if (dateObj instanceof String) { |
| 32 | + dateObj = new Date(dateObj) |
| 33 | + } |
| 34 | + return dateObj.getTime(); |
| 35 | + }); |
| 36 | + |
| 37 | + // https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string |
| 38 | + eleventyConfig.addFilter('htmlDateString', dateObj => { |
| 39 | + return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd'); |
| 40 | + }); |
| 41 | + |
| 42 | + eleventyConfig.addFilter('slugDate', dateObj => { |
| 43 | + return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy/LL/dd'); |
| 44 | + }) |
| 45 | + |
| 46 | + // Get the first `n` elements of a collection. |
| 47 | + eleventyConfig.addFilter("head", (array, n) => { |
| 48 | + if (n < 0) { |
| 49 | + return array.slice(n); |
| 50 | + } |
| 51 | + |
| 52 | + return array.slice(0, n); |
| 53 | + }); |
| 54 | + |
| 55 | + // Filter source file names using a glob |
| 56 | + |
| 57 | + eleventyConfig.addPassthroughCopy("img"); |
| 58 | + eleventyConfig.addPassthroughCopy("css"); |
| 59 | + eleventyConfig.addPassthroughCopy('robots.txt') |
| 60 | + eleventyConfig.addPassthroughCopy('humans.txt') |
| 61 | + eleventyConfig.addPassthroughCopy('manifest.json') |
| 62 | + eleventyConfig.addPassthroughCopy('.well-known') |
| 63 | + |
| 64 | + // Browsersync Overrides |
| 65 | + eleventyConfig.setBrowserSyncConfig({ |
| 66 | + callbacks: { |
| 67 | + ready: function (err, browserSync) { |
| 68 | + // browserSync.addMiddleware("*", (req, res) => { |
| 69 | + // const content_404 = fs.readFileSync('_site/404.html')); |
| 70 | + // res.writeHead(404, { "ContentType": "text/html; charset=UTF-8" }) |
| 71 | + // res.write(content_404); |
| 72 | + // res.end(); |
| 73 | + // }); |
| 74 | + }, |
| 75 | + }, |
| 76 | + ui: false, |
| 77 | + ghostMode: false |
| 78 | + }); |
| 79 | + |
| 80 | + return { |
| 81 | + templateFormats: [ |
| 82 | + "md", |
| 83 | + "njk", |
| 84 | + "html", |
| 85 | + "liquid" |
| 86 | + ], |
| 87 | + |
| 88 | + // If your site lives in a different subdirectory, change this. |
| 89 | + // Leading or trailing slashes are all normalized away, so don’t worry about those. |
| 90 | + |
| 91 | + // If you don’t have a subdirectory, use "" or "/" (they do the same thing) |
| 92 | + // This is only used for link URLs (it does not affect your file structure) |
| 93 | + // Best paired with the `url` filter: https://www.11ty.io/docs/filters/url/ |
| 94 | + |
| 95 | + // You can also pass this in on the command line using `--pathprefix` |
| 96 | + // pathPrefix: "/", |
| 97 | + |
| 98 | + markdownTemplateEngine: "njk", |
| 99 | + htmlTemplateEngine: "njk", |
| 100 | + dataTemplateEngine: "njk", |
| 101 | + |
| 102 | + // These are all optional, defaults are shown: |
| 103 | + dir: { |
| 104 | + input: ".", |
| 105 | + includes: "_includes", |
| 106 | + data: "_data", |
| 107 | + output: "_site" |
| 108 | + } |
| 109 | + }; |
| 110 | +}; |
0 commit comments