forked from xdesro/personalsit.es
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
67 lines (58 loc) · 1.8 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
const filenamifyUrl = require('filenamify-url');
const rssPlugin = require('@11ty/eleventy-plugin-rss');
// const lazyImagesPlugin = require('eleventy-plugin-lazyimages');
const shuffle = require('./filters/shuffle.js');
const htmlmin = require('html-minifier');
require('dotenv').config();
module.exports = (eleventyConfig) => {
// Pass through
eleventyConfig.addPassthroughCopy('assets');
// Collections
eleventyConfig.addCollection('sites', (collection) => {
return collection.getFilteredByGlob('sites/*.md');
});
eleventyConfig.addCollection('sitesWithFeeds', (collection) => {
return collection
.getFilteredByGlob('sites/*.md')
.filter((item) => item.data.rss);
});
eleventyConfig.addCollection('sitesAlphabetized', (collection) => {
return collection.getFilteredByGlob('sites/*.md');
});
// Plugins
eleventyConfig.addPlugin(rssPlugin);
// Filters
eleventyConfig.addFilter('shuffle', shuffle);
eleventyConfig.addFilter('cleanUrl', (str) => {
const urlCruft = /http[s]?:\/\/|\/$/gi;
return str.replace(urlCruft, '');
});
// Minify
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
if (outputPath.indexOf('.html') > -1) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
minifyCSS: true,
});
return minified;
}
return content;
});
// Shortcodes
eleventyConfig.addShortcode(
'cloudinaryUrl',
(path, transforms) =>
`https://res.cloudinary.com/${
process.env.CLOUDINARY_CLOUD_NAME
}/image/upload/${transforms}/${filenamifyUrl(path, {
replacement: '',
})}.png`
);
// Return config settings
return {
markdownTemplateEngine: 'njk',
passthroughFileCopy: true,
};
};