-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
67 lines (59 loc) · 2.7 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
const fs = require("fs");
const path = require("path");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("./src/css");
eleventyConfig.addWatchTarget("./src/css");
eleventyConfig.addPassthroughCopy("./src/js");
eleventyConfig.addWatchTarget("./src/js");
eleventyConfig.addPassthroughCopy("./src/img");
eleventyConfig.addWatchTarget("./src/img");
eleventyConfig.addPassthroughCopy("./src/materials");
eleventyConfig.addWatchTarget("./src/materials");
const markdownLib = markdownIt({html: true}).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.linkInsideHeader({
symbol: '<span class="heading-anchor" aria-hidden="true">¶</span>',
placement: 'after'
})
});
eleventyConfig.setLibrary("md", markdownLib);
eleventyConfig.addFilter("sortDataByTime", (obj) => {
const sorted = {};
Object.keys(obj).sort((a, b) => {
let atime = obj[a].time.split("-")[0].split(":").map(Number)
let btime = obj[b].time.split("-")[0].split(":").map(Number)
return new Date(2025, 3, 14, atime[0], atime[1], 0) > new Date(2025, 3, 14, btime[0], btime[1], 0) ? 1 : -1;
}).forEach((name) => (sorted[name] = obj[name]));
return sorted;
});
eleventyConfig.addFilter("countSession", (obj) => {
if ( obj.panelists || obj.talks.length == 0 ) { return ""; }
var count = {"lt": 0, "normal": 0, "invite": 0};
obj.talks.forEach((talk) => { count[talk.type] += 1; });
return "["
+ ((count["invite"] > 0) ? `招待講演・` : "")
+ `一般発表${count["normal"]}件` + ((count["lt"] > 0) ? `・LT${count["lt"]}件` : "")
+ "]";
});
eleventyConfig.addNunjucksShortcode("pdf", function (talk, index=false) {
const dataFile = path.join("src/materials", `${talk.id}.pdf`);
if (fs.existsSync(dataFile)) {
if (index) { return `<a href="materials/${talk.id}.pdf" target="_blank" rel="noreferrer"><div class="btn_material">資料</div></a>`; } else {
return `<a href="../materials/${talk.id}.pdf" target="_blank" rel="noreferrer"><div class="btn_material">資料</div></a>`;
}
} else {
if (talk.type == "invite") { return `<p>(準備中)</p>`; } else {
return `<div class="btn_material disabled">資料</div>`;
}
}
});
return {
dir: {
input: "src",
output: "docs"
},
pathPrefix: "/JLR2025/",
markdownTemplateEngine: "njk"
}
}