-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path.eleventy.js
162 lines (140 loc) · 5.36 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
151
152
153
154
155
156
157
158
159
160
161
162
const Image = require("@11ty/eleventy-img");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const markdownItAttrs = require("markdown-it-attrs");
const markdownItFootnote = require("markdown-it-footnote");
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const { DateTime } = require("luxon");
module.exports = function (eleventyConfig) {
// Use .eleventyignore as single source of truth for files to process.
eleventyConfig.setUseGitIgnore(false);
// dev: Watch style changes
eleventyConfig.addWatchTarget("./styles/tailwind.css");
eleventyConfig.addWatchTarget("./_site/style.css");
// Filters
// Date filter to fix UTC issues
eleventyConfig.addFilter("dateDisplay", (dateObj) => {
return DateTime.fromJSDate(dateObj).toUTC().toLocaleString(DateTime.DATE_MED);
});
// Add a limit function to limit the amount of items output by an array. https://11ty.rocks/eleventyjs/data-arrays/#limit-filter
eleventyConfig.addFilter("limit", function (arr, limit) {
return arr.slice(0, limit);
});
// Random item filter
eleventyConfig.addFilter("randomItem", (arr) => {
arr.sort(() => {
return 0.5 - Math.random();
});
return arr.slice(0, 1);
});
// Sort by page order - used for ordering docs
function sortByPageOrder (values) {
return values.slice().sort((a, b) => a.data.order - b.data.order);
}
eleventyConfig.addFilter("sortByPageOrder", sortByPageOrder);
// {{ variable | jsonify }}
eleventyConfig.addFilter('jsonify', function (variable) {
return JSON.stringify(variable);
});
eleventyConfig.addFilter("squash", require("./filters/squash.js"));
// Collections
eleventyConfig.addCollection("blog", collectionApi => {
return collectionApi.getFilteredByTag("blog").sort((a, b) => {
return b.date - a.date;
}).filter((item) => {
return item.data.tags.indexOf("releases") -1;
});
});
// Layouts
const layoutAliases = {
"default": "default.njk",
"post": "post.njk",
"page": "page.njk",
"docs": "docs.njk"
};
for (const [alias, layout] of Object.entries(layoutAliases)) {
eleventyConfig.addLayoutAlias(alias, `layouts/${layout}`);
}
// Include our static assets
eleventyConfig.addPassthroughCopy({
"robots.txt": "",
"images": "",
"videos": "",
"site/blog/assets": "blog/assets",
"visidata/docs/assets": "docs/assets",
"visidata/docs/casts": "docs/casts",
"node_modules/asciinema-player/dist/bundle/*.css": "css",
"node_modules/asciinema-player/dist/bundle/*.js": "/",
"node_modules/@fontsource/inconsolata": "css/inconsolata",
"styles/inconsolata.css": "css/inconsolata.css",
"redirects.tsv": "_redirects"
});
// Plugins
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(require("./eleventy.config.drafts.js"));
// Eleventy-img config
async function imageShortcode (src, alt, sizes = "40vw, 60vw, 100vw") {
let metadata = await Image(src, {
widths: [1000],
formats: ["svg", "webp", "jpeg"],
svgShortCircuit: true,
svgAllowUpscale: true,
outputDir: "_site/img/"
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
// You bet we throw an error on missing alt in `imageAttributes` (alt="" works okay)
return Image.generateHTML(metadata, imageAttributes);
}
// Shortcodes
eleventyConfig.addNunjucksAsyncShortcode("image", imageShortcode);
eleventyConfig.addLiquidShortcode("image", imageShortcode);
eleventyConfig.addJavaScriptFunction("image", imageShortcode);
eleventyConfig.addShortcode("version", function () {
return String(Date.now());
});
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
// Configure markdown-it and add plugin for heading anchors
let markdownItOptions = {
html: true,
breaks: true,
linkify: true
};
let markdownLibrary = markdownIt(markdownItOptions).use(markdownItAttrs).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
class: "heading-anchor",
symbol: "",
space: false,
placement: "before",
slugify: (s) =>
s
.trim()
.toLowerCase()
.replace(/[\s+~\/]/g, "-")
.replace(/[().`,%·'"!?¿:@*]/g, ""),
})
}).use(markdownItFootnote);
eleventyConfig.setLibrary("md", markdownLibrary);
// Template formats
return {
templateFormats: ["md", "njk", "html"],
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
passthroughFileCopy: true,
dir: {
input: 'site',
output: '_site',
includes: 'includes',
data: 'globals'
}
};
// Transforms
};