generated from conedevelopment/sprucecss-eleventy-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
64 lines (51 loc) · 1.58 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
require('dotenv').config();
const { parse, stringify } = require('himalaya');
const dateFilter = require('./src/filters/date.js');
const Image = require('@11ty/eleventy-img');
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const w3DateFilter = require('./src/filters/w3-date.js');
function addPrefixToIdsAndUrls(str, prefix) {
const regexId = /id=(["'])(.*?)\1/g;
const regexUrl = /url\((.*?)\)/g;
str = str.replace(regexId, `id=$1${prefix}$2$1`);
str = str.replace(regexUrl, (match, url) => {
if (url.charAt(0) === '#') {
return `url(#${prefix}${url.substring(1)})`;
}
return match;
});
return str;
}
module.exports = config => {
config.addFilter('date', dateFilter);
config.addFilter('w3Date', w3DateFilter);
config.addPlugin(syntaxHighlight);
config.addPassthroughCopy('./src/img/**');
config.addPassthroughCopy('./src/css/**');
config.addPassthroughCopy('./src/js/**');
config.addPassthroughCopy('./src/font/**');
config.addNunjucksAsyncShortcode('svgIcon', async (src, cls = null, prefix = null) => {
const metadata = await Image(src, {
formats: ['svg'],
dryRun: true,
});
const svg = parse(metadata.svg[0].buffer.toString());
svg[0].attributes.push({
key: 'class',
value: cls ? cls : 'icon'
});
if (prefix) {
return addPrefixToIdsAndUrls(stringify(svg), prefix);
}
return stringify(svg);
});
return {
markdownTemplateEngine: 'njk',
dataTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
dir: {
input: 'src',
output: 'dist'
}
};
};