forked from vtcodecamp/2019.vtcodecamp.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
79 lines (63 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
72
73
74
75
76
77
78
79
module.exports = function(eleventyConfig) {
// Copy the `assets/` directory (css, images, etc)
eleventyConfig.addPassthroughCopy("src/assets");
eleventyConfig.addPassthroughCopy("src/favicon.ico");
// add cssmin filter
const CleanCSS = require("clean-css");
eleventyConfig.addFilter("cssmin", function(code) {
return new CleanCSS({}).minify(code).styles;
});
eleventyConfig.addFilter("RootURL", function(value) {
return value.replace('/src','');
});
var enable = ["normalize", "block", "inline", "linkify", "autolink", 'link', 'backticks', 'emphasis', "paragraph", "text", "newline"]
var md = require('markdown-it')('zero',{linkify: true}).enable(enable);
eleventyConfig.addFilter("minimalMarkdown", function(string) {
return md.render(string);
});
eleventyConfig.addFilter("to12hourTime", function(timeString) {
let date = new Date(timeString);
let time = date.toLocaleTimeString('en-US', {
timezone: 'America/New_York',
hour12: true,
hour: 'numeric',
minute: 'numeric',
})
return time;
});
// set markdown defaults (inline so we can extend)
let markdownIt = require("markdown-it");
let options = {
html: true,
breaks: true,
linkify: true
};
// add markdown anchor options
let markdownItAnchor = require("markdown-it-anchor");
let opts = {
permalink: false,
slugify: function(s) {
// strip special chars
let newStr = s.replace(/[^a-z ]/gi,'').trim();
// take first 4 words and separate with "-""
newStr = newStr.split(" ").slice(0,4).join("-");
return newStr;
},
permalinkClass: "direct-link",
permalinkSymbol: "#",
level: [1,2,3,4]
};
eleventyConfig.setLibrary("md", markdownIt(options).use(markdownItAnchor, opts));
// add table of contents plugin
const pluginTOC = require('eleventy-plugin-nesting-toc');
eleventyConfig.addPlugin(pluginTOC);
return {
dir: {
input: "src",
},
passthroughFileCopy: true,
// By default markdown files are pre-processing with liquid template engine
// https://www.11ty.io/docs/config/#default-template-engine-for-markdown-files
markdownTemplateEngine: "njk",
};
};