-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
272 lines (223 loc) · 7.75 KB
/
Copy path.eleventy.js
File metadata and controls
272 lines (223 loc) · 7.75 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const myMarkdown = require("./.myMarkdown");
module.exports = function(eleventyConfig) {
console.log("eleventy setup...");
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.chokidarConfig = {
usePolling: true
};
// eleventy global settings
eleventyConfig.setQuietMode(true);
// Copy any images and css to `_site`, via Glob pattern (in 0.9.0+)
// Keeps the same directory structure.
eleventyConfig.ignores.add("_site/**");
eleventyConfig.ignores.add(".vscode/**");
eleventyConfig.ignores.add("**/_*");
eleventyConfig.ignores.add("**/_*.*");
const contentFolders = ["boards", "boards", "concepts", "dev", "elements", "examples", "portal", "recipes", "sensors", "steps", "stories"];
const assetFolders = ["i", "v09", "v09m", "home"];
contentFolders.forEach(f => {
eleventyConfig.addPassthroughCopy(f + "/**/*.svg");
eleventyConfig.addPassthroughCopy(f + "/**/*.jpg");
eleventyConfig.addPassthroughCopy(f + "/**/*.png");
eleventyConfig.addWatchTarget(f);
})
eleventyConfig.setWatchThrottleWaitTime(2000); // in milliseconds
assetFolders.forEach(f => {
eleventyConfig.ignores.add(f);
eleventyConfig.addPassthroughCopy(f);
})
eleventyConfig.addPassthroughCopy("./robots.txt");
eleventyConfig.addPassthroughCopy("./favicon*.*");
eleventyConfig.addPassthroughCopy("./pages.js");
eleventyConfig.addPassthroughCopy("./story.js");
eleventyConfig.addPassthroughCopy("./microsvg.js");
eleventyConfig.addPassthroughCopy("./elementsvg.js");
eleventyConfig.addPassthroughCopy("./element*.json");
eleventyConfig.addPassthroughCopy("./*.svg");
eleventyConfig.addPassthroughCopy("./homeding.png");
// https://www.11ty.dev/docs/data-global-custom/
eleventyConfig.addGlobalData("layout", "page.njk");
eleventyConfig.setFrontMatterParsingOptions({
excerpt: true,
excerpt_separator: "--- excerpt ---"
});
// https://www.11ty.dev/docs/copy/#passthrough-by-file-extension
eleventyConfig.setTemplateFormats([
"md",
"njk",
"css" // css is not yet a recognized template extension in Eleventy
]);
// Modify all URLs pointing to .md files in all .htm output in your project
eleventyConfig.htmlTransformer.addUrlTransform(
"htm",
/**
* transform internal links to markdown fils to the final url using the htm format.
* @this {object}
* @param {string} url given url in the document
*/
(url) => {
let lUrl = url.toLowerCase();
if ((! lUrl.startsWith('http')) && (lUrl.endsWith('.md'))) {
return(url.substring(0, url.length-2) + 'htm');
}
return (url);
},
{
priority: -1, // run last (especially after PathToUrl transform)
}
);
eleventyConfig.addTransform("insp", function(content) {
// console.log( this.inputPath, this.outputPath );
// note that this.outputPath is `false` for serverless templates
// simply remove whitespace at the beginning of all textlines starting with a tag
// content = content.replace(/$\s+</mg, "<");
return (content);
});
eleventyConfig.addFilter("stringify", function(value) {
console.log(value);
return "logged";
});
eleventyConfig.addFilter("keys", function(value) {
let result = [];
for (const k in value) {
result.push(k);
}
return JSON.stringify(result);
});
eleventyConfig.addFilter("item", function(obj, name) {
return obj[name];
});
eleventyConfig.addFilter("print", function(value) {
const seen = new Set();
function detect(k, v) {
// console.log(">>", k, v);
if (k === 'data') {
return ("...0");
} else if (k === 'all') {
return ("...1");
} else if (typeof v === 'function') {
return ("f()");
} else if (typeof v === 'object') {
if (seen.has(v)) {
return ("--");
} else {
seen.add(v);
}
}
return (v);
};
const res = JSON.stringify(value, detect, 2);
// console.log('>>', res);
return (res);
});
eleventyConfig.addFilter('unique', (list) => {
const map = new Map(list.map((x) => [x, x]));
return [...map.values()]
})
// ===== Shortcodes =====
function findItem(col, name) {
let item = undefined;
if (!col) {
console.error("findItem: no collection given.")
} else if (!Array.isArray(col)) {
console.error("findItem: bad collection given.")
} else {
item = col.find(e => e.url.includes('/' + name + '.'));
}
if (!item) {
console.error(`findItem: entry ${name} not found.`)
}
return (item);
}
// include excerpt text by using: {% excerptOf collections, "map" %}
eleventyConfig.addShortcode("excerptOf", function(col, name) {
if (!col) {
console.error("excerptOf: no collection given.")
}
if (Array.isArray(col)) {
const page = col.find(e => e.url.includes('/' + name + '.'));
if (page) {
return (page.data.excerpt);
}
}
console.error(`excerptOf: entry ${name} not found.`)
return ('');
}
);
// include page title text by using: {% title collections, "map" %}
eleventyConfig.addShortcode("titleOf", function(col, name) {
if (!col) {
console.error("titleOf: no collection given.")
}
if (Array.isArray(col)) {
const page = col.find(e => e.url.includes('/' + name + '.'));
if (page) {
return (page.data.title);
}
}
console.error(`titleOf: entry ${name} not found.`)
return ('');
}
);
// include page title text by using: {% title collections, "map" %}
eleventyConfig.addShortcode("urlOf", function(col, name) {
if (!col) {
console.error("titleOf: no collection given.")
}
if (Array.isArray(col)) {
const page = col.find(e => e.url.includes('/' + name + '.'));
if (page) {
return (page.url);
}
}
console.error(`urlOf: entry ${name} not found.`)
return ('');
}
);
eleventyConfig.addNunjucksGlobal("findItem", function(col, name) {
return findItem(col, name);
});
// include excerpt text by using: {% dataOf collections.Board, "map" %}
eleventyConfig.addShortcode("dataOf", function(col, name, item) {
if (!col) {
console.error("dataOf: no collection given.")
}
if (Array.isArray(col)) {
let page = col.find(e => e.url.includes('/' + name + '.htm'));
if (!page) {
page = col.find(e => e.url.includes(name + '.htm'));
}
if (page) {
return (page.data[item]);
}
}
console.error("dataOf: entry `" + name + "` not found.")
return ('');
}
);
// include excerpt text by using: {% excerptOf collections, "map" %}
eleventyConfig.addPairedShortcode("card", function(content, img) {
let out = `<div class="card autolink">`;
if (img) out += `<img src="${img}">`;
out += `<div class="body">\n${content}\n</div></div>\n`;
return (out);
});
// include excerpt text by using: {% excerptOf collections, "map" %}
eleventyConfig.addPairedShortcode("imgcard", function(content, img, link) {
link = link.replace(/\.md$/, ".htm");
let out = `<div class="imgcard">`;
if (link) out += `<a href="${link}">`;
if (img) out += `<img src="${img}">`;
if (link) out += `</a>\n`;
out += `\n${content}\n</div>\n`;
return (out);
});
// ===== Markdown configuration =====
eleventyConfig.addPlugin(myMarkdown);
// console.log(eleventyConfig.ignores);
return {
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk"
}
};