-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
124 lines (109 loc) · 3.76 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
123
124
require('dotenv').config()
const pluginRss = require('@11ty/eleventy-plugin-rss')
const pluginSyntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
const htmlmin = require('html-minifier')
const markdownIt = require('markdown-it')
const markdownItAnchor = require('markdown-it-anchor')
const filters = require('./_eleventy/filters.js')
const shortcodes = require('./_eleventy/shortcodes.js')
const isProduction = process.env.NODE_ENV === 'production'
const anchorSlugify = (s) =>
encodeURIComponent(
'h-' +
String(s)
.trim()
.toLowerCase()
.replace(/[.,\/#!$%\^&\*;:{}=_`~()]/g, '')
.replace(/\s+/g, '-')
)
module.exports = function (config) {
// Filters
Object.keys(filters).forEach((filterName) => {
config.addFilter(filterName, filters[filterName])
})
// Shortcodes
Object.keys(shortcodes).forEach((shortCodeName) => {
config.addShortcode(shortCodeName, shortcodes[shortCodeName])
})
// Plugins
config.addPlugin(pluginRss)
config.addPlugin(pluginSyntaxHighlight)
// Layouts
config.addLayoutAlias('base', 'base.njk')
config.addLayoutAlias('page', 'page.njk')
config.addLayoutAlias('post', 'post.njk')
config.addLayoutAlias('note', 'note.njk')
// Pass-through files
config.addPassthroughCopy('src/site.webmanifest')
config.addPassthroughCopy('src/keybase.txt')
config.addPassthroughCopy('src/robots.txt')
config.addPassthroughCopy('src/favicon.ico')
config.addPassthroughCopy('src/assets/images')
config.addPassthroughCopy('src/assets/fonts')
// Markdown Parsing
config.setLibrary(
'md',
markdownIt({
html: true,
breaks: true,
typographer: true
}).use(markdownItAnchor, {
permalink: true,
permalinkSymbol: '#',
permalinkClass: 'heading-anchor',
permalinkBefore: true,
level: 2,
slugify: anchorSlugify
})
)
// Collections: Navigation
config.addCollection('nav', function (collection) {
return collection.getFilteredByTag('nav').sort(function (a, b) {
return a.data.navorder - b.data.navorder
})
})
// Collections: Posts
config.addCollection('posts', function (collection) {
const pathsRegex = /\/posts\/|\/drafts\//
return collection
.getAllSorted()
.filter((item) => item.inputPath.match(pathsRegex) !== null)
.filter((item) => item.data.permalink !== false)
.filter((item) => !(item.data.draft && isProduction))
})
// Collections: Notes
config.addCollection('notes', function (collection) {
return collection
.getAllSorted()
.filter((item) => item.inputPath.match(/\/notes\//) !== null)
.reverse()
})
// Minify HTML Output
config.addTransform('htmlmin', function (content, outputPath) {
if (outputPath && outputPath.endsWith('.html') && isProduction) {
return htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
})
}
return content
})
// opt out of using gitignore for eleventy,
// because the drafts folder is ignored, but should still be processed.
config.setUseGitIgnore(false)
// Base Config
return {
dir: {
input: 'src',
output: 'dist',
includes: 'includes',
layouts: 'layouts',
data: 'data'
},
templateFormats: ['njk', 'md'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
passthroughFileCopy: true
}
}