generated from kohrongying/11ty-blog-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
110 lines (97 loc) · 3.63 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
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
import { createRequire } from "module";
import dotenvFlow from "dotenv-flow";
import filters from "./config/filters/index.js";
import htmlmin from "html-minifier-terser";
import markdownIt from "markdown-it";
import markdownItAnchor from "markdown-it-anchor";
import markdownItFootnote from "markdown-it-footnote";
import markdownItPrism from "markdown-it-prism";
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import tablerIcons from "@cdransf/eleventy-plugin-tabler-icons";
import { minifyJsComponents } from "./config/events/index.js";
import { popularPosts, albumReleasesCalendar } from "./config/collections/index.js";
import { cssConfig } from "./config/plugins/css-config.js";
// load .env
dotenvFlow.config();
// get app version
const require = createRequire(import.meta.url);
const appVersion = require("./package.json").version;
export default async function (eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(tablerIcons);
if (process.env.ELEVENTY_PRODUCTION) eleventyConfig.addPlugin(cssConfig);
eleventyConfig.setQuietMode(true);
eleventyConfig.configureErrorReporting({ allowMissingExtensions: true });
eleventyConfig.setLiquidOptions({
jsTruthy: true,
});
eleventyConfig.addPassthroughCopy("src/assets");
eleventyConfig.addPassthroughCopy("_redirects");
eleventyConfig.addPassthroughCopy("_headers");
eleventyConfig.addPassthroughCopy({
"node_modules/@cdransf/api-text/api-text.js":
"assets/scripts/components/api-text.js",
"node_modules/@cdransf/select-pagination/select-pagination.js":
"assets/scripts/components/select-pagination.js",
"node_modules/@daviddarnes/mastodon-post/mastodon-post.js":
"assets/scripts/components/mastodon-post.js",
"node_modules/minisearch/dist/umd/index.js":
"assets/scripts/components/minisearch.js",
"node_modules/youtube-video-element/youtube-video-element.js":
"assets/scripts/components/youtube-video-element.js",
});
eleventyConfig.addCollection("popularPosts", popularPosts);
eleventyConfig.addCollection("albumReleasesCalendar", albumReleasesCalendar);
const md = markdownIt({ html: true, linkify: true });
md.use(markdownItAnchor, {
level: [1, 2],
permalink: markdownItAnchor.permalink.headerLink({
safariReaderFix: true,
}),
});
md.use(markdownItFootnote);
md.use(markdownItPrism);
eleventyConfig.setLibrary("md", md);
eleventyConfig.addLiquidFilter("markdown", (content) => {
if (!content) return;
return md.render(content);
});
Object.keys(filters).forEach((filterName) => {
eleventyConfig.addLiquidFilter(filterName, filters[filterName]);
});
eleventyConfig.addShortcode("appVersion", () => appVersion);
// events
if (process.env.ELEVENTY_PRODUCTION)
eleventyConfig.on("afterBuild", minifyJsComponents);
// transforms
if (process.env.ELEVENTY_PRODUCTION)
eleventyConfig.addTransform("html-minify", (content, path) => {
if (path && path.endsWith(".html")) {
return htmlmin.minify(content, {
collapseBooleanAttributes: true,
collapseWhitespace: true,
decodeEntities: true,
includeAutoGeneratedTags: false,
minifyCSS: true,
minifyJS: true,
minifyURLs: true,
noNewlinesBeforeTagClose: true,
quoteCharacter: '"',
removeComments: true,
sortAttributes: true,
sortClassName: true,
useShortDoctype: true,
});
}
return content;
});
return {
dir: {
input: "src",
includes: "includes",
layouts: "layouts",
data: "data",
output: "dist",
},
};
}