This repository has been archived by the owner on Jun 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path.eleventy.js
208 lines (185 loc) · 6.03 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// const fs = require('fs')
const pluginRss = require('@11ty/eleventy-plugin-rss')
const pluginNavigation = require('@11ty/eleventy-navigation')
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
const markdownIt = require('markdown-it')
const markdownItEmoji = require('markdown-it-emoji')
const pluginSvgSprite = require("eleventy-plugin-svg-sprite");
// const collections = require('./utils/collections.js')
const filters = require('./utils/filters.js')
const shortcodes = require('./utils/shortcodes.js')
const pairedshortcodes = require('./utils/paired-shortcodes.js')
// const transforms = require('./utils/transforms.js')
module.exports = function (eleventyConfig) {
/**
* Plugins
* @link https://www.11ty.dev/docs/plugins/
*/
eleventyConfig.addPlugin(pluginRss)
eleventyConfig.addPlugin(pluginNavigation)
eleventyConfig.addPlugin(syntaxHighlight)
eleventyConfig.addPlugin(pluginSvgSprite, {
path: "./src/assets/svg",
globalClasses: "fill-current"
})
/**
* Filters
* @link https://www.11ty.io/docs/filters/
*/
Object.keys(filters).forEach((filterName) => {
eleventyConfig.addFilter(filterName, filters[filterName])
})
/**
* Transforms
* @link https://www.11ty.io/docs/config/#transforms
Object.keys(transforms).forEach((transformName) => {
eleventyConfig.addTransform(transformName, transforms[transformName])
})
*/
/**
* Shortcodes
* @link https://www.11ty.io/docs/shortcodes/
*/
Object.keys(shortcodes).forEach((shortcodeName) => {
eleventyConfig.addShortcode(shortcodeName, shortcodes[shortcodeName])
})
/**
* Paired Shortcodes
* @link https://www.11ty.dev/docs/languages/nunjucks/#paired-shortcode
*/
Object.keys(pairedshortcodes).forEach((shortcodeName) => {
eleventyConfig.addPairedShortcode(
shortcodeName,
pairedshortcodes[shortcodeName]
)
})
/**
* Collections
* ============================
*
* POST Collection set so we can check status of "draft:" frontmatter.
* If set "true" then post will NOT be processed in PRODUCTION env.
* If "false" or NULL it will be published in PRODUCTION.
* Every Post will ALWAYS be published in DEVELOPMENT so you can preview locally.
*/
eleventyConfig.addCollection('post', (collection) => {
if (process.env.ELEVENTY_ENV !== 'production')
return [...collection.getFilteredByGlob('./src/posts/*.md')]
else
return [...collection.getFilteredByGlob('./src/posts/*.md')].filter((post) => !post.data.draft)
})
// TAGLIST used from the official eleventy-base-blog https://github.com/11ty/eleventy-base-blog/blob/master/.eleventy.js
eleventyConfig.addCollection('tagList', function (collection) {
let tagSet = new Set()
collection.getAll().forEach(function (item) {
if ('tags' in item.data) {
let tags = item.data.tags
tags = tags.filter(function (item) {
switch (item) {
// this list should match the `filter` list in tags.njk
case 'authors':
case 'pages':
case 'post':
return false
}
return true
})
for (const tag of tags) {
tagSet.add(tag)
}
}
})
// returning an array in addCollection works in Eleventy 0.5.3
return [...tagSet]
})
/**
* Custom Watch Targets
* for when the Tailwind config or .css files change...
* by default not watched by 11ty
* @link https://www.11ty.dev/docs/config/#add-your-own-watch-targets
*/
eleventyConfig.addWatchTarget('./src/assets')
eleventyConfig.addWatchTarget('./utils/*.js')
eleventyConfig.addWatchTarget('./tailwind.config.js')
/**
* Passthrough File Copy
* @link https://www.11ty.dev/docs/copy/
*/
eleventyConfig.addPassthroughCopy('src/*.png')
eleventyConfig.addPassthroughCopy('src/*.jpg')
eleventyConfig.addPassthroughCopy('src/*.ico')
eleventyConfig.addPassthroughCopy('src/robots.txt')
eleventyConfig.addPassthroughCopy('src/assets/images/')
eleventyConfig.addPassthroughCopy('src/assets/svg/')
eleventyConfig.addPassthroughCopy('src/assets/video/')
/**
* Set custom markdown library instance...
* and support for Emojis in markdown...
* ...because why not control our .MD files and have Emojis built in?
* @link https://www.11ty.dev/docs/languages/markdown/#optional-set-your-own-library-instance
* @link https://www.npmjs.com/package/markdown-it-emoji
*
*/
let options = {
html: true,
breaks: true,
linkify: true,
typographer: true,
}
let markdownLib = markdownIt(options).use(markdownItEmoji)
eleventyConfig.setLibrary('md', markdownLib)
/**
* Add layout aliases
* @link https://www.11ty.dev/docs/layouts/#layout-aliasing
*/
eleventyConfig.addLayoutAlias('base', 'layouts/base.njk')
eleventyConfig.addLayoutAlias('page', 'layouts/page.njk')
eleventyConfig.addLayoutAlias('post', 'layouts/post.njk')
eleventyConfig.addLayoutAlias('author', 'layouts/author.njk')
/**
* Opts in to a full deep merge when combining the Data Cascade.
* Per the link below, "This will likely become the default in an upcoming major version."
* So I'm going to implement it now.
* @link https://www.11ty.dev/docs/data-deep-merge/#data-deep-merge
*/
eleventyConfig.setDataDeepMerge(true)
/**
* Override BrowserSync Server options
* This so we can have and test a 404 during local dev.
* @link https://www.11ty.dev/docs/config/#override-browsersync-server-options
*/
// eleventyConfig.setBrowserSyncConfig({
// notify: true,
// snippetOptions: {
// rule: {
// match: /<\/head>/i,
// fn: function (snippet, match) {
// return snippet + match
// },
// },
// },
// Set local server 404 fallback
// 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',
includes: '_includes',
data: '_data',
},
passthroughFileCopy: true,
templateFormats: ['html', 'njk', 'md'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
}
}