import markdownIt from "markdown-it"; import footnote_plugin from "markdown-it-footnote"; import readingTime from "eleventy-plugin-reading-time"; import EleventyVitePlugin from "@11ty/eleventy-plugin-vite"; /** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */ export default async function (eleventyConfig) { eleventyConfig.addPassthroughCopy({ assets: "/" }); eleventyConfig.addPassthroughCopy({ public: "/" }); eleventyConfig.addPassthroughCopy({ "public/img": "/img" }); eleventyConfig.addPassthroughCopy({ "public/favicon.ico": "/favicon.ico" }); eleventyConfig.addPassthroughCopy("**/*.jpg"); eleventyConfig.addPassthroughCopy("**/*.png"); eleventyConfig.addCollection("redirects", function (collectionApi) { let redirects = []; // get each post in our posts folder const nodes = collectionApi.getFilteredByGlob("**/*.md"); // iterate over all the nodes nodes.forEach((node) => // for each alias (node.data.aliases || []).forEach((alias) => // push target url and the old url redirects.push([ node.data.page.url, node.data.page.url.replace(/\/[^\/]*?(\..+)?$/, `/${alias}$1`), ]), ), ); return redirects; }); function sortByDate(values) { // inspired by let vals = [...values]; return vals.sort((a, b) => { return a.data.date < b.data.date ? 1 : -1; }); } eleventyConfig.addFilter("sortByDate", sortByDate); let markdownItOptions = { html: true, breaks: true, linkify: true, }; eleventyConfig.setLibrary("md", markdownIt(markdownItOptions)); eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(footnote_plugin)); eleventyConfig.addPlugin(readingTime); eleventyConfig.addPlugin(EleventyVitePlugin, { tempFolderName: ".11ty-vite", // Default name of the temp folder // Options passed to the Eleventy Dev Server // Defaults serverOptions: { module: "@11ty/eleventy-dev-server", domDiff: false, }, // Defaults viteOptions: { clearScreen: false, appType: "mpa", server: { middlewareMode: true, }, build: { emptyOutDir: true, }, }, }); }