forked from parcel-bundler/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
116 lines (101 loc) · 3.23 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
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const pluginSass = require("eleventy-plugin-sass");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight, {
templateFormats: ["*"],
alwaysWrapLineHighlights: false,
});
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.setDataDeepMerge(true);
eleventyConfig.addPlugin(pluginSass, { watch: ["src/*.{scss,sass}"] });
eleventyConfig.addPassthroughCopy("assets");
eleventyConfig.setTemplateFormats(["md", "css", "png", "svg"]);
eleventyConfig.addWatchTarget("./api/");
eleventyConfig.setLibrary(
"md",
markdownIt({
html: true,
}).use(markdownItAnchor, {
permalink: true,
permalinkBefore: true,
})
);
// ---------- Macros ----------
eleventyConfig.addFilter("sortDate", function (data) {
return [...data].sort((a, b) => b.date - a.date);
});
eleventyConfig.addFilter("pageUrl", function (page) {
return page.url;
});
eleventyConfig.addFilter("toDate", function (date) {
return `${date.getDate()}.${date.getMonth() + 1}.${date.getFullYear()}`;
});
eleventyConfig.addPairedShortcode("note", function (content) {
return `<figure class="well"><div>${content}</div></figure>`;
});
eleventyConfig.addPairedShortcode("warning", function (content) {
return `<figure class="well warning"><div>${content}</div></figure>`;
});
eleventyConfig.addPairedShortcode("error", function (content) {
return `<figure class="well error"><div>${content}</div></figure>`;
});
eleventyConfig.addPairedShortcode("sample", function (content, cmd, mode) {
let data = content
.split("\n")
.filter(Boolean)
.map((s) => JSON.parse(s));
return (
`<figure class="well sample ${
mode === "column" ? "column" : "row"
}">\n\n` +
(cmd ? `<div class="cmd"><code>${cmd}</code></div>` : "") +
`<div class="assets">\n` +
`${data
.map(
({ name, content }) =>
`<div class="asset">` +
(name ? `<em>${name}</em>:` : "<span> </span>") +
content +
`</div>`
)
.join("\n")}\n` +
`</div>\n` +
`</figure>`
);
});
eleventyConfig.addPairedShortcode("samplefile", function (content, name) {
return JSON.stringify({ name, content });
});
eleventyConfig.addPairedShortcode("migration", function (content) {
let assets = content
.split("\n")
.filter(Boolean)
.map((s) => JSON.parse(s));
if (assets.length === 1) assets.splice(0, 0, null);
return (
`<figure class="well warning migration">\n\n` +
`<div class="assets">\n` +
assets
.map((a) =>
a
? `<div class="asset">` +
(a.name ? `<em>${a.name}</em>:` : "") +
a.content +
`</div>`
: ""
)
.join(`<div class='arrow'></div>\n`) +
`</div>\n` +
`</figure>`
);
});
return {
dir: {
input: "src",
},
markdownTemplateEngine: "njk",
};
};