Gordon Pedersen
6647dabdc8
Needed a little modification here and there to make it work with the activity pub data structure, but it's looking pretty good!
90 lines
No EOL
2.8 KiB
JavaScript
90 lines
No EOL
2.8 KiB
JavaScript
const { ACTOR_OBJ } = require("./src/env")
|
|
|
|
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)
|
|
|
|
eleventyConfig.addGlobalData("actor_obj", () => ACTOR_OBJ);
|
|
|
|
// 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"))
|
|
|
|
// 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_OBJ
|
|
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("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;
|
|
}
|
|
} |