generated from tempertemper/eleventy-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
146 lines (125 loc) · 4.38 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
module.exports = function(eleventyConfig) {
eleventyConfig.setUseGitIgnore(false);
// Date filter
eleventyConfig.addFilter("date", require("./lib/filters/dates.js") );
eleventyConfig.addFilter("isoDate", require("./lib/filters/isoDate.js") );
// Generate assets
eleventyConfig.addPassthroughCopy({ "src/img": "img" });
eleventyConfig.addPassthroughCopy({ "src/txt": "txt" });
eleventyConfig.addPassthroughCopy({ "src/pdf": "pdf" });
// Smart quotes filter
const smartypants = require("smartypants");
eleventyConfig.addFilter("smart", str => smartypants.smartypants(str, 'qDe'));
// Markdown Plugins
var uslug = require('uslug');
var uslugify = s => uslug(s);
var anchor = require('markdown-it-anchor');
var markdownIt = require("markdown-it");
eleventyConfig.setLibrary("md", markdownIt({
html: true,
typographer: true
}).use(anchor, {slugify: uslugify, tabIndex: false}));
var mdIntro = markdownIt({
typographer: true
});
eleventyConfig.addFilter("markdown", markdown => mdIntro.render(markdown));
const slugify = require("slugify");
eleventyConfig.addFilter("slugify", str => {
return slugify(str, {
customReplacements: [
['+', ' plus '],
['@', ' at ']
],
remove: /[*~.,–—()'"‘’“”!?:;]/g,
lower: true
});
});
// Code syntax highlighting
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
eleventyConfig.addPlugin(syntaxHighlight, {
templateFormats: ["njk", "md"]
});
// RSS
const pluginRss = require("@11ty/eleventy-plugin-rss");
eleventyConfig.addPlugin(pluginRss);
// List all topics for a type of content
eleventyConfig.addFilter("getTopics", (arr) => {
const notRendered = ['all', 'post', 'research', 'software', 'other'];
const topics = arr.map(post => post.data.tags).flat().filter(d => !notRendered.includes(d)).sort();
const uniqueTopics = [...new Set(topics)];
return uniqueTopics;
});
// List all tags
eleventyConfig.addFilter("tags", collection => {
const notRendered = ['all', 'post', 'research', 'software', 'other'];
return Object.keys(collection)
.filter(d => !notRendered.includes(d))
.sort();
});
// List tags belonging to a page
eleventyConfig.addFilter("tagsOnPage", tags => {
const notRendered = ['all', 'post', 'research', 'software', 'other'];
return tags
.filter(d => !notRendered.includes(d))
.sort();
});
// Sort by order in front matter
eleventyConfig.addFilter("ordered", collection => {
return collection.sort((a, b) => a.data.order - b.data.order);
});
// Add limit for output
eleventyConfig.addFilter("limit", (arr, limit) => {
return arr.slice(0, limit);
});
// Remove current post from output
eleventyConfig.addFilter("removeCurrent", (arr, title) => {
return arr.filter(item => {
return item.url && item.data.title !== title;
});
});
// Get all the years that blog posts were posted
eleventyConfig.addFilter("getYears", (arr) => {
const dates = arr.map(post => post.date.getFullYear());
const uniqueYears = [...new Set(dates)];
return uniqueYears;
});
// Filter items by year
eleventyConfig.addFilter("filterByYear", (arr, year) => {
return arr.filter(item => {
return item.date.getFullYear() == year;
})
});
// Get current year for footer
eleventyConfig.addFilter("getCurrentYear", () => new Date().getFullYear());
// Get current date
eleventyConfig.addFilter("getCurrentDate", () => {
const today = new Date();
const dd = String(today.getDate()).padStart(2, '0');
const mm = String(today.getMonth() + 1).padStart(2, '0');
const yyyy = today.getFullYear();
return yyyy + '/' + mm + '/' + dd;
});
// Select type filter
eleventyConfig.addFilter("selectattr", function (arr, attr, value) {
return arr.filter((item) => item.data[attr] === value);
});
// Reject type filter
eleventyConfig.addFilter("rejectattr", function (arr, attr, value) {
return arr.filter((item) => item.data[attr] !== value);
});
// Localhost server config
eleventyConfig.setServerOptions({
port: 3000,
});
return {
dir: {
input: "src/site",
output: "dist",
includes: "_includes",
layouts: "_layouts"
},
templateFormats : ["njk", "html", "md", "txt", "webmanifest", "ico"],
htmlTemplateEngine : "njk",
markdownTemplateEngine : "njk"
};
};