-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheleventy.config.js
More file actions
130 lines (109 loc) · 4.06 KB
/
Copy patheleventy.config.js
File metadata and controls
130 lines (109 loc) · 4.06 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import lightningCSS from "@11tyrocks/eleventy-plugin-lightningcss";
import markdownIt from "markdown-it";
import markdownItFootnote from "markdown-it-footnote";
import markdownItAttrs from "markdown-it-attrs";
import { processSidenotes } from "./src/_includes/transforms/sidenotes.js";
export default function(eleventyConfig) {
const md = markdownIt({
html: true,
breaks: false,
linkify: true,
typographer: true
});
md.use(markdownItFootnote);
md.use(markdownItAttrs);
md.renderer.rules.footnote_anchor_name = (tokens, idx, _options, env) => {
const { label, id } = tokens[idx].meta;
if (label) return "-" + label;
const prefix = typeof env.docId === "string" ? "-" + env.docId + "-" : "";
return prefix + (id + 1);
};
eleventyConfig.setLibrary("md", md);
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(lightningCSS);
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
extensions: "html",
formats: ["avif", "jpeg"],
widths: [600, 1200, 1800],
sharpJpegOptions: { quality: 80, mozjpeg: true },
sharpAvifOptions: { quality: 55 },
defaultAttributes: {
loading: "lazy",
decoding: "async"
}
});
eleventyConfig.addNunjucksFilter("dateToRfc822", (date) => {
return new Date(date).toUTCString();
});
eleventyConfig.addTransform("sidenotes", (content, outputPath) => {
if (outputPath?.endsWith(".html")) {
return processSidenotes(content);
}
return content;
});
eleventyConfig.addCollection("posts", (collectionApi) => {
return collectionApi.getFilteredByGlob("src/writing/*/index.md")
.filter((post) => !post.data.unlisted)
.sort((a, b) => b.date - a.date);
});
eleventyConfig.addCollection("nows", (collectionApi) => {
return collectionApi.getFilteredByGlob("src/now/*/index.md")
.sort((a, b) => a.date - b.date);
});
const MONTHS = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
eleventyConfig.addFilter("dateFormat", (date) => {
return new Date(date).toISOString().slice(0, 10);
});
eleventyConfig.addFilter("monthYear", (date) => {
const d = new Date(date);
return `${MONTHS[d.getUTCMonth()]}, ${d.getUTCFullYear()}`;
});
eleventyConfig.addFilter("monthName", (date) => {
const d = new Date(date);
return MONTHS[d.getUTCMonth()];
});
eleventyConfig.addFilter("head", (array, n) => {
if (!Array.isArray(array)) return [];
return array.slice(0, n);
});
eleventyConfig.addFilter("year", (date) => {
return new Date(date).getUTCFullYear();
});
eleventyConfig.addFilter("currentYear", () => {
return new Date().getFullYear();
});
eleventyConfig.addFilter("readingTime", (content) => {
if (!content) return "1 min read";
const words = content.replace(/<[^>]*>/g, '').split(/\s+/).filter(w => w.length > 0).length;
const minutes = Math.max(1, Math.ceil(words / 200));
return `${minutes} min read`;
});
eleventyConfig.addPassthroughCopy("src/assets/js");
eleventyConfig.addPassthroughCopy("src/assets/fonts");
eleventyConfig.addPassthroughCopy("src/writing/*/images");
eleventyConfig.addPassthroughCopy("src/assets/88x31");
eleventyConfig.addPassthroughCopy("src/assets/friends");
eleventyConfig.addPassthroughCopy("src/assets/favicon.svg");
eleventyConfig.addPassthroughCopy("src/assets/logo.png");
eleventyConfig.addPassthroughCopy({ "src/assets/88x31/88x31.gif": "88x31.gif" });
eleventyConfig.addPassthroughCopy({ "src/rss.xsl": "rss.xsl" });
eleventyConfig.addPassthroughCopy("src/robots.txt");
eleventyConfig.addPassthroughCopy("src/.nojekyll");
eleventyConfig.addWatchTarget("src/styles/");
};
export const config = {
dir: {
input: "src",
output: "dist",
includes: "_includes",
data: "_data"
},
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
templateFormats: ["md", "njk", "html"]
};