-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheleventy.config.js
More file actions
77 lines (67 loc) · 2.31 KB
/
Copy patheleventy.config.js
File metadata and controls
77 lines (67 loc) · 2.31 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
import path from 'path';
import { fileURLToPath } from 'url';
import { EleventyHtmlBasePlugin } from '@11ty/eleventy';
import eleventyNavigationPlugin from '@11ty/eleventy-navigation';
import eleventyAutoCacheBuster from 'eleventy-auto-cache-buster';
import loadAndAnnotateFile from './src/lib/loadAndAnnotateFile.js';
import NunjucksLib from 'nunjucks';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const inputDir = path.relative(__dirname, 'src/content');
const outputDir = path.relative(__dirname, 'build');
/**
*
* @param eleventyConfig
*/
export default async function (eleventyConfig) {
// Tell 11ty to reload if the JS is put there by esbuild changes.
eleventyConfig.setServerOptions({
watch: ['build/js/*.js'],
});
// Plugins.
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(eleventyAutoCacheBuster, {
hashAlgorithm: 'md5',
});
// Files that are passed through.
eleventyConfig.addPassthroughCopy('./src/content/fonts/');
eleventyConfig.addPassthroughCopy('./src/content/css/');
eleventyConfig.addPassthroughCopy('./src/content/img/');
// Filters.
eleventyConfig.addFilter('slug', (str) =>
str.toLowerCase().replace(/[\s/]+/g, '-'),
);
eleventyConfig.addNunjucksFilter('ignoreFilter', (num) => {
return num === -1
? new NunjucksLib.runtime.SafeString(
'<span class="ignored" title="No CSS properties of interest were located within this file, so it isn\'t counted">No Props Found</span>',
)
: `${+num.toFixed(2)}%`;
});
eleventyConfig.addFilter('rangeClass', function (number) {
number = parseInt(number.toString().replace('%', ''), 10);
if (number >= 75 && number <= 100) {
return 'high';
} else if (number >= 50 && number < 75) {
return 'medium';
} else if (number >= 0 && number < 50) {
return 'low';
} else {
return '';
}
});
// Shortcodes.
eleventyConfig.addAsyncShortcode('loadAndAnnotateFile', loadAndAnnotateFile);
return {
markdownTemplateEngine: 'njk',
dir: {
input: inputDir,
output: outputDir,
// The following are relative to the input dir.
data: '../data/',
includes: '../includes/',
layouts: '../layouts/',
},
};
}