forked from HackingHistory/hh-project-11ty-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
130 lines (108 loc) · 4.34 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
// 11ty Plugins
const socialImages = require("@11tyrocks/eleventy-plugin-social-images");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginRss = require("@11ty/eleventy-plugin-rss");
// Helper packages
const slugify = require("slugify");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const markdownItFootnote = require("markdown-it-footnote")
// Local utilities/data
const packageVersion = require("./package.json").version;
const pluginTOC = require('eleventy-plugin-toc');
const { EleventyRenderPlugin } = require("@11ty/eleventy");
const { DateTime } = require("luxon");
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(socialImages);
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginTOC, {
tags: ['h2', 'h3', 'h4'], // which heading tags are selected headings must each have an ID attribute
wrapper: 'nav', // element to put around the root `ol`/`ul`
wrapperClass: 'toc', // class for the element around the root `ol`/`ul`
ul: false, // if to use `ul` instead of `ol`
flat: false, // if subheadings should appear as child of parent or as a sibling
})
eleventyConfig.addWatchTarget("./src/sass/");
eleventyConfig.addPassthroughCopy("./src/css");
eleventyConfig.addPassthroughCopy("./src/fonts");
eleventyConfig.addPassthroughCopy("./src/img");
eleventyConfig.addPassthroughCopy("./src/favicon.png");
eleventyConfig.addPassthroughCopy("./src/js");
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
eleventyConfig.addShortcode("packageVersion", () => `v${packageVersion}`);
// two date filters for the map templates
// I actually need to refactor/rewrite as templates nayway I think.
eleventyConfig.addFilter("findDate", (item) => {
let dateReference= item.data.date || item.data.year || item.data.time || item.geojson?.features?.properties?.time || item.geojson?.features?.properties?.start
return DateTime.fromISO(dateReference).toISODate()})
eleventyConfig.addFilter("dateToUnix", (item) => {
let dateReference= item.data.date || item.data.year || item.data.time || item.geojson?.properties?.time || item.geojson?.properties?.start
return DateTime.fromISO(dateReference).valueOf()})
// dealing with json
const util = require('util')
eleventyConfig.addFilter('stringify', obj => {
return JSON.stringify(obj)
});
// stolen from https://github.com/11ty/eleventy/issues/266#issuecomment-450397156
eleventyConfig.addFilter('serializeMaps', (value) => {
const mapData = value.map((map) => {
return map.data.geojson ? {
date: map.date,
url: map.url,
data: {
title: map.data.title,
excerpt: map.data.excerpt,
geojson: map.data.geojson
},
} : null;
});
return JSON.stringify(
mapData.filter( data => data ),
null, 2);
});
eleventyConfig.addFilter("findDate", (item) => {
let dateReference= item.data.date || item.data.year || item.data.time || item.geojson?.features?.properties?.time || item.geojson?.features?.properties?.start
return DateTime.fromISO(dateReference).toISODate()})
eleventyConfig.addFilter("dateToUnix", (item) => {
let dateReference= item.data.date || item.data.year || item.data.time || item.geojson?.properties?.time || item.geojson?.properties?.start
return DateTime.fromISO(dateReference).valueOf()})
eleventyConfig.addFilter("slug", (str) => {
if (!str) {
return;
}
return slugify(str, {
lower: true,
strict: true,
remove: /["]/g,
});
});
/* Markdown Overrides */
let markdownLibrary = markdownIt({
html: true,
}).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
class: "tdbc-anchor",
space: false,
symbol: "🔗",
}),
level: [1, 2, 3],
slugify: (str) =>
slugify(str, {
lower: true,
strict: true,
remove: /["]/g,
}),
}).use(markdownItFootnote);
eleventyConfig.setLibrary("md", markdownLibrary);
return {
passthroughFileCopy: true,
pathPrefix: "/hh-project-11ty-starter-kit",
dir: {
input: "src",
output: "docs",
layouts: "_layouts",
},
};
};