Tom Hubrecht
951fc2c11c
All checks were successful
Deploy dgnum.eu / deploy (push) Successful in 54s
112 lines
3 KiB
JavaScript
112 lines
3 KiB
JavaScript
// SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
|
|
//
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
// Module imports
|
|
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
|
|
import { feedPlugin } from "@11ty/eleventy-plugin-rss";
|
|
import markdownIt from "markdown-it";
|
|
import anchor from "markdown-it-anchor";
|
|
import attributes from "markdown-it-attrs";
|
|
import { minify } from "terser";
|
|
import { extname } from "path";
|
|
|
|
const headerIconLink = (slug, _, state, idx) => {
|
|
const linkTokens = [
|
|
Object.assign(new state.Token("link_open", "a", 1), {
|
|
attrs: [
|
|
["href", `#${slug}`],
|
|
["class", "header-anchor"],
|
|
],
|
|
}),
|
|
...[new state.Token("span_open", "span", 1)],
|
|
...state.tokens[idx + 1].children,
|
|
...[new state.Token("span_close", "span", -1)],
|
|
Object.assign(new state.Token("html_inline", "", 0), {
|
|
content: ` <i class="ti ti-link" aria-hidden=true></i>`,
|
|
meta: { isPermalinkSymbol: true },
|
|
}),
|
|
new state.Token("link_close", "a", -1),
|
|
];
|
|
|
|
state.tokens[idx + 1] = Object.assign(new state.Token("inline", "", 0), {
|
|
children: linkTokens,
|
|
});
|
|
};
|
|
|
|
const copy = (md, _) => {
|
|
md.renderer.rules.fence = ((rule) => {
|
|
return (tokens, idx, options, env, self) => {
|
|
// The original rendered code block
|
|
const rendered = rule(tokens, idx, options, env, self);
|
|
|
|
if (!tokens[idx].info) {
|
|
return rendered;
|
|
}
|
|
|
|
return `<div class="code-container">${rendered}<button class="code-copy"><span class="ti ti-clipboard"></span></button></div>`;
|
|
};
|
|
})(md.renderer.rules.fence);
|
|
};
|
|
|
|
export default function (config) {
|
|
// Setup passthrough directories
|
|
[
|
|
"src/_uploads",
|
|
...["css", "js", "fonts"].map((d) => `src/assets/${d}`),
|
|
].forEach((dir) => config.addPassthroughCopy(dir));
|
|
|
|
config.addPassthroughCopy({
|
|
"node_modules/@tabler/icons-webfont/dist/fonts": "assets/icons/fonts",
|
|
"node_modules/@tabler/icons-webfont/dist/*.min.css": "assets/icons",
|
|
});
|
|
|
|
// Plugins registration
|
|
config.addPlugin(syntaxHighlight, { lineSeparator: "<br>" });
|
|
config.addPlugin(feedPlugin, {
|
|
type: "atom",
|
|
outputPath: "/feed.xml",
|
|
collection: {
|
|
name: "post",
|
|
limit: 10,
|
|
},
|
|
metadata: {
|
|
language: "fr",
|
|
title: "DGNum",
|
|
subtitle: "A small collection of texts.",
|
|
base: "https://dgnum.eu/",
|
|
author: {
|
|
name: "La Délégation Générale Numérique",
|
|
},
|
|
},
|
|
});
|
|
|
|
// Date filter
|
|
config.addFilter("showDate", (d) => d.toDateString());
|
|
|
|
// Markdown configuration
|
|
config.setLibrary(
|
|
"md",
|
|
markdownIt({ html: true, breaks: true, linkify: true })
|
|
.use(anchor, { permalink: headerIconLink })
|
|
.use(copy)
|
|
.use(attributes),
|
|
);
|
|
|
|
// Minify js files
|
|
// config.addTransform("min.js", async (content, outputPath) => {
|
|
// if (outputPath && extname(outputPath) == ".js") {
|
|
// const js = await minify(content, {});
|
|
// return js.code;
|
|
// }
|
|
//
|
|
// return content;
|
|
// });
|
|
|
|
return {
|
|
dir: {
|
|
includes: "_includes",
|
|
layouts: "_layouts",
|
|
},
|
|
};
|
|
}
|