-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.js
130 lines (99 loc) · 3.78 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
const { UserConfig } = require("@11ty/eleventy/src/UserConfig");
const markdownIt = require("markdown-it");
const markdownItAttrs = require("markdown-it-attrs");
const markdownItFootNotes = require("markdown-it-footnote");
const moment = require("moment");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const lucideIcons = require("@grimlink/eleventy-plugin-lucide-icons");
const safeLinks = require("@sardine/eleventy-plugin-external-links");
const navigation = require("@11ty/eleventy-navigation");
const rss = require("@11ty/eleventy-plugin-rss");
const img = require("./eleventy.config.images");
/**
* @param {UserConfig} eleventyConfig
* @returns {void}
*/
module.exports = function (eleventyConfig) {
let mdOptions = {
html: true,
breaks: true,
linkify: true,
};
const markdownLib = markdownIt(mdOptions)
.use(markdownItAttrs)
.use(markdownItFootNotes);
eleventyConfig.setLibrary("md", markdownLib);
eleventyConfig.addWatchTarget("src/**/*.{svg,webp,png,jpeg}");
eleventyConfig.addPlugin(img);
// PLUGINS
eleventyConfig.addPlugin(syntaxHighlight, {
lineSeparator: "\n",
preAttributes: {
tabindex: 0,
// Added in 4.1.0 you can use callback functions too
"data-language": function ({ language, content, options }) {
return language;
},
},
});
eleventyConfig.addPlugin(lucideIcons, {
width: 16,
height: 16,
});
eleventyConfig.addPlugin(safeLinks);
eleventyConfig.addPlugin(navigation);
eleventyConfig.addPlugin(rss);
// FILTERS
const mdRender = new markdownIt();
eleventyConfig.addFilter("renderUsingMarkdown", function (rawString) {
return mdRender.render(rawString);
});
eleventyConfig.addFilter("toUTC", function (value) {
const date = moment(new Date(value)).utc().format("MMM DD, YYYY");
return date;
});
// SHORTCODES
eleventyConfig.addShortcode("renderStar", (rating) => {
const star = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-star"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>`;
const halfStar = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-star-half"><path d="M12 17.8 5.8 21 7 14.1 2 9.3l7-1L12 2"/></svg>`;
let stars = "";
while (rating-- > 0) {
if (rating !== 1.5) {
stars += star;
}
}
if (rating % 1 !== 0) {
stars += halfStar;
}
return stars;
});
eleventyConfig.addShortcode("aside", (type, message) => {
return `<aside class="${type}">${message}</aside>`;
});
eleventyConfig.addPairedShortcode("spoiler", (content) => {
return `<span class="spoiler">${content}</span>`;
});
eleventyConfig.addShortcode("furi", (kanji, furi) => {
return `<ruby><rb>${kanji}</rb><rp>(</rp><rt>${furi}</rt><rp>)</rp></ruby>`;
});
eleventyConfig.addPairedShortcode("lang", (content) => {
return `<span lang="ja">${content}</span>`;
});
// COLLECTIONS
eleventyConfig.addCollection("books", function (collection) {
return collection.getFilteredByTag("books").reverse();
});
// PASSTHROUGH
eleventyConfig.addPassthroughCopy("./src/assets/css");
eleventyConfig.addPassthroughCopy("./src/assets/img");
eleventyConfig.addPassthroughCopy("./src/assets/fonts");
eleventyConfig.addPassthroughCopy("./src/assets/js");
eleventyConfig.addPassthroughCopy("./src/assets/etc");
return {
dir: {
input: "src",
output: "public",
includes: "_includes",
},
};
};