forked from ampproject/bentojs.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
118 lines (96 loc) · 3.8 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
const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor');
const markdownItContainer = require('./third-party/@gerhobbelt/markdown-it-container');
const pluginRss = require('@11ty/eleventy-plugin-rss');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const toc = require('eleventy-plugin-toc');
const imageShortcode = require('./site/_shortcodes/Image.js');
const iframeShortcode = require('./site/_shortcodes/Iframe.js');
const noOpShortCode = require('./site/_shortcodes/NoOp.js');
const {
exampleShortCode,
writeExamples,
} = require('./site/_shortcodes/Example.js');
const {heroExampleShortcode} = require('./site/_shortcodes/HeroExample.js');
const {i18n} = require('./site/_filters/i18n');
const md = require('./site/_filters/md');
const date = require('./site/_filters/date.js');
const insertStyles = require('./site/_transforms/insertStyles.js');
const minifyHtml = require('./site/_transforms/minifyHtml.js');
const components = require('./site/_collections/components.js');
const componentCategories = require('./site/_collections/componentCategories.js');
const highlights = require('./site/_collections/highlights.js');
const guides = require('./site/_collections/guides.js');
const notFound = require('./site/_config/404.js');
const isProduction = process.env.NODE_ENV === 'production';
global.__basedir = __dirname;
module.exports = (eleventyConfig) => {
eleventyConfig.setUseGitIgnore(false);
eleventyConfig.setDataDeepMerge(true);
eleventyConfig.addPassthroughCopy('assets');
eleventyConfig.addWatchTarget('./assets/**/*.css');
eleventyConfig.addWatchTarget('./assets/**/*.js');
eleventyConfig.setLibrary(
'md',
markdownIt({
html: true,
breaks: true,
})
.use(markdownItAnchor)
// Let folks customize markdown output with attributes (id, class, data-*)
.use(require('markdown-it-attrs'), {
leftDelimiter: '{:',
rightDelimiter: '}',
allowedAttributes: ['id', 'class', /^data-.*$/],
})
// Automatically add anchors to headings
/*
.use(require('markdown-it-anchor'), {
level: 2,
permalink: true,
permalinkClass: 'w-headline-link',
permalinkSymbol: '#',
// @ts-ignore
slugify: (s) => slugify(s, {lower: true}),
})
*/
.use(markdownItContainer, 'raw', {
render: (tokens, idx) => {
return '\n';
},
content: (tokens, idx) => {
return tokens[idx].markup;
},
})
.disable('code')
);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(toc);
eleventyConfig.addNunjucksAsyncShortcode('image', imageShortcode);
eleventyConfig.addShortcode('iframe', iframeShortcode);
eleventyConfig.addJavaScriptFunction('image', imageShortcode);
eleventyConfig.addPairedShortcode('tip', noOpShortCode);
eleventyConfig.addNunjucksTag('examples', exampleShortCode);
eleventyConfig.addNunjucksTag('heroexample', heroExampleShortcode);
eleventyConfig.addFilter('date', date);
eleventyConfig.addFilter('i18n', i18n);
eleventyConfig.addFilter('md', md);
eleventyConfig.addTransform('insert-styles', insertStyles);
eleventyConfig.addTransform('minify-html', minifyHtml);
eleventyConfig.addCollection('components', components);
eleventyConfig.addCollection('componentCategories', componentCategories);
eleventyConfig.addCollection('highlights', highlights);
eleventyConfig.addCollection('guides', guides);
eleventyConfig.on('afterBuild', writeExamples);
eleventyConfig.setBrowserSyncConfig(notFound);
return {
templateFormats: ['njk', 'md', '11ty.js'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
dir: {
input: 'site',
output: 'dist',
},
};
};