-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
135 lines (122 loc) Β· 4.73 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
const pluginRss = require('@11ty/eleventy-plugin-rss');
const pluginHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginPageAssets = require("eleventy-plugin-page-assets");
const pluginInclusiveLanguage = require("@11ty/eleventy-plugin-inclusive-language");
const del = require("del");
const htmlmin = require("html-minifier");
const readingtime = require("@myxotod/eleventy-plugin-readingtime");
const config = {
dir: {
input: 'src',
output: 'dist',
layouts: '_layouts',
includes: '_includes'
}
};
// Clear output folder
del.sync(config.dir.output, { dot: true })
module.exports = (eleventyConfig) => {
// Options
eleventyConfig.setQuietMode(true);
// Set global data
eleventyConfig.addGlobalData('accentcolor', 'rebeccapurple');
eleventyConfig.addGlobalData('layout', 'base');
eleventyConfig.addGlobalData('topbar', true);
eleventyConfig.addGlobalData('include_prism', false);
eleventyConfig.addGlobalData('include_fontawesome', false);
eleventyConfig.addGlobalData('fallbackcover', '/assets/images/fallback-cover.webp');
eleventyConfig.addGlobalData('sitemap', {
'priority': 0.5
});
eleventyConfig.addGlobalData('site', {
'url': 'https://www.makkusu.dev',
'title': 'makkusu.dev',
'builtAt': Date.now()
});
// Passthrough copies
eleventyConfig.addPassthroughCopy(config.dir.input + '/assets/stylesheets/application.min.css');
eleventyConfig.addPassthroughCopy(config.dir.input + '/assets/stylesheets/fontawesome.min.css');
eleventyConfig.addPassthroughCopy(config.dir.input + '/assets/images');
eleventyConfig.addPassthroughCopy(config.dir.input + '/assets/fonts');
eleventyConfig.addPassthroughCopy(config.dir.input + '/assets/javascripts');
eleventyConfig.addPassthroughCopy(config.dir.input + '/.htaccess');
eleventyConfig.addPassthroughCopy(config.dir.input + '/robots.txt');
eleventyConfig.addPlugin(pluginPageAssets, {
mode: 'directory',
assetsMatching: '*.png|*.jpg|*.jpeg|*.gif|*.svg|*.webp',
hashAssets: false,
postsMatching: config.dir.input + '/blog|hobbies|coding/**/*.md'
});
// Enable plugins
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginHighlight);
eleventyConfig.addPlugin(pluginInclusiveLanguage);
eleventyConfig.addPlugin(readingtime, {
verbose: true
});
// Filters
const publishedPosts = (post) => {
const now = new Date();
return post.date <= now && !post.data.draft;
};
eleventyConfig.addFilter('formatDate', (value) => {
if (value == 'now')
return value;
const date = new Date(value);
return date.toLocaleString('default', {
month: 'long',
year: 'numeric'
});
});
eleventyConfig.addFilter('formatDateFull', (value) => {
const date = new Date(value);
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
return date.getDate() + '. ' + months[date.getMonth()] + ' ' + date.getFullYear();
});
eleventyConfig.addFilter('publishedPosts', (data) => {
return data.filter(publishedPosts);
});
// Collections
eleventyConfig.addCollection('blog', (collectionApi) => {
return collectionApi.getFilteredByGlob(config.dir.input + '/blog/**/*.md')
.filter(publishedPosts);
});
eleventyConfig.addCollection('hobbies', (collectionApi) => {
return collectionApi.getFilteredByGlob(config.dir.input + '/hobbies/**/*.md')
.sort((a, b) => {
if (!a.data.order) a.data.order = 9999999;
if (!b.data.order) b.data.order = 9999999;
return a.data.order - b.data.order;
})
.filter(publishedPosts);
});
eleventyConfig.addCollection('page_coding', (collectionApi) => {
return collectionApi.getFilteredByGlob(config.dir.input + '/coding/**/*.md')
.filter(publishedPosts);
});
eleventyConfig.addCollection('sitemap', (collectionApi) => {
return collectionApi.getAll()
.sort((a, b) => b.data.sitemap.priority - a.data.sitemap.priority)
.filter(publishedPosts)
.filter(page => !page.data.sitemap.exclude);
});
eleventyConfig.addCollection('feed', (collectionApi) => {
return collectionApi.getFilteredByGlob([config.dir.input + '/blog/**/*.md', config.dir.input + '/coding/**/*.md'])
.filter(publishedPosts);
});
// Transforms
eleventyConfig.addTransform('htmlmin', (content, outputPath) => {
if (outputPath.endsWith('.html')) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
minified += "\r\n\r\n<!-- π½: Hello earthling, I was hiding here, but you found me. Take this πͺ -->";
return minified;
}
return content;
});
// Return global config
return config;
};