2021-06-17 17:02:30 -06:00
|
|
|
|
const { DateTime } = require('luxon')
|
|
|
|
|
const fs = require('fs')
|
|
|
|
|
const markdownIt = require('markdown-it')
|
|
|
|
|
const markdownItAnchor = require('markdown-it-anchor')
|
2018-01-16 20:08:47 -07:00
|
|
|
|
|
2018-01-22 07:17:48 -07:00
|
|
|
|
module.exports = function(eleventyConfig) {
|
2019-11-11 15:22:08 -07:00
|
|
|
|
|
2021-03-17 09:29:29 -06:00
|
|
|
|
// https://www.11ty.dev/docs/data-deep-merge/
|
2021-06-17 17:02:30 -06:00
|
|
|
|
eleventyConfig.setDataDeepMerge(true)
|
2018-01-22 07:17:48 -07:00
|
|
|
|
|
2021-06-17 17:02:30 -06:00
|
|
|
|
eleventyConfig.addFilter('readableDate', dateObj => {
|
|
|
|
|
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('dd LLL yyyy')
|
|
|
|
|
})
|
2018-01-22 07:17:48 -07:00
|
|
|
|
|
2019-01-10 21:20:14 -07:00
|
|
|
|
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
|
|
|
|
|
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
|
2021-06-17 17:02:30 -06:00
|
|
|
|
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('yyyy-LL-dd')
|
|
|
|
|
})
|
2019-01-10 21:20:14 -07:00
|
|
|
|
|
2018-09-19 08:52:49 -06:00
|
|
|
|
// Get the first `n` elements of a collection.
|
2021-06-17 17:02:30 -06:00
|
|
|
|
eleventyConfig.addFilter('head', (array, n) => {
|
2018-09-29 23:09:09 -06:00
|
|
|
|
if( n < 0 ) {
|
2021-06-17 17:02:30 -06:00
|
|
|
|
return array.slice(n)
|
2018-09-29 23:09:09 -06:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-17 17:02:30 -06:00
|
|
|
|
return array.slice(0, n)
|
|
|
|
|
})
|
2018-09-19 08:52:49 -06:00
|
|
|
|
|
2021-03-17 09:29:29 -06:00
|
|
|
|
// Return the smallest number argument
|
2021-06-17 17:02:30 -06:00
|
|
|
|
eleventyConfig.addFilter('min', (...numbers) => {
|
|
|
|
|
return Math.min.apply(null, numbers)
|
|
|
|
|
})
|
2020-10-16 12:06:30 -06:00
|
|
|
|
|
2021-06-17 17:02:30 -06:00
|
|
|
|
eleventyConfig.addFilter('filterTagList', tags => {
|
2021-03-17 15:29:07 -06:00
|
|
|
|
// should match the list in tags.njk
|
2021-06-17 17:02:30 -06:00
|
|
|
|
return (tags || []).filter(tag => ['all', 'nav', 'post', 'posts'].indexOf(tag) === -1)
|
2021-03-17 15:29:07 -06:00
|
|
|
|
})
|
|
|
|
|
|
2021-06-20 11:43:16 -06:00
|
|
|
|
// Convert text to hex
|
|
|
|
|
eleventyConfig.addFilter('toHex', (str) => {
|
2021-10-23 22:18:42 -06:00
|
|
|
|
let hex = ''
|
|
|
|
|
for(let i=0; i<str.length; i++){
|
|
|
|
|
let h = str.codePointAt(i).toString(16)
|
|
|
|
|
if(h.length===1) h='0'+h
|
|
|
|
|
hex += h + ' '
|
|
|
|
|
if( h.length>4 ) i++
|
|
|
|
|
} return hex.trim()
|
|
|
|
|
})
|
2022-10-20 09:53:02 -06:00
|
|
|
|
|
2021-10-23 22:18:42 -06:00
|
|
|
|
// Fold lines
|
|
|
|
|
eleventyConfig.addFilter('fold', (str, size) => {
|
|
|
|
|
// https://stackoverflow.com/a/29202760/3006854
|
|
|
|
|
const numChunks = Math.ceil(str.length/size)
|
|
|
|
|
const chunks = new Array(numChunks)
|
|
|
|
|
for (let i = 0, o = 0; i < numChunks; ++i, o += size)
|
|
|
|
|
chunks[i] = str.substr(o, size)
|
|
|
|
|
return chunks.join('\n')
|
2021-06-20 11:43:16 -06:00
|
|
|
|
})
|
|
|
|
|
|
2021-03-17 09:29:29 -06:00
|
|
|
|
// Create an array of all tags
|
2021-06-17 17:02:30 -06:00
|
|
|
|
eleventyConfig.addCollection('tagList', function(collection) {
|
|
|
|
|
let tagSet = new Set()
|
2021-03-17 15:29:07 -06:00
|
|
|
|
collection.getAll().forEach(item => {
|
2021-06-17 17:02:30 -06:00
|
|
|
|
(item.data.tags || []).forEach(tag => tagSet.add(tag))
|
2021-10-23 22:18:42 -06:00
|
|
|
|
}); return [...tagSet]
|
2021-06-17 17:02:30 -06:00
|
|
|
|
})
|
2018-08-29 07:46:06 -06:00
|
|
|
|
|
2021-03-17 09:29:29 -06:00
|
|
|
|
// Customize Markdown library and settings:
|
2019-11-11 15:22:08 -07:00
|
|
|
|
let markdownLibrary = markdownIt({
|
2018-06-18 08:00:00 -06:00
|
|
|
|
html: true,
|
|
|
|
|
breaks: true,
|
|
|
|
|
linkify: true
|
2021-11-20 17:09:16 -07:00
|
|
|
|
})//.use(markdownItAnchor, {
|
|
|
|
|
// permalink: true,
|
|
|
|
|
// permalinkClass: "direct-link",
|
|
|
|
|
// permalinkSymbol: "#"
|
|
|
|
|
// })
|
2021-06-17 17:02:30 -06:00
|
|
|
|
eleventyConfig.setLibrary("md", markdownLibrary)
|
2018-06-18 08:00:00 -06:00
|
|
|
|
|
2021-03-17 09:29:29 -06:00
|
|
|
|
// Override Browsersync defaults (used only with --serve)
|
2019-01-31 06:14:06 -07:00
|
|
|
|
eleventyConfig.setBrowserSyncConfig({
|
|
|
|
|
callbacks: {
|
|
|
|
|
ready: function(err, browserSync) {
|
2022-10-20 09:53:02 -06:00
|
|
|
|
const content_404 = fs.readFileSync('_site/404.html')
|
2019-01-31 06:14:06 -07:00
|
|
|
|
|
|
|
|
|
browserSync.addMiddleware("*", (req, res) => {
|
|
|
|
|
// Provides the 404 content without redirect.
|
2021-06-17 17:02:30 -06:00
|
|
|
|
res.writeHead(404, {"Content-Type": "text/html charset=UTF-8"})
|
|
|
|
|
res.write(content_404)
|
|
|
|
|
res.end()
|
|
|
|
|
})
|
2019-06-18 09:22:58 -06:00
|
|
|
|
},
|
|
|
|
|
},
|
2020-01-03 10:30:27 -07:00
|
|
|
|
ui: false,
|
|
|
|
|
ghostMode: false
|
2021-06-17 17:02:30 -06:00
|
|
|
|
})
|
2019-01-31 06:14:06 -07:00
|
|
|
|
|
2018-01-22 07:17:48 -07:00
|
|
|
|
return {
|
2021-03-17 09:29:29 -06:00
|
|
|
|
// Control which files Eleventy will process
|
|
|
|
|
// e.g.: *.md, *.njk, *.html, *.liquid
|
2018-01-22 07:17:48 -07:00
|
|
|
|
templateFormats: [
|
2018-01-16 20:08:47 -07:00
|
|
|
|
"md",
|
|
|
|
|
"njk",
|
2021-06-17 17:02:30 -06:00
|
|
|
|
'html',
|
|
|
|
|
'liquid',
|
|
|
|
|
'css',
|
|
|
|
|
'png',
|
2021-06-18 19:42:56 -06:00
|
|
|
|
'webp',
|
2021-06-17 17:02:30 -06:00
|
|
|
|
'jpg',
|
|
|
|
|
'gif',
|
|
|
|
|
'js',
|
2021-06-17 20:35:39 -06:00
|
|
|
|
'crt',
|
2021-11-20 17:09:16 -07:00
|
|
|
|
'pem',
|
2021-11-21 09:47:23 -07:00
|
|
|
|
'ttf',
|
2021-06-21 18:01:11 -06:00
|
|
|
|
'webmanifest',
|
2018-01-16 20:08:47 -07:00
|
|
|
|
],
|
2018-01-22 07:17:48 -07:00
|
|
|
|
|
2021-03-17 09:29:29 -06:00
|
|
|
|
// -----------------------------------------------------------------
|
|
|
|
|
// If your site deploys to a subdirectory, change `pathPrefix`.
|
|
|
|
|
// Don’t worry about leading and trailing slashes, we normalize these.
|
2019-11-11 15:22:08 -07:00
|
|
|
|
|
2021-06-17 17:02:30 -06:00
|
|
|
|
// If you don’t have a subdirectory, use "" or "/' (they do the same thing)
|
2019-11-11 15:22:08 -07:00
|
|
|
|
// This is only used for link URLs (it does not affect your file structure)
|
2020-07-17 08:36:28 -06:00
|
|
|
|
// Best paired with the `url` filter: https://www.11ty.dev/docs/filters/url/
|
2019-11-11 15:22:08 -07:00
|
|
|
|
|
2020-01-02 19:51:47 -07:00
|
|
|
|
// You can also pass this in on the command line using `--pathprefix`
|
2018-01-22 07:17:48 -07:00
|
|
|
|
|
2021-03-17 09:29:29 -06:00
|
|
|
|
// Optional (default is shown)
|
2021-06-17 17:02:30 -06:00
|
|
|
|
pathPrefix: '/',
|
2021-03-17 09:29:29 -06:00
|
|
|
|
// -----------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// Pre-process *.md files with: (default: `liquid`)
|
2021-06-17 17:02:30 -06:00
|
|
|
|
markdownTemplateEngine: 'njk',
|
2021-03-17 09:29:29 -06:00
|
|
|
|
|
|
|
|
|
// Pre-process *.html files with: (default: `liquid`)
|
2021-06-17 17:02:30 -06:00
|
|
|
|
htmlTemplateEngine: 'njk',
|
2019-11-11 15:22:08 -07:00
|
|
|
|
|
2021-03-17 09:29:29 -06:00
|
|
|
|
// Opt-out of pre-processing global data JSON files: (default: `liquid`)
|
|
|
|
|
dataTemplateEngine: false,
|
|
|
|
|
|
|
|
|
|
// These are all optional (defaults are shown):
|
2018-01-16 20:08:47 -07:00
|
|
|
|
dir: {
|
2021-06-17 17:02:30 -06:00
|
|
|
|
input: '_src',
|
|
|
|
|
includes: '_includes',
|
|
|
|
|
data: '_data',
|
2022-10-20 09:53:02 -06:00
|
|
|
|
output: '_site'
|
2018-01-22 07:17:48 -07:00
|
|
|
|
}
|
2021-06-17 17:02:30 -06:00
|
|
|
|
}
|
|
|
|
|
}
|