-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheleventy.config.js
More file actions
119 lines (105 loc) · 4 KB
/
Copy patheleventy.config.js
File metadata and controls
119 lines (105 loc) · 4 KB
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
const blockEmbedPlugin = require("markdown-it-block-embed");
const frame = require("markdown-it-iframe");
const flatten = require("flat");
const featureTable = require("./plugins/featureTable.js");
const gitlabreleases = require("./plugins/gitlabreleases.js");
const addId = require("./plugins/addID.js");
const html5Embed = require("markdown-it-html5-embed");
const implicitFigures = require("markdown-it-implicit-figures");
const markdownIt = require("markdown-it");
const pluginTOC = require("eleventy-plugin-nesting-toc");
module.exports = function(eleventyConfig) {
// plugins
eleventyConfig.addPlugin(gitlabreleases);
eleventyConfig.addPlugin(pluginTOC, {
tags: ["h2", "h3", "h4"], // which heading tags are selected headings must each have an ID attribute
wrapper: "nav", // element to put around the root `ol`/`ul`
wrapperClass: "toc", // class for the element around the root `ol`/`ul`
ul: false, // if to use `ul` instead of `ol`
flat: false,
});
eleventyConfig.addPlugin(featureTable);
eleventyConfig.addPlugin(addId);
eleventyConfig.addFilter("prependLinks", function(value, prepend) {
let regex = /<a href="/g;
return value.replace(regex, `<a href="${prepend}`);
});
eleventyConfig.addCollection("sortedByOrder", function(collectionApi) {
return collectionApi.getAll().sort((a, b) => {
const numA = parseInt(a.data.order);
const numB = parseInt(b.data.order);
return numA - numB;
});
});
eleventyConfig.addCollection("news", function(collectionApi) {
return collectionApi.getFilteredByGlob("./src/content/blog/entries/*.md");
});
eleventyConfig.addCollection("featuresTable", function(collectionApi) {
return collectionApi.getFilteredByGlob(
"./src/content/features/featureList.md"
);
});
// files copy
eleventyConfig.addPassthroughCopy({ "static/css": "css" });
eleventyConfig.addPassthroughCopy({ "static/js": "js" });
eleventyConfig.addPassthroughCopy({ "static/admin": "admin" });
eleventyConfig.addPassthroughCopy({ "static/images": "images" });
eleventyConfig.addPassthroughCopy({ "static/font": "font" });
eleventyConfig.addPassthroughCopy({ "static/images/favicons": "/" });
// packages for markdown
let markdownLib = markdownIt({ html: true })
.use(implicitFigures, {
dataType: false, // <figure data-type="image">, default: false
figcaption: false, // <figcaption>alternative text</figcaption>, default: false
tabindex: true, // <figure tabindex="1+n">..., default: false
// link: true, // <a href="img.png"><img src="img.png"></a>, default: false
})
.use(frame)
.use(blockEmbedPlugin, {
containerClassName: "video-embed",
outputPlayerSize: false,
})
.use(html5Embed, {
html5embed: {
useImageSyntax: true, // Enables video/audio embed with ![]() syntax (default)
useLinkSyntax: true, // Enables video/audio embed with []() syntax
},
});
eleventyConfig.setLibrary("md", markdownLib);
eleventyConfig.addFilter("markdownify", (value) => markdownLib.render(value));
eleventyConfig.addFilter("showAvailableMeta", function(value) {
return propertiesToArray(value);
});
eleventyConfig.addFilter("fulldate", (value) => {
const options = {
year: "numeric",
month: "long",
day: "numeric",
};
const date = new Date(value);
if (isNaN(date)) return value;
return Intl.DateTimeFormat("en-GB", options).format(date);
});
eleventyConfig.addFilter("urldate", (value) => {
const date = new Date(value);
if (isNaN(date)) return value;
return date.toISOString().split("T")[0];
});
return {
dir: {
input: "src",
output: "public",
includes: "layouts",
data: "data",
},
};
};
function propertiesToArray(value) {
let stuff = flatten(value, { maxDepth: 10 });
let content = "";
for (var key in stuff) {
content += `<section><div class="meta">${key}</div><div class="value">${stuff[key] != null ? stuff[key] : ""
}</div></section>`;
}
return content;
}