-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
executable file
·294 lines (235 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
const htmlmin = require('html-minifier');
const markdownIt = require("markdown-it");
const hljs = require('highlight.js');
const { render } = require('./src/_layouts/presentation.11ty');
const pathPrefix = (process.env.ELEVENTY_ENV === 'production') ? "slides" : "";
const ghPagesFolder = "docs";
const md = new markdownIt({
html: true,
});
const highlightCode = (lang, code) => {
if (lang && hljs.getLanguage(lang)) {
try {
const highlightedCode = `<pre class="code-wrapper"><samp class="code">${hljs.highlight(lang, code).value}</samp></pre>`
return highlightedCode.replace(/<span class="hljs-comment">\/\*\*\/<\/span>/g, "<span class='hljs-break'>/* break */</span>");
} catch (__) {}
}
return ''; // use external default escaping
};
const insertMarkup = (string)=>{
string = string.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>", string);
return string.replace(/\*(.*?)\*/g, "<mark>$1</mark>", string);
}
const insertColor = (string, colorClass)=>{
const color = (colorClass) ? colorClass : "is-purple";
return string.replace(/\/\//g, "<span class="+color+">//</span>", string);
}
const getPresentationData = (collection, pattern)=>{
const allSlides = collection.getFilteredByGlob(pattern);
return allSlides.sort((a, b) => {
if (a.fileSlug > b.fileSlug) return 1;
else a.fileSlug < b.fileSlug
return -1;
});
}
const renderCode = (code, lang) => {
return `${highlightCode(lang, code)}`;
};
module.exports = function (eleventyConfig) {
eleventyConfig.setWatchThrottleWaitTime(500);
eleventyConfig.setUseGitIgnore(false);
eleventyConfig.setWatchJavaScriptDependencies(true);
eleventyConfig.setBrowserSyncConfig({
snippet: true,
});
/* Compilation
########################################################################## */
// Watch our compiled assets for changes
// eleventyConfig.addWatchTarget('./src/compiled-assets/main.css');
eleventyConfig.addWatchTarget('./src/assets/scripts/main.js');
// Copy _data
eleventyConfig.addPassthroughCopy({'src/_data': 'assets/data'});
// Copy src/compiled-assets to /assets
eleventyConfig.addPassthroughCopy({'src/compiled-assets': 'assets'});
// Copy all fonts
eleventyConfig.addPassthroughCopy({'src/assets/fonts': 'assets/fonts'});
// Copy asset images
eleventyConfig.addPassthroughCopy({'src/assets/images': 'assets/images'});
// Copy asset icons
eleventyConfig.addPassthroughCopy({'src/assets/icons': 'assets/icons'});
// Copy images
eleventyConfig.addPassthroughCopy('src/presentations/**/images/*.{jpg,png,svg,jpeg, gif}');
eleventyConfig.addPassthroughCopy('src/presentations/**/images/**/*.{jpg,png,svg,jpeg,gif}');
// Copy Reveal Stuff
eleventyConfig.addPassthroughCopy({'reveal/dist': 'reveal/dist'});
eleventyConfig.addPassthroughCopy({'reveal/plugin': 'reveal/plugin'});
// Copy Scripts
eleventyConfig.addPassthroughCopy({'src/assets/scripts': 'assets/scripts'});
eleventyConfig.addWatchTarget("./src/assets/scripts");
// Copy Manifest
eleventyConfig.addPassthroughCopy({'src/manifest.json': 'manifest.json'});
/* Functions
########################################################################## */
eleventyConfig.addJavaScriptFunction("urlPrefix", function() {
return pathPrefix;
});
eleventyConfig.addJavaScriptFunction("markdown", function(content) {
return md.render(content);
});
/* Filter
########################################################################## */
eleventyConfig.addFilter("presentationByTopic", function (topic) {
eleventyConfig.addCollection(topic, (collection) => {
return collection.getFilteredByGlob(`./src/presentations/${topic}/*.md`);
});
return topic;
});
/* Collections
########################################################################## */
eleventyConfig.addCollection("screendesign", (collection) => {
return presentations = getPresentationData(collection, "./src/presentations/screendesign/**/index.md");
});
eleventyConfig.addCollection("misc", (collection) => {
return presentations = getPresentationData(collection, "./src/presentations/misc/**/index.md");
});
eleventyConfig.addCollection("all", function (collection) {
return collection.getAll();
});
eleventyConfig.addCollection("sorted", function (collection) {
return presentations = collection.getFilteredByGlob("./src/presentations/**/*.md").sort((a, b) => {
const filenameFromA = a.filePathStem.split(/\//).pop();
if (filenameFromA === 'index') return 1;
else if (a.fileSlug > b.fileSlug) return 1;
else if (a.fileSlug < b.fileSlug) return -1;
else return 0;
});
});
/* Shortcodes
########################################################################## */
eleventyConfig.addShortcode('screenshot', (imgSrc, props) => {
const propData = (props) ? JSON.parse(props) : {};
const dataTransition = propData && propData.transition ? `data-transition="${propData.transition}"` : '';
const dataBackgroundTransition = propData && propData.backgroundTransition ? `data-background-transition="${propData.backgroundTransition}"` : '';
const classes = propData && propData.classes ? propData.classes : '';
const width = propData && propData.width ? `width="${propData.width}" ` : '';
const buCreditHtml = propData && propData.credit ? `<p class="credit">${propData.credit}</p>` : '';
const buHtml = propData && propData.bu ? `<figcaption class="bu"><p>${insertMarkup(propData.bu)}</p></figcaption>` : '';
return `<section data-slide-shortcode-class="screenshot" class="image screenshot ${classes}" ${dataTransition} ${dataBackgroundTransition}><figure><img src="${imgSrc}" alt="${imgSrc}" ${width}>${buHtml}</figure></section>`;
});
eleventyConfig.addShortcode('screenshotFs', (imgSrc, props) => {
const propData = (props) ? JSON.parse(props) : {};
const dataTransition = propData && propData.transition ? `data-transition="${propData.transition}"` : '';
const dataBackgroundTransition = propData && propData.backgroundTransition ? `data-background-transition="${propData.backgroundTransition}"` : '';
const classes = propData && propData.classes ? propData.classes : '';
const buCreditHtml = propData && propData.credit ? `<p class="credit">${propData.credit}</p>` : '';
const buHtml = propData && propData.bu ? `<div class="bu"><p>${insertMarkup(md.render(propData.bu))}</p></div>` : '';
return `<section data-slide-shortcode-class="screenshot" class="image is-fullscreen ${classes}" data-background="${imgSrc}" ${dataTransition} ${dataBackgroundTransition}>${buHtml}</section>`;
});
eleventyConfig.addShortcode('meta',()=>{
return `<meta name="robots" content="noindex">
<meta name="googlebot" content="noindex">
<meta name="googlebot-news" content="noindex">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
`});
eleventyConfig.addShortcode('interlude', (title, subtitle, transition) => {
const getRandomBackgroundColor = ()=>{
const colors = ['#4952e1', '#d16', '#00ad2f', '#9313ce', '#2b2b2b'];
return colors[colors.length * Math.random() | 0];
}
const htmlSubtitle = subtitle ? `<h2 class="subtitle js-delay">${md.render(subtitle)}</h2>` : '';
const dataTransition = transition ? `data-transition="${transition}"` : '';
return `<section data-slide-shortcode-class="interlude" data-background-color="${getRandomBackgroundColor()}" class="image screenshot interlude" ${dataTransition}><div><h1 class="title">${insertMarkup(title)}</h1>${htmlSubtitle}</div></section>`;
});
eleventyConfig.addShortcode('question', (question, tagline) => {
const htmlTagline = tagline ? `<h2 class="subtitle js-delay">${tagline}</h2>` : '';
return `<section data-slide-shortcode-class="question" class="question"><div><h1 class="title">${md.render(question)}</h1>${htmlTagline}</div></section>`;
});
eleventyConfig.addShortcode('simpleText', (title, text, transition) => {
const titleHtml = title ? `<h1 class="title">${insertMarkup(title)}</h1>` : '';
const dataTransition = transition ? `data-transition="${transition}"` : '';
return `<section data-slide-shortcode-class="simple-text" class="simple" ${dataTransition}>
<div>${titleHtml}${md.render(text)}</div></section>`;
});
eleventyConfig.addShortcode('codeSmall', (title, content, code, lang, transition) => {
const codeBlocks = typeof code !== 'object'
? highlightCode(lang, code)
: `<div class="code-columns">${code.map((codeBlock) => {
const {code} = codeBlock;
const lang = codeBlock.lang ? codeBlock.lang : 'html';
return highlightCode(lang, code);
}).join('')}</div>`;
const dataTransition = transition ? `data-transition="${transition}"` : '';
const contentBlock = content.match(/[a-zA-Z0-9]/) ? content : '.';
return `
<section ${dataTransition} data-slide-shortcode-class="codeSmall" class="codeSmall"><div><h1 class="title">${title}</h1>${md.render(contentBlock)}${codeBlocks}</div></section>`
;
});
eleventyConfig.addShortcode('important', (content) => {
return `<div class="is-important">${md.render(content)}</div>`;
});
eleventyConfig.addShortcode('statement', (title, content, props) => {
const propData = (props) ? JSON.parse(props) : {};
const fragment = content && content.length > 0 ? `<div class="fragment">${insertMarkup(content)}</div>`: '';
const dataBackgroundTransition = propData && propData.backgroundTransition ? `data-background-transition="${propData.backgroundTransition}"` : '';
return `<section ${dataBackgroundTransition} class="statement"><div><h1 class="title">${insertMarkup(title)}</h1>${fragment}</div></section>`;
});
eleventyConfig.addShortcode('cite', (title, content, props) => {
const propData = (props) ? JSON.parse(props) : {};
return `<section data-slide-shortcode-class="cite" class="cite"><div class="cite"><blockquote class="typo-quote"><p>${insertMarkup(title)}</p><cite></cite></blockquote></div></section>`;
});
eleventyConfig.addShortcode('niceToKnow', (content, props) => {
const propData = (props) ? JSON.parse(props) : {};
return `<div class="is-add-on-info">${md.render(content)}</div>`;
});
eleventyConfig.addShortcode('fragment', (content, props) => {
const propData = (props) ? JSON.parse(props) : {};
return `<div data-slide-shortcode-class="fragment" class="fragment">${insertMarkup(content)}</div>`;
});
eleventyConfig.addShortcode('splitView', (title, content, props) => {
return `<section class="split-view"><div><h1 class="title">${insertMarkup(title)}</h1>${insertMarkup(content)}</div></section>`;
});
eleventyConfig.addShortcode('qa', (q, a, props) => {
const propData = (props) ? JSON.parse(props) : {};
const dataTransition = propData && propData.transition ? `data-transition="${propData.transition}"` : '';
let answer = insertMarkup(a);
answer = insertColor(answer, "is-green");
return `<section data-slide-shortcode-class="qa" class="qa" ${dataTransition}><div class="qa-wrap"><h1 class="qa-question">${q}</h1><p class="qa-answer fragment">${answer}</p></div></section>`;
});
eleventyConfig.setServerOptions({
showAllHosts: true
});
/* Environment
########################################################################## */
if (process.env.ELEVENTY_ENV === 'production') {
eleventyConfig.addTransform('htmlmin', (content, outputPath) => {
if (outputPath.endsWith('.html')) {
return content;
return minified = htmlmin.minify(content, {
collapseInlineTagWhitespace: false,
collapseWhitespace: true,
removeComments: true,
sortClassName: true,
useShortDoctype: true,
});
}
return content;
});
}
return {
dir: {
includes: '_components',
input: 'src',
layouts: '_layouts',
output: 'docs',
},
pathPrefix: pathPrefix,
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
templateFormats: [
'md',
'html',
'njk'
],
};
};