-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleventy.config.js
144 lines (123 loc) · 3.74 KB
/
eleventy.config.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
const sass = require("sass");
const { feedPlugin } = require("@11ty/eleventy-plugin-rss");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const timeToRead = require('eleventy-plugin-time-to-read');
const markdownItExternalAnchor = require('markdown-it-external-anchor');
const prism = require('markdown-it-prism');
module.exports = function (eleventyConfig) {
const md = markdownIt({ "html": true }).use(markdownItAnchor, {
"level": 2,
permalink: markdownItAnchor.permalink.headerLink()
}).use(markdownItExternalAnchor, {
class: "link-external"
}).use(prism, {
highlightInlineCode: true,
plugins: [
"copy-to-clipboard",
"show-language",
"inline-color",
"toolbar"
]
});
eleventyConfig.setLibrary("md", md);
eleventyConfig.addTemplateFormats("scss");
// Creates the extension for use
eleventyConfig.addExtension("scss", {
outputFileExtension: "css", // optional, default: "html"
// `compile` is called once per .scss file in the input directory
compile: async function (inputContent) {
let result = sass.compileString(inputContent);
// This is the render function, `data` is the full data cascade
return async (data) => {
return result.css;
};
},
});
eleventyConfig.addPlugin(timeToRead, {
speed: '250 words a minute'
});
eleventyConfig.addCollection(
"allPosts",
function (collectionApi) {
return collectionApi.getFilteredByTags("post").sort((a, b) => (b.date - a.date)).filter((a) => {
return a.data.published != false;
});
}
);
eleventyConfig.addCollection(
"allProjects",
function (collectionApi) {
return collectionApi.getFilteredByTags("project").sort((a, b) => (b.date - a.date));
}
);
eleventyConfig.addPlugin(feedPlugin, {
type: "rss", // or "rss", "json"
outputPath: "/feed.xml",
collection: {
name: "allPosts",
limit: 0,
},
metadata: {
language: "en",
title: "Reboot/Fitz's Blog",
subtitle: "Bleh",
base: "https://www.reboot-codes.com/",
author: {
name: "Reboot/Fitz",
email: "[email protected]"
}
}
});
eleventyConfig.addFilter("startsWith", function(str, comp) {
return str.startsWith(comp);
});
eleventyConfig.addFilter("strSlice", function(str, num) {
return str.slice(num);
});
// 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", "post", "allPosts", "project", "allProjects", "featuredProject"].indexOf(tag) === -1).filter((tag) => (!(tag.startsWith("project:"))));
});
const parseDate = (str) => {
if (str instanceof Date) {
return str;
}
return Date.parse(str);
};
const formatPart = (part, date) =>
new Intl.DateTimeFormat("en", part).format(date);
eleventyConfig.addFilter("formatDate", async (obj) => {
if (!obj) {
return "";
}
const date = parseDate(obj);
const month = formatPart({ month: "short" }, date);
const day = formatPart({ day: "numeric" }, date);
const year = formatPart({ year: "numeric" }, date);
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();
if (hours != 0 && minutes != 0) {
return `${month} ${day}, ${year} - ${hours}:${minutes} UTC`;
}
return `${month} ${day}, ${year}`;
});
eleventyConfig.addPassthroughCopy({"src/public": "/"});
return {
dir: {
input: "src",
output: "dist",
includes: "_includes",
layouts: "_includes/layouts",
},
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk"
}
};