-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eleventy.js
executable file
Β·94 lines (77 loc) Β· 2.73 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
"use strict";
const filters = require('./utils/filters.js');
const shortcodes = require('./utils/shortcodes.js');
const readingTime = require('eleventy-plugin-reading-time');
const lazyImagesPlugin = require('eleventy-plugin-lazyimages');
const cacheBuster = require('@mightyplow/eleventy-plugin-cache-buster');
const pjson = require('./package.json');
// The @11ty/eleventy configuration.
// For a full list of options, see: https://www.11ty.io/docs/config/
module.exports = (eleventyConfig) => {
const dirs = {
input: 'src',
data: '_data',
includes: '_includes',
output: 'dist',
}
// Filters
Object.keys(filters).forEach(filterName => {
eleventyConfig.addFilter(filterName, filters[filterName])
})
// Shortcodes
Object.keys(shortcodes).forEach(shortCodeName => {
eleventyConfig.addShortcode(shortCodeName, shortcodes[shortCodeName])
})
eleventyConfig.addCollection('food', collection => {
// return collection.getFilteredByGlob('**/food/*.md').reverse();
return collection.getFilteredByGlob('**/food/*.md').sort(function(a, b) {
//return a.date - b.date; // sort by date - ascending
// return b.date - a.date; // sort by date - descending
return a.inputPath.localeCompare(b.inputPath); // sort by path - ascending
// return b.inputPath.localeCompare(a.inputPath); // sort by path - descending
});
});
eleventyConfig.addCollection('posts', collection => {
return collection.getFilteredByGlob('**/blog/*.md').reverse();
});
eleventyConfig
.addPassthroughCopy('_redirects')
.addPassthroughCopy('src/img')
.addPassthroughCopy('src/fonts');
eleventyConfig.addPlugin(readingTime);
if (process.env.ELEVENTY_ENV !== 'development') {
eleventyConfig.addPlugin(lazyImagesPlugin, {
appendInitScript: false,
className: ['lazyload', 'blur-up'],
transformImgPath: (imgPath) => {
if (imgPath.startsWith('/') && !imgPath.startsWith('//')) {
return `./src${imgPath}`;
}
return imgPath;
},
});
}
const cacheBusterOptions = {
outputDirectory: dirs.output,
createResourceHash(outputDirectoy, url, target) {
return pjson.version;
}
};
eleventyConfig.addPlugin(cacheBuster(cacheBusterOptions));
return {
// Set the path from the root of the deploy domain
// i.e, example.com + "/"
pathPrefix: "/",
// Set the src and output directories
dir: dirs,
// Set the default template engine from `liquid` to `njk`
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
dataTemplateEngine: "njk",
// Set up eleventy to pass-through files to be compiled by Parcel
passthroughFileCopy: true
};
};
function resolveNameFromPath(path) {
return path.basename(path);
}