-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eleventy.js
71 lines (53 loc) · 2.32 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
const utilities = require('./util/utilities')
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("assets");
eleventyConfig.addPassthroughCopy("favicon.ico");
// grab 3rd party dependencies
eleventyConfig.addPassthroughCopy({
"node_modules/mark.js/dist/mark.min.js": "/assets/mark.js",
"node_modules/details-polyfill/index.js": "/assets/details-polyfill.js"
});
eleventyConfig.addCollection("FaqsByTopic", async c => {
const buildFAQsByTopic = require('./util/faqsByTopic')
let col = await buildFAQsByTopic()
return col
});
eleventyConfig.addAsyncShortcode("ldJson", async() => await require('./util/ldJson')());
eleventyConfig.addShortcode("now", () => utilities.getCurrentTimestamp());
eleventyConfig.addFilter("prettyDate", utilities.prettyDate)
eleventyConfig.addFilter("slugify", title => utilities.slugify(title))
let md = customizeMarkdown();
eleventyConfig.addFilter("md", content => md.render(content))
eleventyConfig.setLibrary("md", md);
return {};
};
function customizeMarkdown() {
let md = require("markdown-it")({
html: true,
linkify: true
});
// Remember old renderer, if overridden, or proxy to default renderer
let defaultAnchorRender = md.renderer.rules.link_open || function(tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};
md.renderer.rules.link_open = function(tokens, idx, options, env, self) {
// If you are sure other plugins can't add `target` - drop check below
let token = tokens[idx]
let setAttribute = function(token, attrName, attrValue, append) {
var index = token.attrIndex(attrName);
if (index < 0) {
// add new attribute
token.attrPush([attrName, attrValue]);
} else {
// update value of existing attr
token.attrs[index][1] = (append ? token.attrs[index][1] : "") + attrValue;
}
}
setAttribute(token, "target", "_blank")
setAttribute(token, "rel", "noopener")
setAttribute(token, "class", " external-link", true)
// pass token to default renderer.
return defaultAnchorRender(tokens, idx, options, env, self);
};
return md
}