-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.mjs
98 lines (83 loc) · 2.94 KB
/
eleventy.config.mjs
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
import { EleventyRenderPlugin } from '@11ty/eleventy';
import EleventyNavigationPlugin from '@11ty/eleventy-navigation';
import EleventyRssPlugin from '@11ty/eleventy-plugin-rss';
import esbuild from 'esbuild';
import markdownIt from 'markdown-it';
import markdownItAttrs from 'markdown-it-attrs';
import yaml from 'js-yaml';
export default function (eleventyConfig) {
eleventyConfig.setServerOptions({
domdiff: false,
});
eleventyConfig.setDataFileBaseName('_data');
eleventyConfig.addPassthroughCopy({
'_site/_assets/img': '_assets/img',
'_site/_assets/files': '_assets/files',
'_site/_assets/_root': './',
});
eleventyConfig.addWatchTarget('./_site/_app/_app.js');
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(EleventyNavigationPlugin);
eleventyConfig.addPlugin(EleventyRssPlugin);
//{% renderTemplate "md" %}
//# Blah{.text-center}
//{% endrenderTemplate %}
let markdownLibrary = markdownIt().use(markdownItAttrs);
eleventyConfig.setLibrary('md', markdownLibrary);
// yaml
eleventyConfig.addDataExtension('yaml', (contents) => yaml.load(contents));
// shortcodes
eleventyConfig.addShortcode('bust', () => `${new Date().getFullYear()}${new Date().getMonth()}${new Date().getDate()}${new Date().getHours()}`);
eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`);
eleventyConfig.addShortcode('renderblock', function(name) {
return (this.page.setblock || {})[name] || '';
});
eleventyConfig.addPairedShortcode('setblock', function(content, name) {
if (!this.page.setblock) this.page.setblock = {};
this.page.setblock[name] = content;
return '';
});
// filters
// md {{ some.content | md | safe }}
eleventyConfig.addFilter('md', function(content) {
return markdownLibrary.render(content);
});
// | randomLimit(6, page.url)
eleventyConfig.addFilter('randomLimit', (arr, limit, currPage) => {
const pageArr = arr.filter((page) => page.url !== currPage);
pageArr.sort(() => {
return 0.5 - Math.random();
});
return pageArr.slice(0, limit);
});
// pluck
eleventyConfig.addFilter('pluck', function (arr, value, attr) {
return arr.filter((item) => item[attr] === value);
});
// for item in (items | flatMap('category') | unique('category'))
eleventyConfig.addFilter('flatMap', (list, key) => list.flatMap((x) => x[key]));
eleventyConfig.addFilter('unique', (list, key) => {
const map = new Map(list.map((x) => [x[key], x]))
return [...map.values()]
});
// esbuild
eleventyConfig.on('eleventy.before', async () => {
await esbuild.build({
entryPoints: ['_site/_app/_app.js'],
outfile: 'public/_assets/js/_app.js',
bundle: true,
minify: true,
sourcemap: false,
});
});
return {
jsDataFileSuffix: '.data',
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
dir: {
input: '_site',
output: 'public',
},
pathPrefix: '/',
};
};