-
Notifications
You must be signed in to change notification settings - Fork 12
/
.eleventy.js
52 lines (43 loc) · 2.19 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
// This escapes the HTML inside the example code block
function escapeHtml(unsafe) {
return unsafe
.replace(/\<br\>/g, "\n")
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addLayoutAlias('home', 'layouts/home.html');
eleventyConfig.addLayoutAlias('page', 'layouts/page.html');
eleventyConfig.addLayoutAlias('playground', 'layouts/playground.html');
// When the linked css or javascript changes and we are in dev mode, update in the browser
eleventyConfig.setServerPassthroughCopyBehavior("passthrough");
// Make sure to either copy (or passthrough from original location for dev server) needed files
eleventyConfig.addPassthroughCopy("assets/**/*");
eleventyConfig.addPassthroughCopy("dist/**/*");
eleventyConfig.addPassthroughCopy("js/**/*.js");
// For source maps, pass through scss as well
eleventyConfig.addPassthroughCopy("src/**/*.scss");
eleventyConfig.addPairedShortcode("example", function (content, id, application_notice, further_preview_class) {
content = content.trim();
if (application_notice) {
return `<h5 id="example-${id}">Example</h5><div class="d-example"><pre class="d-example-code"><code>${escapeHtml(content)}</code></pre><div class="d-example-preview ${further_preview_class}">${content}<p><span class="has-color-tertiary-600 has-font-size-caption has-font-style-italic">${application_notice}</span></p></div></div>`;
}
return `<h5 id="example-${id}">Example</h5><div class="d-example"><pre class="d-example-code"><code>${escapeHtml(content)}</code></pre><div class="d-example-preview ${further_preview_class}">${content}</div></div>`;
});
eleventyConfig.addPairedShortcode("notice", function (content, title) {
content = content.trim();
return `<div class="notice is-warning"><h4>${title}</h4><p>${content}</div>`;
});
return {
pathPrefix: process.env.ELEVENTY_PATH_PREFIX || "",
dir: {
input: "docs_src",
output: "docs"
},
};
};