95 lines
No EOL
3.1 KiB
JavaScript
95 lines
No EOL
3.1 KiB
JavaScript
const ACTOR = require("./actor").default
|
|
|
|
module.exports = function(eleventyConfig) {
|
|
// I'm .gitignoring my content for now, so 11ty should not ignore that
|
|
eleventyConfig.setUseGitIgnore(false)
|
|
|
|
// Filters are in a separate function to try and keep this config less cluttered
|
|
addFilters(eleventyConfig)
|
|
// same with shortcodes
|
|
addShortcodes(eleventyConfig)
|
|
// and collections
|
|
addCollections(eleventyConfig)
|
|
|
|
// add the actor data, accessible globally
|
|
eleventyConfig.addGlobalData("ACTOR", ACTOR);
|
|
|
|
// TODO: assets?
|
|
// files to passthrough copy
|
|
eleventyConfig.addPassthroughCopy({"img":"assets/img"})
|
|
eleventyConfig.addPassthroughCopy({"js":"assets/js"})
|
|
eleventyConfig.addPassthroughCopy("css")
|
|
eleventyConfig.addPassthroughCopy("CNAME")
|
|
|
|
// plugins
|
|
eleventyConfig.addPlugin(require("@11ty/eleventy-plugin-rss"))
|
|
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy")
|
|
eleventyConfig.addPlugin(EleventyHtmlBasePlugin)
|
|
|
|
// Return your Object options:
|
|
return {
|
|
dir: {
|
|
input: "_content",
|
|
output: "_site"
|
|
},
|
|
htmlTemplateEngine: "njk",
|
|
templateFormats: ["md","html","njk"]
|
|
}
|
|
}
|
|
|
|
function addCollections(eleventyConfig) {
|
|
eleventyConfig.addCollection("feed", function(collectionApi) {
|
|
return collectionApi.getAllSorted().reverse().filter(item => {
|
|
if(!item.data.published) return false
|
|
return item.filePathStem.startsWith('/posts/')
|
|
}).map(item => {
|
|
item.data.author = ACTOR
|
|
return item
|
|
}).sort((a, b) => new Date(b.published).getTime() - new Date(a.published).getTime())
|
|
})
|
|
}
|
|
|
|
function addShortcodes(eleventyConfig) {
|
|
eleventyConfig.addNunjucksShortcode("getVar", function(varString){ return this.ctx[varString] })
|
|
eleventyConfig.addShortcode('renderlayoutblock', function(name){ return (this.page.layoutblock || {})[name] || '' })
|
|
eleventyConfig.addPairedShortcode('layoutblock', function(content, name) {
|
|
if (!this.page.layoutblock) this.page.layoutblock = {}
|
|
this.page.layoutblock[name] = content
|
|
return ''
|
|
})
|
|
}
|
|
|
|
function addFilters(eleventyConfig) {
|
|
eleventyConfig.addFilter("formatDate", formatDateFilter)
|
|
eleventyConfig.addFilter("dateISOString", dateISOStringFilter)
|
|
eleventyConfig.addFilter("dateObj", (value) => new Date(value))
|
|
eleventyConfig.addFilter("log", (value) => { console.log(`[11ty] 📄LOG: `, value); return value })
|
|
eleventyConfig.addFilter("concat", (value, other) => value + '' + other)
|
|
eleventyConfig.addNunjucksAsyncFilter("await", (promise) => promise.then(res => callback(null, res)).catch(err => callback(err)))
|
|
}
|
|
|
|
// default date formatting
|
|
function formatDateFilter(value) {
|
|
try{
|
|
const date = new Date(value)
|
|
if(date) return date.toISOString().replace('T', ' ').slice(0, -5)
|
|
else throw 'Unrecognized data format'
|
|
}
|
|
catch(e) {
|
|
console.error(`Could not convert "${value}"`, e)
|
|
return value;
|
|
}
|
|
}
|
|
|
|
// dates as iso string
|
|
function dateISOStringFilter(value) {
|
|
try{
|
|
const date = new Date(value)
|
|
if(date) return date.toISOString()
|
|
else throw 'Unrecognized data format'
|
|
}
|
|
catch(e) {
|
|
console.error(`Could not convert "${value}"`, e)
|
|
return value;
|
|
}
|
|
} |