-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.eleventy.js
82 lines (68 loc) · 2.83 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
const esbuild = require('esbuild');
const yaml = require("js-yaml");
const { execSync } = require('child_process')
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const markdownIt = require("markdown-it");
const markdownItNamedHeadings = require("markdown-it-named-headings");
const markdownOptions = {
html: true,
breaks: true,
linkify: true
};
const markdownRenderer = markdownIt(markdownOptions).use(markdownItNamedHeadings);
// shortcode requires
const twitter = require('./src/_includes/shortcodes/twitter')
const youtube = require('./src/_includes/shortcodes/youtube')
const vimeo = require('./src/_includes/shortcodes/vimeo')
const figure = require('./src/_includes/shortcodes/figure')
const gist = require('./src/_includes/shortcodes/gist')
const summary_divider = require('./src/_includes/shortcodes/summaryDivider')
const param = require('./src/_includes/shortcodes/param')
const reference = require('./src/_includes/shortcodes/reference')
const diffcode = require('./src/_includes/shortcodes/diffcode')
const tree = require('./src/_includes/shortcodes/tree')
module.exports = function(eleventyConfig) {
// shortcodes
eleventyConfig.addShortcode("twitter", twitter)
eleventyConfig.addShortcode("youtube", youtube)
eleventyConfig.addShortcode("vimeo", vimeo)
eleventyConfig.addShortcode("figure", figure)
eleventyConfig.addShortcode("gist", gist)
eleventyConfig.addShortcode("summary_divider", summary_divider)
eleventyConfig.addShortcode("param", param)
eleventyConfig.addShortcode("ref", reference)
eleventyConfig.addShortcode("diffcode", diffcode)
eleventyConfig.addShortcode("tree", tree)
eleventyConfig.setLibrary("md", markdownRenderer);
eleventyConfig.addDataExtension("yaml", contents => yaml.load(contents));
eleventyConfig.addDataExtension("yml", contents => yaml.load(contents));
eleventyConfig.addPassthroughCopy("src/assets/images");
// esbuild
eleventyConfig.addWatchTarget('./src/assets/js/**');
eleventyConfig.on('eleventy.before', async () => {
await esbuild.build({
entryPoints: ['src/assets/js/**'],
outdir: '_site/js',
bundle: true,
minify: true,
sourcemap: true,
});
});
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addFilter("process_content", text => {
text = text.replace(/(<h[2-6]\sid=\"([^\"]+)\"\s?>)(.+)(<\/h[2-6]+>)/, "$1<a data-pagefind-ignore class=\"anchor\" href=\"#$2\" title=\"Link to $3\">#</a>$3$4")
text = text.replace(/<code>([^<]{0,30})<\/code>/, "<code class=\"inline\">$1</code>")
return text;
});
eleventyConfig.addFilter("excerpt", content => {
content = content.replace(/(<([^>]+)>)/gi, "");
return content.substr(0, content.lastIndexOf(" ", 200)) + "...";
});
return {
dir: {
input: "src",
output: "_site",
includes: "_includes"
}
}
};