-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
117 lines (103 loc) · 3.62 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
const { parse } = require("csv-parse/sync")
const pluginRss = require("@11ty/eleventy-plugin-rss")
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight")
const markdownIt = require("markdown-it")
const taskLists = require("markdown-it-task-lists")
const anchor = require("markdown-it-anchor")
let footnotes = require("markdown-it-footnote")
const pagingate = require("./paginate")
let markdownOptions = {
html: true,
}
let markdownLib = markdownIt(markdownOptions).use(taskLists).use(footnotes).use(anchor, { tabIndex: false })
markdownLib.renderer.rules.footnote_block_open = () => '<section class="footnotes">\n' + '<ol class="footnotes-list">\n'
markdownLib.renderer.rules.footnote_caption = (tokens, idx) => {
var n = Number(tokens[idx].meta.id + 1).toString()
if (tokens[idx].meta.subId > 0) {
n += ":" + tokens[idx].meta.subId
}
return n
}
function getIndex(arr, prop, value) {
for (let i = 0; i < arr.length; i++) {
if (arr[i][prop] === value) {
return i
}
}
return false
}
function groupPostsByYear(posts) {
let postsByYear = []
let currentYear = ""
posts.forEach((p) => {
let y = new Date(p.data.date).getFullYear()
if (y !== currentYear) {
postsByYear.push({
year: y,
shortYear: y.toString().substr(2),
posts: [p],
})
currentYear = y
} else {
let index = getIndex(postsByYear, "year", currentYear)
postsByYear[index].posts.push(p)
}
})
return postsByYear.reverse()
}
const md = new markdownIt()
module.exports = function (eleventyConfig) {
eleventyConfig.addFilter("renderMarkdown", function (value) {
return md.render(value)
})
eleventyConfig.addPairedShortcode("details", function (content, summary) {
return `<details><summary>${summary}</summary>${md.render(content)}</details>`
})
eleventyConfig.addPairedShortcode("leadin", function (content) {
return `<span class="leadin">${content}</span>`
})
eleventyConfig.addCollection("workByYear", function (collectionApi) {
const posts = collectionApi.getFilteredByGlob(["./work/*.md"])
return groupPostsByYear(posts)
})
eleventyConfig.addCollection("postsByYear", function (collectionApi) {
const posts = collectionApi.getFilteredByGlob(["./posts/*.md"])
return groupPostsByYear(posts)
})
eleventyConfig.addCollection("pagedNotes", function (collectionApi) {
const posts = collectionApi.getFilteredByGlob(["./notes/*.md", "./notes/*.markdown"])
posts.reverse()
return pagingate(posts, 12)
})
eleventyConfig.addGlobalData("builtOn", new Date().toLocaleString())
if (process.env.NODE_ENV === "prod") {
console.log("Building site for production.")
eleventyConfig.addGlobalData("env", "prod")
} else {
eleventyConfig.addGlobalData("env", "dev")
console.log("Building in dev mode.")
}
eleventyConfig.addPassthroughCopy("assets")
eleventyConfig.addPassthroughCopy("./*.png")
eleventyConfig.addPassthroughCopy("./*.xml")
eleventyConfig.addPassthroughCopy("./*.txt")
eleventyConfig.addPassthroughCopy("_redirects")
eleventyConfig.addPassthroughCopy("favicon.ico")
eleventyConfig.addPassthroughCopy("site.webmanifest")
eleventyConfig.addPassthroughCopy("*.vcf")
eleventyConfig.addWatchTarget("./_site/main.css")
eleventyConfig.setLibrary("md", markdownLib)
eleventyConfig.addDataExtension("csv", (contents) => {
const records = parse(contents, {
columns: true,
skip_empty_lines: true,
})
return records
})
eleventyConfig.addPlugin(syntaxHighlight, {
alwaysWrapLineHighlights: false,
lineSeparator: "\n",
})
eleventyConfig.addPlugin(pluginRss)
return {}
}