-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.js
83 lines (72 loc) · 2.37 KB
/
eleventy.config.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require('dotenv').config();
const { DateTime } = require('luxon');
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const bundlerPlugin = require("@11ty/eleventy-plugin-bundle");
const gist = require('eleventy-gist');
const markdownIt = require('markdown-it');
const markdownItAttrs = require('markdown-it-attrs');
const { minify } = require('terser');
const CleanCss = require('clean-css');
module.exports = function (eleventyConfig) {
eleventyConfig.setServerOptions({
watch: ['./_site/assets/css/**/*.css']
});
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(bundlerPlugin);
eleventyConfig.addPlugin(gist, {
authToken: process.env.github_access_token,
userAgent: process.env.github_user_agent,
debug: process.env.NODE_ENV === 'development',
useCache: process.env.NODE_ENV === 'development',
addHiddenField: true
});
const markdownLib = markdownIt({ html: true }).use(markdownItAttrs)
eleventyConfig.setLibrary('md', markdownLib)
/**
* Recreating Jekyll's post_url as best I can.
* This was really helpful:
* https://github.com/11ty/eleventy/issues/813#issuecomment-1037874929
*/
eleventyConfig.addShortcode('post_url', function (path) {
// find the posts collection in this.ctx for nunjucks, this.context.environments for liquid
const collections = this.ctx?.collections || this.context?.environments.collections | {};
const posts = collections?.posts || [];
const post = posts.find(p => p.url === `/posts/${path}/`);
if (post) {
return post.url;
}
throw `Eleventy Config --> post_url :: The URL for ${path} was not found`;
});
eleventyConfig.addFilter('asPostDate', date => {
return DateTime.fromJSDate(date).toLocaleString(DateTime.DATE_MED);
});
eleventyConfig.addNunjucksAsyncFilter('jsmin', async function(code, cb){
try {
const minified = await minify(code);
cb(null, minified.code);
} catch(e) {
console.log('Eleventy Config --> Terser error: ', e);
cb(null, code);
}
});
eleventyConfig.addFilter('cssmin', function(code){
return new CleanCss({}).minify(code).styles;
});
eleventyConfig.addPassthroughCopy('./assets/**/*');
return {
dir: {
input: './content',
includes: '../_includes',
layouts: '../_layouts',
data: '../_data'
},
templateFormats: [
"md",
"njk",
"html",
"liquid",
],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk"
}
}