forked from danurbanowicz/eleventy-netlify-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
122 lines (103 loc) · 3.45 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const { DateTime } = require("luxon");
const CleanCSS = require("clean-css");
const UglifyJS = require("uglify-es");
const htmlmin = require("html-minifier");
const showdown = require('showdown');
const converter = new showdown.Converter();
const pictureFilter = require('./filters/picture');
const imageFilter = require('./filters/image');
const pluginPWA = require("eleventy-plugin-pwa");
const cacheBuster = require('@mightyplow/eleventy-plugin-cache-buster');
//
// CONFIG
// -----------------------
module.exports = function(eleventyConfig) {
eleventyConfig.addLayoutAlias("post", "layouts/post.njk");
// Date formatting (human readable)
eleventyConfig.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(dateObj).toFormat("dd LLL yyyy");
});
eleventyConfig.addFilter("markdownify", string => {
var html = converter.makeHtml(string);
return html;
});
eleventyConfig.addFilter("picture", pictureFilter );
eleventyConfig.addFilter("image", imageFilter );
// Date formatting (machine readable)
eleventyConfig.addFilter("machineDate", dateObj => {
return DateTime.fromJSDate(dateObj).toFormat("yyyy-MM-dd");
});
// Minify CSS
eleventyConfig.addFilter("cssmin", function(code) {
return new CleanCSS({}).minify(code).styles;
});
// Minify JS
eleventyConfig.addFilter("jsmin", function(code) {
let minified = UglifyJS.minify(code);
if (minified.error) {
return code;
}
return minified.code;
});
// Minify HTML output
eleventyConfig.addTransform("htmlmin", function(content, outputPath) {
if (outputPath.indexOf(".html") > -1) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: false,
});
return minified;
}
return content;
});
// only content in the `posts/` directory
eleventyConfig.addCollection("posts", function(collection) {
return collection.getAllSorted().filter(function(item) {
return item.inputPath.match(/^\.\/src\/posts\//) !== null;
});
});
// Don't process folders with static assets e.g. images
eleventyConfig.addPassthroughCopy("src/assets");
eleventyConfig.addPassthroughCopy("src/admin");
eleventyConfig.addPassthroughCopy("src/public");
// Plugins
eleventyConfig.addPlugin(pluginPWA);
const cacheBusterOptions = {
outputDirectory: 'dist'
};
eleventyConfig.addPlugin(cacheBuster(cacheBusterOptions));
/* Markdown Plugins */
let markdownIt = require("markdown-it");
let markdownItAnchor = require("markdown-it-anchor");
let options = {
html: true,
breaks: true,
linkify: true
};
let opts = {
permalink: false
};
eleventyConfig.setLibrary("md", markdownIt(options)
.use(markdownItAnchor, opts)
);
return {
templateFormats: ["md", "njk", "html", "liquid"],
// If your site lives in a different subdirectory, change this.
// Leading or trailing slashes are all normalized away, so don’t worry about it.
// If you don’t have a subdirectory, use "" or "/" (they do the same thing)
// This is only used for URLs (it does not affect your file structure)
pathPrefix: "/",
markdownTemplateEngine: "liquid",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
// Allows copy of non-processed files and folders (assets, etc)
passthroughFileCopy: true,
dir: {
input: "src",
includes: "_includes",
data: "_data",
output: "dist"
}
};
};