-
Notifications
You must be signed in to change notification settings - Fork 3
/
.eleventy.js
72 lines (59 loc) · 2.03 KB
/
.eleventy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const { DateTime } = require("luxon");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const MarkdownIt = require("markdown-it");
const { execSync } = require("child_process");
const mdAnchor = require("markdown-it-anchor");
const mdHighlightjs = require("markdown-it-highlightjs");
const filterArticles = require("./util/sort-articles");
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("./src/styles");
eleventyConfig.addPassthroughCopy("./src/assets");
eleventyConfig.addPassthroughCopy("./src/scripts");
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addFilter("postDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toLocaleString(DateTime.DATE_MED);
});
eleventyConfig.addFilter("shorten", (path) => {
if (path.length > 16) {
return path.substring(0, 16) + "...";
} else {
return path;
}
});
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
// cuts out the starting '/articles' from output url
eleventyConfig.addFilter("rootify", (url) => {
return url.replace("/articles", "/");
});
eleventyConfig.addFilter("summary", (mdString, page) => {
const md = new MarkdownIt({ html: true });
const html = md.render(mdString);
targetAttr = `href="${page.outputPath.replace("public/", "/")}"`;
return html.replace(
targetAttr,
targetAttr + " " + 'class="active" aria-current="page"'
);
});
eleventyConfig.on("eleventy.after", () => {
execSync(`npx pagefind --source public --glob \"**/*.html\"`, {
encoding: "utf-8",
});
});
const md = new MarkdownIt({
html: true,
linkify: true,
typographer: true,
});
md.use(mdAnchor, { permalink: mdAnchor.permalink.headerLink() });
md.use(mdHighlightjs, { auto: false });
eleventyConfig.setLibrary("md", md);
eleventyConfig.addCollection("sortedArticles", filterArticles);
return {
dir: {
input: "src",
output: "public",
includes: "includes/partials",
layouts: "includes/layouts",
},
};
};