-
Notifications
You must be signed in to change notification settings - Fork 16
/
.eleventy.js
69 lines (58 loc) · 2.03 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
const CleanCSS = require('clean-css');
const generateSearchIndex = require('./_11ty/generate-search-index');
module.exports = function(config) {
config.addPassthroughCopy('site/img');
config.addPassthroughCopy('site/fonts');
config.addPassthroughCopy('site/sw.js');
config.addPassthroughCopy('site/manifest.json');
config.addFilter('cssmin', function(code) {
return new CleanCSS({}).minify(code).styles;
});
let markdownIt = require("markdown-it");
let markdownItDefList = require("markdown-it-deflist");
let options = {
html: true,
linkify: true,
breaks: true
};
let markdownLib = markdownIt(options).use(markdownItDefList);
config.setLibrary("md", markdownLib);
config.addShortcode("year", () => `${new Date().getFullYear()}`);
config.addCollection("posts", function(collection) {
const posts = collection.getFilteredByGlob([
"site/posts/**/*.md",
]);
posts.forEach(post => {
const date = new Date(post.data.date);
post.data.permalink = `/${date.getFullYear()}/${String(date.getMonth() + 1).padStart(2, '0')}/${String(date.getDate()).padStart(2, '0')}/${post.fileSlug}/`;
});
return posts;
});
config.addCollection("tagList", function(collection) {
const tagsSet = new Set();
collection.getAll().forEach(item => {
if (!item.data.tags) return;
const tags = Array.isArray(item.data.tags) ? item.data.tags : item.data.tags.split(',');
tags.forEach(tag => {
const trimmedTag = tag.trim();
if (trimmedTag) {
tagsSet.add(trimmedTag);
console.log('Added tag:', trimmedTag);
}
});
});
const sortedTags = Array.from(tagsSet).sort();
console.log('All tags:', sortedTags);
return sortedTags;
});
config.addCollection("searchIndex", async function(collection) {
const posts = collection.getFilteredByGlob(["site/posts/**/*.md"]);
return await generateSearchIndex(posts);
});
// Add global data
config.addGlobalData("localhost", process.argv.includes("--serve"));
return {
dir: { input: 'site', output: 'dist', includes: '_includes' },
passthroughFileCopy: true
};
};