-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path.eleventy.js
More file actions
177 lines (156 loc) · 5.57 KB
/
.eleventy.js
File metadata and controls
177 lines (156 loc) · 5.57 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import collections from "./config/collections.js";
import * as sass from "sass";
import path from "node:path";
import { JSDOM } from "jsdom";
import fs from "fs";
import eleventyNavigationPlugin from "@11ty/eleventy-navigation"
import pluginRss from "@11ty/eleventy-plugin-rss";
import attributes from "markdown-it-attrs";
import CETEI from 'CETEIcean';
import attrs from "markdown-it-attrs";
export default function (eleventyConfig) {
// Add attributes plugin to markdown so we can have, e.g., {#id .class}
eleventyConfig.amendLibrary("md", (md) => {
md.use(attributes);
});
eleventyConfig.addPassthroughCopy({"src/assets/favicon.ico": "favicon.ico"});
eleventyConfig.addPassthroughCopy({ "src/assets/js": "js" });
eleventyConfig.addPassthroughCopy({ "src/assets/css/*.css": "css" });
eleventyConfig.addPassthroughCopy({ "src/assets/img": "img" });
eleventyConfig.addPassthroughCopy({ "src/assets/xslt": "xslt" });
eleventyConfig.addPassthroughCopy("src/**/*.ai");
eleventyConfig.addPassthroughCopy("src/**/*.eps");
eleventyConfig.addPassthroughCopy("src/**/*.jpg");
eleventyConfig.addPassthroughCopy("src/**/*.png");
eleventyConfig.addPassthroughCopy("src/**/*.gif");
eleventyConfig.addPassthroughCopy("src/**/*.pdf");
eleventyConfig.addPassthroughCopy("src/**/*.svg");
eleventyConfig.addPassthroughCopy("src/**/*.var");
eleventyConfig.addPassthroughCopy({ "src/_data/*.json": "data" });
eleventyConfig.addPassthroughCopy({ "node_modules/bootstrap-icons/font/fonts/*.*": "fonts" });
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addTemplateFormats("scss");
eleventyConfig.addTemplateFormats("xml");
eleventyConfig.setUseGitIgnore(false);
eleventyConfig.addCollection("docs", function(collectionApi) {
console.log("Building documentation collection");
console.log(collectionApi.getFilteredByTag("documentation").map(item => item.page.url));
return collectionApi.getFilteredByTag("documentation")
.filter(item => item.page.url !== "/about/bylaws/")
.sort((a, b) => {
return a.data.title.localeCompare(b.data.title);
});
}
);
eleventyConfig.addCollection("tc_meetings", function(collectionApi) {
return collectionApi.getFilteredByTag("council_meetings").reverse().
filter(item => !item.data.tags.includes("meeting_list"));
}
);
eleventyConfig.addFilter("isoDateToPath",
function(date) {
if (date instanceof Date) {
date = date.toISOString().replace(/:.*$/, "").replace(/T.*$/, "");
}
return date.replace(/-/g, "/");
}
);
eleventyConfig.addFilter("dateString",
function(date) {
if (!(date instanceof Date)) {
date = new Date(date);
}
return date.toDateString();
}
);
eleventyConfig.addFilter("getYears",
function(pages) {
return Array.from(new Set(pages.map(item => {
let date = item.data.date;
if (date instanceof Date) {
date = date.toISOString().replace(/:.*$/, "").replace(/T.*$/, "");
}
return date.replace(/-.*$/, "");
})));
}
);
eleventyConfig.addFilter("pagesByYear",
function(pages, year) {
return pages.filter(item => {
let date = item.data.date;
if (date instanceof Date) {
date = date.toISOString().replace(/:.*$/, "").replace(/T.*$/, "");
}
return date.startsWith(year);
});
}
);
eleventyConfig.addFilter("limit", function(array, limit) {
return array.slice(0, limit);
});
eleventyConfig.addFilter("scrub", function(content) {
return content.replace(/<a[^>]+>/g, "").replace(/<\/a>/, "");
});
eleventyConfig.addExtension("scss", {
compileOptions: {
permalink: function(contents, inputPath) {
return (data) => {
return inputPath.replace("src/assets", "").replace(".scss", ".css");
}
}
},
compile: async function(inputContent, inputPath) {
let parsed = path.parse(inputPath);
let result = sass.compileString(inputContent, {
loadPaths: [
parsed.dir || ".",
this.config.dir.includes
]
});
return async (data) => {
return result.css;
};
}
});
eleventyConfig.addExtension("xml", {
getData: async function(inputPath) {
const file = fs.readFileSync(inputPath, 'utf8');
const jdom = new JSDOM(file, { contentType: "text/xml" });
if (!jdom.window.document.querySelector("TEI")) {
return;
}
return {
"title": jdom.window.document.querySelector("titleStmt > title").textContent,
"navkey": inputPath.replace(".*/", "").replace(".xml", ""),
"eleventyNavigation": {
parent: inputPath.includes("TCW") ? "Council" : "About",
key: inputPath,
title: jdom.window.document.querySelector("titleStmt > title").textContent
}
}
},
compile: async function(contents, inputPath) {
const jdom = new JSDOM(contents, { contentType: "text/xml" });
if (!jdom.window.document.querySelector("TEI")) {
return;
}
let cetei = new CETEI({ documentObject: jdom.window.document });
let doc = await cetei.domToHTML5(jdom.window.document);
return async (data) => {
return cetei.utilities.serializeHTML(doc, true);
};
}
});
Object.keys(collections).forEach(collectionName => {
eleventyConfig.addCollection(collectionName, collections[collectionName]);
});
return {
dir: {
input: 'src',
output: 'dist',
includes: '_includes',
layouts: '_layouts'
}
}
}