-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
131 lines (112 loc) · 3.58 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
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
120
121
122
123
124
125
126
127
128
129
130
131
const collections = require('./config/collections')
const plugins = require('./config/plugins')
const shortcodes = require('./config/shortcodes.js')
const dateFilters = require('./config/filters/date.js')
const postFilters = require('./config/filters/posts.js')
const fs = require('fs')
const moment = require("moment")
module.exports = function (eleventyConfig) {
const markdownIt = require("markdown-it")
const markdownItFootnote = require("markdown-it-footnote")
const markdownItAttrs = require("markdown-it-attrs")
const markdownItAnchor = require('markdown-it-anchor')
const options = {
html: true,
breaks: true,
linkify: true
}
let markdownLib = markdownIt(options)
.use(markdownItFootnote)
.use(markdownItAttrs)
.use(markdownItAnchor)
eleventyConfig.setLibrary('md', markdownLib);
// Liquid options
eleventyConfig.setLiquidOptions({
dynamicPartials: true,
strict_filters: true,
root: ["src/_includes"],
extname: ".html"
});
// Passthroughs
['src/assets', '{ "node_modules/littlefoot/dist/littlefoot.js": "assets/js/littlefoot.js" }'].forEach(path => {
eleventyConfig.addPassthroughCopy(path, {
filter: path => !path.endsWith('.scss') && !path.startsWith('_')
})
})
// Plugins
plugins.forEach(plugin => {
eleventyConfig.addPlugin(require(plugin.name), { ...plugin.options })
})
// collections
Object.keys(collections).forEach(collectionName => {
eleventyConfig.addCollection(collectionName, collections[collectionName])
})
// Shortcodes
Object.keys(shortcodes).forEach(shortcodeName => {
eleventyConfig.addShortcode(shortcodeName, shortcodes[shortcodeName])
})
// SVG
let getSvgContent = function (file) {
let relativeFilePath = `./src/assets/${file}.svg`;
let data = fs.readFileSync(relativeFilePath,
function(err, contents) {
if (err) return err
return contents
});
return data.toString('utf8');
}
eleventyConfig.addShortcode("svg", getSvgContent)
const md = new markdownIt({
html: true
});
eleventyConfig.addPairedShortcode("markdown", (content) => {
return md.render(content);
});
// Filters
Object.keys(dateFilters).forEach(filterName => {
eleventyConfig.addFilter(filterName, dateFilters[filterName])
})
// Return all the tags used in a collection
eleventyConfig.addFilter("getAllTags", collection => {
let tagSet = new Set();
for(let item of collection) {
(item.data.tags || []).forEach(tag => tagSet.add(tag));
}
return Array.from(tagSet);
});
eleventyConfig.addFilter("filterTagList", function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "nav", "post", "posts", "page"].indexOf(tag) === -1);
});
eleventyConfig.addFilter("afterDateForRss", function afterDateForRss(collection) {
return collection.filter((p) => {
return moment(p.date).isAfter(moment("2018-08-01"));
});
});
// Object.keys(postFilters).forEach(filterName => {
// eleventyConfig.addFilter(filterName, dateFilters[filterName])
// })
// eleventyConfig.addPlugin(feedPlugin, {
// type: "atom", // or "rss", "json"
// outputPath: "/feed.xml",
// collection: {
// name: "post", // iterate over `collections.posts`
// limit: 10, // 0 means no limit
// },
// metadata: {
// language: "en",
// title: "Nic Lake",
// subtitle: "Life, technology, family, and more.",
// base: "https://niclake.me",
// author: {
// name: "Nic Lake",
// email: "niclake13@gmail.com", // Optional
// }
// }
// });
return {
dir: {
input: "src",
output: "_site",
}
}
};