-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
110 lines (91 loc) · 3.09 KB
/
.eleventy.js
File metadata and controls
110 lines (91 loc) · 3.09 KB
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
const { DateTime } = require("luxon");
const readingTime = require("reading-time");
const markdownIt = require("markdown-it");
const markdownItKatex = require("markdown-it-katex");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginRss = require("@11ty/eleventy-plugin-rss");
module.exports = function(eleventyConfig) {
// Plugins
eleventyConfig.addPlugin(pluginSyntaxHighlight, {
alwaysWrapLineHighlights: false,
trim: true
});
eleventyConfig.addPlugin(pluginRss);
// Passthrough file copies
eleventyConfig.addPassthroughCopy("src/assets/css");
eleventyConfig.addPassthroughCopy("src/assets/js");
eleventyConfig.addPassthroughCopy("src/assets/images");
eleventyConfig.addPassthroughCopy("src/assets/fonts");
// Collections
eleventyConfig.addCollection("posts", function(collectionApi) {
return collectionApi.getFilteredByGlob("src/content/blog/posts/*.md")
.filter(item => !item.data.draft)
.sort((a, b) => b.date - a.date);
});
eleventyConfig.addCollection("featuredPosts", function(collectionApi) {
return collectionApi.getFilteredByGlob("src/content/blog/posts/*.md")
.filter(item => item.data.featured && !item.data.draft)
.sort((a, b) => b.date - a.date)
.slice(0, 3);
});
eleventyConfig.addCollection("pages", function(collectionApi) {
return collectionApi.getFilteredByGlob("src/content/pages/*.md");
});
// Filters
eleventyConfig.addFilter("date", (dateObj) => {
return DateTime.fromJSDate(dateObj).toLocaleString(DateTime.DATE_MED);
});
eleventyConfig.addFilter("dateIso", (dateObj) => {
return DateTime.fromJSDate(dateObj).toISODate();
});
eleventyConfig.addFilter("readableDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).setZone("America/Santiago").toFormat("MMMM dd, yyyy");
});
eleventyConfig.addFilter("readingTime", (content) => {
return Math.ceil(readingTime(content).minutes);
});
eleventyConfig.addFilter("markdownify", (str) => {
const md = new markdownIt();
return md.render(str);
});
eleventyConfig.addFilter("excerpt", (str) => {
if (!str) return "";
return str.substring(0, 160);
});
eleventyConfig.addFilter("absoluteUrl", (url) => {
const siteUrl = eleventyConfig.globalData.site.url;
return siteUrl + url;
});
// Template Formats
eleventyConfig.setTemplateFormats(["md", "njk", "html"]);
// Markdown Library
const mdLibrary = markdownIt({
html: true,
breaks: true,
linkify: true,
typographer: true
});
mdLibrary.use(markdownItKatex);
eleventyConfig.setLibrary("md", mdLibrary);
// Watch Targets
eleventyConfig.addWatchTarget("src/assets/css/");
eleventyConfig.addWatchTarget("src/assets/js/");
// Server Options
eleventyConfig.setServerOptions({
port: 8080,
watch: true,
liveReload: true
});
return {
dir: {
input: "src",
output: "_site",
includes: "_includes",
data: "_data"
},
templateFormats: ["md", "njk", "html"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
passthroughFileCopy: true
};
};