/
eleventy.config.js
147 lines (122 loc) · 4.26 KB
/
eleventy.config.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
require("dotenv").config();
const { DateTime } = require("luxon");
const _ = require("lodash");
const { EleventyRenderPlugin } = require("@11ty/eleventy");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginBundle = require("@11ty/eleventy-plugin-bundle");
const pluginDrafts = require("./eleventy.config.drafts.js");
const pluginMarkdoc = require("./eleventy.config.markdoc.js");
const pluginScss = require("eleventy-sass");
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
module.exports = function (eleventyConfig) {
// Copy the contents of the `public` folder to the output folder
// For example, `./public/css/` ends up in `_site/css/`
eleventyConfig.addPassthroughCopy({
"src/site/public/": "/",
});
// Run Eleventy when these files change:
// https://www.11ty.dev/docs/watch-serve/#add-your-own-watch-targets
// Watch content images for the image pipeline.
eleventyConfig.addWatchTarget("src/content/**/*");
eleventyConfig.addWatchTarget("src/site/**/*");
// App plugins
eleventyConfig.addPlugin(pluginDrafts);
eleventyConfig.addPlugin(pluginMarkdoc);
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(pluginScss, {
sass: {
style: "expanded",
sourceMap: true,
},
});
// Official plugins
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginBundle);
// Filters
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
// Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" }).toFormat(
format || "DDD"
);
});
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat("yyyy-LL-dd");
});
// Get the first `n` elements of a collection.
eleventyConfig.addFilter("head", (array, n) => {
if (!Array.isArray(array) || array.length === 0) {
return [];
}
if (n < 0) {
return array.slice(n);
}
return array.slice(0, n);
});
eleventyConfig.addShortcode("renderlayoutblock", function (name) {
return (this.page.layoutblock || {})[name] || "";
});
eleventyConfig.addPairedShortcode("layoutblock", function (content, name) {
if (!this.page.layoutblock) this.page.layoutblock = {};
this.page.layoutblock[name] = content;
return "";
});
eleventyConfig.addCollection("blog", (collection) => {
return collection.getFilteredByGlob("src/content/blog/*.md").reverse();
});
eleventyConfig.addAsyncFilter(
"renderForFeed",
async (content, outputPath) => {
return eleventyConfig.javascriptFunctions.renderTemplate.call(
this,
content,
"md",
{
markdocRenderMode: "feed",
}
);
}
);
eleventyConfig.addCollection("blogByYear", (collection) => {
return _.chain(collection.getFilteredByGlob("src/content/blog/*.md"))
.groupBy((post) => post.date.getFullYear())
.toPairs()
.reverse()
.value();
});
eleventyConfig.addCollection("projects", (collection) => {
return collection.getFilteredByGlob("src/content/projects/*.md").reverse();
});
eleventyConfig.addGlobalData("copyrightYear", () => {
return DateTime.now().toFormat("yyyy");
});
eleventyConfig.addGlobalData(
"commit",
(revision = require("child_process")
.execSync("git rev-parse HEAD")
.toString()
.trim())
);
eleventyConfig.addGlobalData(
"env",
process.env.ELEVENTY_RUN_MODE == "serve" ? "development" : "production"
);
eleventyConfig.addGlobalData(
"jil_api_admin_key",
process.env.JIL_API_ADMIN_KEY
);
return {
// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
templateFormats: ["md", "njk", "html", "11ty.js"],
// Pre-process *.html files with: (default: `liquid`)
htmlTemplateEngine: "njk",
dir: {
input: "src/content", // default: "."
includes: "../site/includes", // default: "_includes"
layouts: "../site/layouts", // default: "_layouts
data: "../site/data", // default: "_data"
output: "_site",
},
};
};