-
Notifications
You must be signed in to change notification settings - Fork 4
/
.eleventy.js
64 lines (56 loc) · 1.77 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
const chalk = require("chalk");
module.exports = function(eleventyConfig) {
let markdownIt = require("markdown-it");
let markdownItDeflist = require("markdown-it-deflist");
let markdownItAnchor = require("markdown-it-anchor");
let { markdownItImageSize } = require("markdown-it-image-size");
let pluginTOC = require('eleventy-plugin-toc')
let slugify = function (s) {
let newStr = String(s).trim().toLowerCase()
.replace(/\s+/g, '-')
.replace(/[():.,&'`]/g, '');
return encodeURIComponent(newStr);
}
let markdownItAnchorOpts = {
slugify,
};
let options = {
html: true,
};
eleventyConfig.addShortcode("ref", function(page, title) {
return `<a href="/${page}/#${slugify(title)}">${title}</a>`;
});
eleventyConfig.setLibrary("md", markdownIt(options)
.use(markdownItAnchor, markdownItAnchorOpts)
.use(markdownItDeflist)
.use(markdownItImageSize)
);
eleventyConfig.addPassthroughCopy("_assets");
eleventyConfig.addPlugin(pluginTOC);
eleventyConfig.addTransform("ellipsis", async function(content, outputPath) {
return content.replace(/\.\.\./g, "…");
});
eleventyConfig.addLinter("naked-url", async function(content, inputPath, outputPath) {
if (!(inputPath.endsWith(".md"))) {
return;
}
const nakedUrlRegexp = /(?:[^<>";]|^)(https?:(?:[^<\s]+))/g
const matches = content.matchAll(nakedUrlRegexp);
const found = [];
for (const match of matches) {
found.push(match[1]);
}
if (found.length) {
console.warn(chalk.yellow(`Naked URL Linter (${inputPath}):`));
console.warn(" " + found.join("\n" + " "));
}
});
return {
passthroughFileCopy: true,
dir: {
input: "manuscript",
output: "_site",
includes: "../_includes"
}
};
};