2023-11-06 14:36:02 +00:00
|
|
|
const path = require("node:path");
|
|
|
|
|
2023-05-19 12:12:14 +00:00
|
|
|
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
|
2023-01-21 17:21:09 +00:00
|
|
|
const pluginRss = require('@11ty/eleventy-plugin-rss');
|
2023-05-19 11:56:16 +00:00
|
|
|
const timeToRead = require('eleventy-plugin-time-to-read');
|
2023-05-19 12:12:14 +00:00
|
|
|
const safeLinks = require('@sardine/eleventy-plugin-external-links');
|
2023-05-19 14:21:09 +00:00
|
|
|
const related = require("eleventy-plugin-related");
|
2023-07-24 13:38:03 +00:00
|
|
|
const markdownIt = require("markdown-it");
|
|
|
|
const markdownItAnchor = require("markdown-it-anchor");
|
2023-11-06 14:36:02 +00:00
|
|
|
const sass = require("sass");
|
2022-05-31 18:36:19 +00:00
|
|
|
|
2023-10-27 16:12:11 +00:00
|
|
|
const figure = require('./src/_includes/components/figure.js');
|
2023-10-27 19:08:25 +00:00
|
|
|
const bounce = require('./src/_includes/components/bounce.js');
|
2023-10-27 16:12:11 +00:00
|
|
|
|
2022-05-31 13:09:45 +00:00
|
|
|
module.exports = function (eleventyConfig) {
|
2023-11-06 14:36:02 +00:00
|
|
|
const isDev = (process.env.ELEVENTY_ENV || "dev") == "dev";
|
|
|
|
|
2022-05-31 13:09:45 +00:00
|
|
|
const parseDate = (str) => {
|
|
|
|
if (str instanceof Date) {
|
|
|
|
return str;
|
|
|
|
}
|
2022-05-31 14:10:07 +00:00
|
|
|
return Date.parse(str);
|
2022-05-31 13:09:45 +00:00
|
|
|
};
|
|
|
|
|
2022-05-31 14:10:07 +00:00
|
|
|
const formatPart = (part, date) =>
|
2022-05-31 18:36:19 +00:00
|
|
|
new Intl.DateTimeFormat("en", part).format(date);
|
|
|
|
|
2023-05-19 12:20:25 +00:00
|
|
|
eleventyConfig.setNunjucksEnvironmentOptions({
|
|
|
|
lstripBlocks: true,
|
|
|
|
trimBlocks: true
|
|
|
|
});
|
|
|
|
|
2023-10-27 16:12:11 +00:00
|
|
|
const md = markdownIt({ "html": true }).use(markdownItAnchor, { "level": 2 });
|
|
|
|
eleventyConfig.setLibrary("md", md);
|
2023-07-24 13:38:03 +00:00
|
|
|
|
2023-05-19 11:56:16 +00:00
|
|
|
eleventyConfig.addPlugin(pluginRss);
|
|
|
|
eleventyConfig.addPlugin(syntaxHighlight);
|
|
|
|
eleventyConfig.addPlugin(timeToRead);
|
2023-05-19 12:12:14 +00:00
|
|
|
eleventyConfig.addPlugin(safeLinks);
|
2022-05-31 14:10:07 +00:00
|
|
|
|
2023-10-27 16:12:11 +00:00
|
|
|
eleventyConfig.addShortcode('figure', figure(md));
|
2023-10-27 19:08:25 +00:00
|
|
|
eleventyConfig.addShortcode('bounce', bounce);
|
2023-10-27 16:12:11 +00:00
|
|
|
|
2022-05-31 13:09:45 +00:00
|
|
|
eleventyConfig.addPassthroughCopy({ "src/static": "/" });
|
2023-11-06 14:36:02 +00:00
|
|
|
eleventyConfig.addPassthroughCopy({ "node_modules/reveal.js/dist/reveal.css": "reveal.js/reveal.css" });
|
|
|
|
eleventyConfig.addPassthroughCopy({ "node_modules/reveal.js/dist/reveal.esm.js": "reveal.js/reveal.esm.js" });
|
|
|
|
eleventyConfig.addPassthroughCopy({ "node_modules/reveal.js/plugin/markdown/markdown.esm.js": "reveal.js/plugin/markdown/markdown.esm.js" });
|
2023-11-28 20:33:39 +00:00
|
|
|
eleventyConfig.addPassthroughCopy({ "node_modules/reveal.js/plugin/highlight/highlight.esm.js": "reveal.js/plugin/highlight/highlight.esm.js" });
|
|
|
|
eleventyConfig.addPassthroughCopy({ "node_modules/reveal.js/plugin/highlight/monokai.css": "reveal.js/plugin/highlight/monokai.css" });
|
|
|
|
eleventyConfig.addPassthroughCopy({ "node_modules/reveal.js/plugin/notes/notes.esm.js": "reveal.js/plugin/notes/notes.esm.js" });
|
2022-05-31 13:09:45 +00:00
|
|
|
|
2023-10-27 21:02:58 +00:00
|
|
|
eleventyConfig.addFilter("date_to_datetime", async (obj) => {
|
2023-11-06 14:36:02 +00:00
|
|
|
if (!obj) {
|
|
|
|
return "";
|
|
|
|
}
|
2022-05-31 13:09:45 +00:00
|
|
|
const date = parseDate(obj);
|
2022-05-31 14:10:07 +00:00
|
|
|
return date.toISOString();
|
2022-05-31 13:09:45 +00:00
|
|
|
});
|
|
|
|
|
2023-10-27 21:02:58 +00:00
|
|
|
eleventyConfig.addFilter("date_formatted", async (obj) => {
|
2023-11-06 14:36:02 +00:00
|
|
|
if (!obj) {
|
|
|
|
return "";
|
|
|
|
}
|
2022-05-31 14:10:07 +00:00
|
|
|
const date = parseDate(obj);
|
|
|
|
|
|
|
|
const month = formatPart({ month: "short" }, date);
|
|
|
|
const day = formatPart({ day: "numeric" }, date);
|
|
|
|
const year = formatPart({ year: "numeric" }, date);
|
2023-07-24 20:34:41 +00:00
|
|
|
const hours = date.getUTCHours();
|
|
|
|
const minutes = date.getUTCMinutes();
|
|
|
|
|
|
|
|
if (hours != 0 && minutes != 0) {
|
|
|
|
return `${month} ${day}, ${year} - ${hours}:${minutes} UTC`;
|
|
|
|
}
|
2022-05-31 14:10:07 +00:00
|
|
|
|
|
|
|
return `${month} ${day}, ${year}`;
|
|
|
|
});
|
|
|
|
|
2023-10-27 21:02:58 +00:00
|
|
|
eleventyConfig.addFilter('urlescape', async str => {
|
2023-01-21 17:21:09 +00:00
|
|
|
return str.split('/').map(part => encodeURI(part)).join('/')
|
2023-05-19 14:21:09 +00:00
|
|
|
});
|
|
|
|
|
2023-10-27 21:02:58 +00:00
|
|
|
// TODO: possibly turn this into a post processing step instead of a filter (or at least make it a shortcode)
|
|
|
|
eleventyConfig.addFilter("related", async function(obj) {
|
2023-05-19 14:21:09 +00:00
|
|
|
const post = this.ctx;
|
|
|
|
const posts = this.ctx.collections.posts.map(post => post.data);
|
|
|
|
|
|
|
|
const tagScore = (a, b) => {
|
|
|
|
const total = a.tags.length + b.tags.length;
|
|
|
|
const intersection = a.tags.filter(tag => b.tags.includes(tag)).length;
|
|
|
|
return (intersection * 2) / total;
|
|
|
|
}
|
|
|
|
|
|
|
|
const results = related.related({
|
|
|
|
serializer: (doc) => [doc.title, doc.description],
|
|
|
|
weights: [10, 10],
|
|
|
|
})(post, posts).map(result => {
|
|
|
|
return {
|
|
|
|
relative: result.relative + tagScore(post, result.document),
|
|
|
|
document: result.document
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-06-08 16:04:58 +00:00
|
|
|
return results.filter(result => result.relative > 0.2).sort((a, b) => a.relative - b.relative).reverse().slice(0,3);
|
2023-05-19 14:21:09 +00:00
|
|
|
});
|
2023-01-21 17:21:09 +00:00
|
|
|
|
2022-05-31 14:10:07 +00:00
|
|
|
eleventyConfig.addCollection('posts', collection => {
|
|
|
|
return collection.getFilteredByGlob('src/posts/*.md').reverse()
|
2023-05-19 14:21:09 +00:00
|
|
|
});
|
2022-05-31 14:10:07 +00:00
|
|
|
|
2023-11-06 14:36:02 +00:00
|
|
|
eleventyConfig.addCollection('decks', collection => {
|
|
|
|
return collection.getFilteredByGlob('src/decks/*.md')
|
|
|
|
// append the raw content
|
|
|
|
.map(item => {
|
|
|
|
const content = item.template.frontMatter.content;
|
|
|
|
item.data.rawMarkdown = content || "";
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
eleventyConfig.addTemplateFormats("scss");
|
|
|
|
eleventyConfig.addExtension("scss", {
|
|
|
|
outputFileExtension: "css",
|
|
|
|
|
|
|
|
compile: function (inputContent, inputPath) {
|
|
|
|
let parsed = path.parse(inputPath);
|
|
|
|
|
|
|
|
let result = sass.compileString(inputContent, {
|
|
|
|
style: isDev ? "expanded" : "compressed",
|
|
|
|
loadPaths: [
|
|
|
|
parsed.dir || "."
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
this.addDependencies(inputPath, result.loadedUrls);
|
|
|
|
|
|
|
|
return async (data) => {
|
|
|
|
return result.css;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-05-31 13:09:45 +00:00
|
|
|
return {
|
|
|
|
templateFormats: ["njk", "md", "html"],
|
|
|
|
dir: {
|
|
|
|
input: "src",
|
|
|
|
includes: "_includes",
|
|
|
|
data: "_data",
|
|
|
|
output: "www",
|
|
|
|
},
|
|
|
|
markdownTemplateEngine: "njk",
|
|
|
|
htmlTemplateEngine: "njk",
|
|
|
|
dataTemplateEngine: "njk",
|
|
|
|
passthroughFileCopy: false,
|
|
|
|
};
|
|
|
|
};
|