-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy path.eleventy.js
69 lines (63 loc) · 1.89 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
65
66
67
68
69
const {EleventyServerlessBundlerPlugin} = require('@11ty/eleventy');
const serialize = require('serialize-javascript');
const {titleCase} = require('title-case');
const {isWebUri} = require('valid-url');
const markdownIt = require('markdown-it');
const markdownItFootnote = require('markdown-it-footnote');
/**
* @typedef {import('@11ty/eleventy/src/UserConfig')} EleventyConfig
* @typedef {ReturnType<import('@11ty/eleventy/src/defaultConfig')>} EleventyReturnValue
*
* @type {(eleventyConfig: EleventyConfig)) => EleventyReturnValue}
*/
module.exports = function (eleventyConfig) {
let markdownItOptions = {
html: true,
breaks: true,
linkify: true,
};
let markdownLib = markdownIt(markdownItOptions).use(markdownItFootnote);
eleventyConfig.setLibrary('md', markdownLib);
eleventyConfig.addPlugin(EleventyServerlessBundlerPlugin, {
name: 'serverless',
functionsDir: './netlify/functions',
inputDir: './src',
copy: ['src/themes/'],
});
eleventyConfig.addPassthroughCopy('src/assets');
eleventyConfig.addPassthroughCopy('src/scripts');
eleventyConfig.addPassthroughCopy('src/themes');
eleventyConfig.addFilter('debug', (output) =>
JSON.stringify(output, null, 2)
);
eleventyConfig.addFilter('formatThemeName', (input) =>
titleCase(input.replace(/\-/g, ' '))
);
eleventyConfig.addFilter('serialize', (input) =>
serialize(input, {isJSON: true})
);
eleventyConfig.addFilter('toStylesheet', toStylesheet);
return {
dir: {
input: 'src',
},
};
};
/**
* Takes chosen theme and determines stylesheet href
* @param {string} theme chosen theme
* @param {{
* list: string[],
* normalized: Object<string, true>
* }}
* @returns {string} valid href for chosen theme
*/
function toStylesheet(theme = 'default', themes) {
if (isWebUri(theme)) {
return theme;
} else if (themes.normalized[theme]) {
return `/themes/${theme}.css`;
} else {
return `/themes/default.css`;
}
}