-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.eleventy.js
117 lines (91 loc) · 3.44 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
const rssPlugin = require('@11ty/eleventy-plugin-rss');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const fs = require("fs");
// Import filters
const dateFilter = require('./src/filters/date-filter.js');
const markdownFilter = require('./src/filters/markdown-filter.js');
const w3DateFilter = require('./src/filters/w3-date-filter.js');
// Import transforms
const htmlMinTransform = require('./src/transforms/html-min-transform.js');
const parseTransform = require('./src/transforms/parse-transform.js');
// Import data files
const site = require('./src/_data/site.json');
module.exports = function(config) {
// Filters
config.addFilter('dateFilter', dateFilter);
config.addFilter('markdownFilter', markdownFilter);
config.addFilter('w3DateFilter', w3DateFilter);
// set markdown footnote processor
let markdownIt = require("markdown-it");
let markdownItFootnote = require("markdown-it-footnote");
let options = {
html: true, // Enable HTML tags in source
breaks: true, // Convert '\n' in paragraphs into <br>
linkify: true // Autoconvert URL-like text to links
};
// configure the library with options
let markdownLib = markdownIt(options).use(markdownItFootnote);
// set the library to process markdown files
config.setLibrary("md", markdownLib);
// Layout aliases
config.addLayoutAlias('home', 'layouts/home.njk');
// Transforms
config.addTransform('htmlmin', htmlMinTransform);
config.addTransform('parse', parseTransform);
// Permalink possible fix from https://github.com/11ty/eleventy/issues/923
// "permalink": "{{ page | post_permalink }}"
config.addFilter("post_permalink", page => {
const yyyy = page.date.getFullYear();
const mm = String(page.date.getMonth() + 1).padStart(2, "0");
const slug = page.fileSlug.replace(/^\d{4}-\d{2}-\d{2}\./, "");
return `${yyyy}/${mm}/${slug}/`;
});
config.addFilter('dateFilter', dateFilter);
config.addFilter('markdownFilter', markdownFilter);
config.addFilter('w3DateFilter', w3DateFilter);
// Passthrough copy
config.addPassthroughCopy('src/fonts');
config.addPassthroughCopy('src/images');
config.addPassthroughCopy('src/js');
config.addPassthroughCopy('src/admin/config.yml');
config.addPassthroughCopy('src/admin/previews.js');
config.addPassthroughCopy('node_modules/nunjucks/browser/nunjucks-slim.js');
const now = new Date();
// Custom collections
const livePosts = post => post.date <= now && !post.data.draft;
config.addCollection('posts', collection => {
return [
...collection.getFilteredByGlob('./src/posts/*.md').filter(livePosts)
].reverse();
});
config.addCollection('postFeed', collection => {
return [...collection.getFilteredByGlob('./src/posts/*.md').filter(livePosts)]
.reverse()
.slice(0, site.maxPostsPerPage);
});
const embedYouTube = require("eleventy-plugin-youtube-embed");
// Plugins
config.addPlugin(rssPlugin);
config.addPlugin(syntaxHighlight);
config.addPlugin(embedYouTube);
// 404
config.setBrowserSyncConfig({
callbacks: {
ready: function(err, browserSync) {
const content_404 = fs.readFileSync('dist/404.html');
browserSync.addMiddleware("*", (req, res) => {
// Provides the 404 content without redirect.
res.write(content_404);
res.end();
});
}
}
});
return {
dir: {
input: 'src',
output: 'dist'
},
passthroughFileCopy: true
};
};