forked from GoogleChrome/web.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
267 lines (246 loc) · 11.7 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const chalk = require('chalk');
const pluginRss = require('@11ty/eleventy-plugin-rss');
const pluginSyntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const yaml = require('js-yaml');
const fs = require('fs');
const toc = require('eleventy-plugin-toc');
const markdown = require('./src/site/_plugins/markdown');
const componentsDir = 'src/site/_includes/components';
const ArticleNavigation = require(`./${componentsDir}/ArticleNavigation`);
const Aside = require(`./${componentsDir}/Aside`);
const Assessment = require(`./${componentsDir}/Assessment`);
const Author = require(`./${componentsDir}/Author`);
const AuthorCard = require(`./${componentsDir}/AuthorCard`);
const AuthorInfo = require(`./${componentsDir}/AuthorInfo`);
const Banner = require(`./${componentsDir}/Banner`);
const Blockquote = require(`./${componentsDir}/Blockquote`);
const Breadcrumbs = require(`./${componentsDir}/Breadcrumbs`);
const CodelabsCallout = require(`./${componentsDir}/CodelabsCallout`);
const Codepen = require(`./${componentsDir}/Codepen`);
const Compare = require(`./${componentsDir}/Compare`);
const CompareCaption = require(`./${componentsDir}/CompareCaption`);
const Details = require(`./${componentsDir}/Details`);
const DetailsSummary = require(`./${componentsDir}/DetailsSummary`);
const EventTable = require(`./${componentsDir}/EventTable`);
const Glitch = require(`./${componentsDir}/Glitch`);
const Hero = require(`./${componentsDir}/Hero`);
const IFrame = require(`./${componentsDir}/IFrame`);
const {Img, generateImgixSrc} = require(`./${componentsDir}/Img`);
const Instruction = require(`./${componentsDir}/Instruction`);
const Label = require(`./${componentsDir}/Label`);
const Meta = require(`./${componentsDir}/Meta`);
const PathCard = require(`./${componentsDir}/PathCard`);
const PostCard = require(`./${componentsDir}/PostCard`);
const SignPosts = require(`./${componentsDir}/SignPosts`);
const StackOverflow = require(`./${componentsDir}/StackOverflow`);
const Tooltip = require(`./${componentsDir}/Tooltip`);
const {Video} = require(`./${componentsDir}/Video`);
const {YouTube} = require('webdev-infra/shortcodes/YouTube');
// Collections
const authors = require(`./src/site/_collections/authors`);
const blogPostsDescending = require(`./src/site/_collections/blog-posts-descending`);
const newsletters = require(`./src/site/_collections/newsletters`);
const pages = require('./src/site/_collections/pages');
const {
postsWithLighthouse,
} = require(`./src/site/_collections/posts-with-lighthouse`);
const tags = require(`./src/site/_collections/tags`);
// Filters
const filtersDir = 'src/site/_filters';
const consoleDump = require(`./${filtersDir}/console-dump`);
const {i18n} = require(`./${filtersDir}/i18n`);
const {memoize, findByUrl} = require(`./${filtersDir}/find-by-url`);
const pathSlug = require(`./${filtersDir}/path-slug`);
const containsTag = require(`./${filtersDir}/contains-tag`);
const expandAuthors = require(`./${filtersDir}/expand-authors`);
const findTags = require(`./${filtersDir}/find-tags`);
const githubLink = require(`./${filtersDir}/github-link`);
const gitlocalizeLink = require(`./${filtersDir}/gitlocalize-link`);
const htmlDateString = require(`./${filtersDir}/html-date-string`);
const isNewContent = require(`./${filtersDir}/is-new-content`);
const md = require(`./${filtersDir}/md`);
const pagedNavigation = require(`./${filtersDir}/paged-navigation`);
const postsLighthouseJson = require(`./${filtersDir}/posts-lighthouse-json`);
const prettyDate = require(`./${filtersDir}/pretty-date`);
const removeDrafts = require(`./${filtersDir}/remove-drafts`);
const slugify = require(`./${filtersDir}/slugify`);
const strip = require(`./${filtersDir}/strip`);
const stripBlog = require(`./${filtersDir}/strip-blog`);
const getPaths = require(`./${filtersDir}/get-paths`);
const navigation = require(`./${filtersDir}/navigation`);
const padStart = require(`./${filtersDir}/pad-start`);
const {minifyJs} = require(`./${filtersDir}/minify-js`);
const {cspHash, getHashList} = require(`./${filtersDir}/csp-hash`);
const transformsDir = 'src/site/_transforms';
const disableLazyLoad = require(`./${transformsDir}/disable-lazy-load`);
const {purifyCss} = require(`./${transformsDir}/purify-css`);
const {minifyHtml} = require(`./${transformsDir}/minify-html`);
// Shared dependencies between web.dev and developer.chrome.com
const {updateSvgForInclude} = require('webdev-infra/filters/svg');
// TODO: We should migrate all of our ToCs over to using this filter which we
// wrote for d.c.c. Currently we're also using eleventy-plugin-toc on articles
// but this one seems to work better.
const {toc: courseToc} = require('webdev-infra/filters/toc');
module.exports = function (config) {
console.log(chalk.black.bgGreen('Eleventy is building, please wait…'));
const isProd = process.env.ELEVENTY_ENV === 'prod';
const isStaging = process.env.ELEVENTY_ENV === 'staging';
// ----------------------------------------------------------------------------
// PLUGINS
// ----------------------------------------------------------------------------
// Syntax highlighting for code snippets
config.addPlugin(pluginSyntaxHighlight);
// RSS feeds
config.addPlugin(pluginRss);
config.addPlugin(toc, {
tags: ['h2', 'h3'],
wrapper: 'div',
wrapperClass: 'w-toc__list',
ul: true,
flat: true,
});
// ----------------------------------------------------------------------------
// MARKDOWN
// ----------------------------------------------------------------------------
config.setLibrary('md', markdown);
// ----------------------------------------------------------------------------
// NON-11TY FILES TO WATCH
// ----------------------------------------------------------------------------
config.addWatchTarget('./src/site/content/en/**/*.yml');
// ----------------------------------------------------------------------------
// COLLECTIONS
// ----------------------------------------------------------------------------
config.addCollection('authors', authors);
config.addCollection('blogPosts', blogPostsDescending);
config.addCollection('newsletters', newsletters);
config.addCollection('pages', pages);
config.addCollection('postsWithLighthouse', postsWithLighthouse);
config.addCollection('tags', tags);
// Turn collection.all into a lookup table so we can use findBySlug
// to quickly find collection items without looping.
config.addCollection('memoized', (collection) => {
return memoize(collection.getAll());
});
// ----------------------------------------------------------------------------
// FILTERS
// ----------------------------------------------------------------------------
config.addFilter('consoleDump', consoleDump);
config.addFilter('i18n', i18n);
config.addFilter('findByUrl', findByUrl);
config.addFilter('findTags', findTags);
config.addFilter('pathSlug', pathSlug);
config.addFilter('containsTag', containsTag);
config.addFilter('expandAuthors', expandAuthors);
config.addFilter('githubLink', githubLink);
config.addFilter('gitlocalizeLink', gitlocalizeLink);
config.addFilter('htmlDateString', htmlDateString);
config.addFilter('imgix', generateImgixSrc);
config.addFilter('isNewContent', isNewContent);
config.addFilter('md', md);
config.addFilter('navigation', navigation);
config.addFilter('pagedNavigation', pagedNavigation);
config.addFilter('postsLighthouseJson', postsLighthouseJson);
config.addFilter('prettyDate', prettyDate);
config.addFilter('removeDrafts', removeDrafts);
config.addFilter('slugify', slugify);
config.addFilter('stripBlog', stripBlog);
config.addFilter('getPaths', getPaths);
config.addFilter('strip', strip);
config.addFilter('courseToc', courseToc);
config.addFilter('updateSvgForInclude', updateSvgForInclude);
config.addFilter('padStart', padStart);
config.addFilter('minifyJs', minifyJs);
config.addFilter('cspHash', cspHash);
// ----------------------------------------------------------------------------
// SHORTCODES
// ----------------------------------------------------------------------------
config.addShortcode('ArticleNavigation', ArticleNavigation);
config.addPairedShortcode('Aside', Aside);
config.addShortcode('Assessment', Assessment);
config.addShortcode('Author', Author);
config.addShortcode('AuthorCard', AuthorCard);
config.addShortcode('AuthorInfo', AuthorInfo);
config.addPairedShortcode('Banner', Banner);
config.addPairedShortcode('Blockquote', Blockquote);
config.addShortcode('Breadcrumbs', Breadcrumbs);
config.addShortcode('CodelabsCallout', CodelabsCallout);
config.addShortcode('Codepen', Codepen);
config.addPairedShortcode('Compare', Compare);
config.addPairedShortcode('CompareCaption', CompareCaption);
config.addPairedShortcode('Details', Details);
config.addPairedShortcode('DetailsSummary', DetailsSummary);
config.addShortcode('Glitch', Glitch);
config.addShortcode('Hero', Hero);
config.addShortcode('IFrame', IFrame);
config.addShortcode('Img', Img);
config.addShortcode('Instruction', Instruction);
config.addPairedShortcode('Label', Label);
config.addShortcode('Meta', Meta);
config.addShortcode('PathCard', PathCard);
config.addShortcode('PostCard', PostCard);
config.addShortcode('SignPosts', SignPosts);
config.addShortcode('StackOverflow', StackOverflow);
config.addShortcode('Tooltip', Tooltip);
config.addShortcode('Video', Video);
config.addShortcode('YouTube', YouTube);
// This table is used for the web.dev/LIVE event, and should be taken down
// when the event is over or we no longer use it.
config.addShortcode('EventTable', EventTable);
// ----------------------------------------------------------------------------
// TRANSFORMS
// ----------------------------------------------------------------------------
if (process.env.PERCY) {
config.addTransform('disable-lazy-load', disableLazyLoad);
}
if (isProd || isStaging) {
config.addTransform('purifyCss', purifyCss);
config.addTransform('minifyHtml', minifyHtml);
}
// ----------------------------------------------------------------------------
// ELEVENTY OPTIONS
// ----------------------------------------------------------------------------
// https://www.11ty.io/docs/config/#data-deep-merge
config.setDataDeepMerge(true);
config.setUseGitIgnore(false);
// Make .yml files work in the _data directory.
config.addDataExtension('yml', (contents) => yaml.safeLoad(contents));
// Make CSP hashes accessible to firebase config.
if (isProd) {
config.on('afterBuild', () => {
fs.writeFileSync(
'dist/script-hash-list.json',
JSON.stringify(getHashList()),
);
});
}
return {
dir: {
input: 'src/site/content/', // we use a string path with the forward slash since windows doesn't like the paths generated from path.join
output: 'dist',
data: '../_data',
includes: '../_includes',
},
templateFormats: ['njk', 'md'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
// Because eleventy's passthroughFileCopy does not work with permalinks
// we need to manually copy assets ourselves using gulp.
// https://github.com/11ty/eleventy/issues/379
passthroughFileCopy: false,
};
};