-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (32 loc) · 1.04 KB
/
index.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
const {atlas, slugToStr, strToSlug} = require('./src/tag-atlas');
const defaultOptions = {
ignore: [],
similar: {},
slugify: require('./src/str-to-slug'),
};
const validateOptions = (options) => {
let validated = {};
for (let [key, value] of Object.entries(options)) {
key = key.toLowerCase();
switch (key) {
case 'ignore':
if (Array.isArray(value)) validated.ignore = value;
break;
case 'similar':
validated.similar = value;
break;
case 'slugify':
if (typeof value === 'function') validated.slugify = value;
break;
}
}
return validated;
};
module.exports = function (eleventyConfig, customOptions = {}) {
const globalOptions = Object.assign({}, defaultOptions, validateOptions(customOptions));
const tagAtlas = atlas(globalOptions);
eleventyConfig.addFilter('strToSlug', strToSlug(tagAtlas));
eleventyConfig.addFilter('slugToStr', slugToStr(tagAtlas));
eleventyConfig.addGlobalData('tagAtlas', tagAtlas);
};
module.exports.validateOptions = validateOptions;