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
|
import { IdAttributePlugin, EleventyHtmlBasePlugin, RenderPlugin, InputPathToUrlTransformPlugin } from '@11ty/eleventy';
import syntaxHighlightPlugin from "@11ty/eleventy-plugin-syntaxhighlight";
import { feedPlugin } from "@11ty/eleventy-plugin-rss";
import eleventyNavigationPlugin from "@11ty/eleventy-navigation";
import directoryOutputPlugin from "@11ty/eleventy-plugin-directory-output";
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img"
import pluginWebc from "@11ty/eleventy-plugin-webc";
import { readFile } from 'node:fs/promises';
import { DateTime } from "luxon";
import htmlmin from "html-minifier-terser";
import mdAbbr from 'markdown-it-abbr';
import mdContainer from 'markdown-it-container';
import postcss from 'postcss';
import cssnano from 'cssnano';
import metadata from './data/metadata.js';
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
export default async function(eleventyConfig) {
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(RenderPlugin);
eleventyConfig.addPlugin(InputPathToUrlTransformPlugin);
eleventyConfig.addPlugin(IdAttributePlugin);
eleventyConfig.addPlugin(syntaxHighlightPlugin);
eleventyConfig.addPlugin(feedPlugin, {
type: "atom",
outputPath: "/atom.xml",
collection: {
name: "post"
},
stylesheet: "atom.xsl",
metadata: {
language: metadata.language,
title: metadata.title,
subtitle: metadata.description,
base: metadata.url.href,
author: metadata.author,
}
});
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(directoryOutputPlugin);
eleventyConfig.addPlugin(pluginWebc, {
components: [
"npm:@11ty/eleventy-plugin-syntaxhighlight/*.webc",
],
bundlePluginOptions: {
transforms: [
async function(content) {
if (this.type == 'css') {
const result = await postcss([
cssnano({
preset: ['default', {
discardComments: {
removeAll: true,
},
}]
}),
]).process(content, {
from: this.page.inputPath,
to: null,
})
return result.css
}
return content;
}
],
}
});
eleventyConfig.addPassthroughCopy({
"public/": "/",
});
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
extensions: "html",
formats: ["webp", "jpeg", "svg", "avif", "auto", "png"],
widths: [128, 256, 512, 1024, "auto"],
defaultAttributes: {
sizes: "auto",
decoding: "async",
loading: "lazy"
},
});
eleventyConfig.amendLibrary("md", mdLib => {
mdLib.use(mdAbbr).use(mdContainer, "aside");
});
eleventyConfig.setServerPassthroughCopyBehavior("passthrough");
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" }).toFormat(format || "dd LLLL yyyy")
});
eleventyConfig.addFilter('htmlDateString', dateObj => DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd'));
eleventyConfig.addShortcode('schema', type => (type instanceof URL ? type : new URL(type, "http://schema.org/")).href);
eleventyConfig.addAsyncFilter('embed', path => readFile(path, { encoding: 'utf8' }));
eleventyConfig.setQuietMode(true);
eleventyConfig.setDynamicPermalinks(false);
eleventyConfig.addTransform("htmlmin", function(content) {
if ((this.page.outputPath || "").endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
// If not an HTML output, return content as-is
return content;
});
return {
markdownTemplateEngine: "njk",
htmlTemplateEngine: "webc",
dir: {
output: "dist",
input: "src",
includes: "../includes",
data: "../data",
components: "components",
}
};
}
|