-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheleventy.config.js
More file actions
174 lines (156 loc) · 5.52 KB
/
Copy patheleventy.config.js
File metadata and controls
174 lines (156 loc) · 5.52 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { EleventyRenderPlugin } from "@11ty/eleventy";
import EleventyPluginRss from "@11ty/eleventy-plugin-rss";
import EleventyPluginSyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import EleventyPluginWebc from "@11ty/eleventy-plugin-webc";
import EleventyPluginOgImage from "eleventy-plugin-og-image";
import markdownIt from "markdown-it";
import markdownItAnchor from "markdown-it-anchor";
import markdownItAttrs from "markdown-it-attrs";
import readingTime from "reading-time";
import slugify from "slugify";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const controlTags = new Set(["all", "nav", "post", "posts"]);
function toSlug(value = "") {
return slugify(String(value), {
lower: true,
strict: true,
trim: true
});
}
function stripTags(value = "") {
return String(value).replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
}
function formatDate(value) {
return new Intl.DateTimeFormat("en-US", {
dateStyle: "long"
}).format(new Date(value));
}
function machineDate(value) {
return new Date(value).toISOString();
}
function escapeHtml(value = "") {
return String(value)
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">")
.replaceAll('"', """)
.replaceAll("'", "'");
}
const markdownLibrary = markdownIt({
html: true,
linkify: true,
breaks: false
})
.use(markdownItAttrs)
.use(markdownItAnchor, {
slugify: toSlug,
permalink: markdownItAnchor.permalink.ariaHidden({
placement: "after",
class: "heading-anchor",
symbol: "#"
})
});
export default function (eleventyConfig) {
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(EleventyPluginRss);
eleventyConfig.addPlugin(EleventyPluginSyntaxHighlight);
eleventyConfig.addPlugin(EleventyPluginWebc, {
components: "src/_includes/components/**/*.webc",
useTransform: true
});
eleventyConfig.addPlugin(EleventyPluginOgImage, {
previewMode: false,
satoriOptions: {
width: 1200,
height: 630,
fonts: [
{
name: "Atkinson Hyperlegible",
data: fs.readFileSync(
path.join(
__dirname,
"node_modules/@fontsource/atkinson-hyperlegible/files/atkinson-hyperlegible-latin-400-normal.woff"
)
),
weight: 400,
style: "normal"
},
{
name: "Atkinson Hyperlegible",
data: fs.readFileSync(
path.join(
__dirname,
"node_modules/@fontsource/atkinson-hyperlegible/files/atkinson-hyperlegible-latin-700-normal.woff"
)
),
weight: 700,
style: "normal"
},
{
name: "Silkscreen",
data: fs.readFileSync(
path.join(__dirname, "node_modules/@fontsource/silkscreen/files/silkscreen-latin-400-normal.woff")
),
weight: 400,
style: "normal"
}
]
}
});
eleventyConfig.setLibrary("md", markdownLibrary);
eleventyConfig.addFilter("slugify", toSlug);
eleventyConfig.addFilter("stripTags", stripTags);
eleventyConfig.addFilter("formatDate", formatDate);
eleventyConfig.addFilter("machineDate", machineDate);
eleventyConfig.addFilter("readTime", value => readingTime(String(value || "")).text);
eleventyConfig.addFilter("renderMarkdown", value => markdownLibrary.render(String(value || "")));
eleventyConfig.addFilter("renderMarkdownInline", value => markdownLibrary.renderInline(String(value || "")));
eleventyConfig.addFilter("limit", (values = [], amount = 3) => values.slice(0, amount));
eleventyConfig.addFilter("publicTags", (tags = []) => tags.filter(tag => !controlTags.has(tag)));
eleventyConfig.addFilter("urlencode", value => encodeURIComponent(String(value ?? "")));
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
eleventyConfig.addShortcode("button88", (label, href, accent = "ember") => {
const safeAccent = ["ember", "surf", "mint"].includes(accent) ? accent : "ember";
return `<a class="button-88 button-88--${safeAccent}" href="${escapeHtml(href)}"><span>${escapeHtml(
label
)}</span></a>`;
});
eleventyConfig.addCollection("posts", collectionApi => {
return collectionApi.getFilteredByTag("post").reverse();
});
eleventyConfig.addCollection("tagList", collectionApi => {
const tags = new Set();
for (const item of collectionApi.getFilteredByTag("post")) {
for (const tag of item.data.tags || []) {
if (!controlTags.has(tag)) {
tags.add(tag);
}
}
}
return Array.from(tags).sort((left, right) => left.localeCompare(right));
});
eleventyConfig.addPassthroughCopy({ "src/assets/js": "assets/js" });
eleventyConfig.addPassthroughCopy({
"node_modules/@fontsource/atkinson-hyperlegible/files": "assets/css/files"
});
eleventyConfig.addPassthroughCopy({
"node_modules/@fontsource/silkscreen/files": "assets/css/files"
});
eleventyConfig.addPassthroughCopy({ "src/favicon.svg": "favicon.svg" });
eleventyConfig.addPassthroughCopy({ "node_modules/@11ty/is-land/is-land.js": "assets/js/is-land.js" });
eleventyConfig.addWatchTarget("./src/assets/");
return {
dir: {
input: "src",
includes: "_includes",
data: "_data",
output: "_site"
},
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
templateFormats: ["md", "njk", "html", "webc", "11ty.js"]
};
}