-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
150 lines (131 loc) · 4.74 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
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
require("dotenv").config();
const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const markdownIt = require("markdown-it");
const markdownItAttrs = require("markdown-it-attrs");
/* const markdownItTexmath = require("markdown-it-texmath"); */
const filters = require("./utils/filters.js");
const transforms = require("./utils/transforms.js");
const shortcodes = require("./utils/shortcodes.js");
const IS_PRODUCTION = process.env.ELEVENTY_ENV === "production";
// ELEVENTY CONFIG
module.exports = function (eleventyConfig) {
// PLUGINS
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginSyntaxHighlight);
/* MARKDOWN-IT
https://www.11ty.dev/docs/languages/markdown/
https://github.com/markdown-it/markdown-it#init-with-presets-and-options
https://github.com/goessner/markdown-it-texmath */
const markdownLib = markdownIt({
html: true,
breaks: true,
linkify: true,
}).use(markdownItAttrs);
/* .use(markdownItTexmath, {
engine: require("katex"),
delimiters: "dollars",
katexOptions: { macros: { "\\RR": "\\mathbb{R}" } },
}); */
eleventyConfig.setLibrary("md", markdownLib);
/* const markdownLib = markdownIt({
html: true,
breaks: true,
linkify: true,
})
.use(markdownItAttrs)
.use(markdownItTexmath, {
engine: require("katex"),
delimiters: "dollars",
delimiters: [
{ left: "$$", right: "$$", display: true },
{ left: "\\(", right: "\\)", display: true },
], */
/* katexOptions: { macros: { "\\RR": "\\mathbb{R}" } },
});
eleventyConfig.setLibrary("md", markdownLib);
const str = "Euler\'s identity $e^{i\\pi}+1=0$ is a beautiful formula in $\\RR^2$.";
md.render(str); */
// FILTERS
eleventyConfig.addFilter();
eleventyConfig.addFilter("dateFriendly", filters.dateFriendly);
eleventyConfig.addFilter("dateYMD", filters.dateYMD);
eleventyConfig.addFilter("dateISO", filters.dateISO);
eleventyConfig.addFilter("readTime", filters.readTime);
eleventyConfig.addFilter("excludePost", filters.excludePost);
eleventyConfig.addFilter("slice", filters.slice);
eleventyConfig.addFilter("limit", filters.limit);
eleventyConfig.addFilter("randomItem", (arr) => {
arr.sort(() => {
return 0.5 - Math.random();
});
return arr.slice(0, 1);
});
// TRANSFORMS
eleventyConfig.addTransform("minifyHTML", transforms.minifyHTML);
// SHORTCODES
eleventyConfig.addShortcode("year", shortcodes.year);
eleventyConfig.addNunjucksAsyncShortcode("image", shortcodes.eleventyImage);
eleventyConfig.addShortcode("randomColor", shortcodes.randomColor);
eleventyConfig.addShortcode("hAnchor", shortcodes.hAnchor);
/* eleventyConfig.addShortcode("math", (mathContent) => {
return md.render(mathContent);
}); */
// COLLECTIONS
eleventyConfig.addCollection("posts", (collection) => {
return collection
.getFilteredByGlob("./src/posts/*.md")
.filter((p) => !(p.data.draft && IS_PRODUCTION));
});
eleventyConfig.addCollection("featuredPosts", (collection) => {
return collection
.getFilteredByGlob("./src/posts/*.md")
.filter((p) => p.data.featured);
});
eleventyConfig.addCollection("randomizedPosts", function (collection) {
return (
collection
// Change to the name of your tag
.getFilteredByTag("post")
.sort(() => {
return 0.5 - Math.random();
})
// Optional limit, remove if unwanted
.slice(0, 3)
);
});
eleventyConfig.addCollection("projects", (collection) => {
return collection
.getFilteredByGlob("./src/projects/*.md")
.sort((a, b) =>
Number(a.data.displayOrder) > Number(b.data.displayOrder) ? 1 : -1
);
});
eleventyConfig.addCollection("featuredProjects", (collection) => {
return collection
.getFilteredByGlob("./src/projects/*.md")
.sort((a, b) =>
Number(a.data.displayOrder) > Number(b.data.displayOrder) ? 1 : -1
)
.filter((p) => p.data.featured);
});
eleventyConfig.addCollection("tagList", filters.getTagList);
// PASSTHROUGH FILE COPY
eleventyConfig.addPassthroughCopy("./src/assets/images/favicons");
eleventyConfig.addPassthroughCopy("./src/assets/images/posts/");
eleventyConfig.addPassthroughCopy("./src/assets/fonts");
/* eleventyConfig.addPassthroughCopy('./src/site.webmanifest') */
eleventyConfig.addPassthroughCopy("./src/robots.txt");
// WATCH TARGET
eleventyConfig.addWatchTarget("./src/assets");
// RETURN THE BASE CONFIG OBJECT
return {
markdownTemplateEngine: "njk",
dataTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dir: {
input: "src",
output: "dist",
},
};
}; // END ELEVENTY CONFIG