generated from 11ta/11ta-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
180 lines (163 loc) · 6.07 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
const pluginRss = require('@11ty/eleventy-plugin-rss')
const pluginNavigation = require('@11ty/eleventy-navigation')
const markdownIt = require('markdown-it')
const markdownItEmoji = require('markdown-it-emoji')
const markdownItFigureCaption = require('markdown-it-image-figures')
const markdownItAnchor = require('markdown-it-anchor')
const structure = require('./src/_data/structure.js')
const filterFactory = require('./utils/filters.js')
const njkFilterFactory = require('./utils/njkFilters.js')
const njkGlobalsFactory = require('./utils/njkGlobals.js')
// const sprite = require('./utils/sprite.js')
const shortcodesFactory = require('./utils/shortcodes.js')
const pairedshortcodesFactory = require('./utils/paired-shortcodes.js')
const pluginDrafts = require('./eleventy.config.drafts.js')
const pluginSprite = require('./eleventy.config.sprite.js')
const { minify } = require('terser')
const htmlmin = require('html-minifier')
module.exports = function (eleventyConfig) {
eleventyConfig.setServerOptions({
showAllHosts: true, // Show local network IP addresses for device testing (e.g. use devServer on mobile devices)
})
/**
* Plugins
* @link https://www.11ty.dev/docs/plugins/
*/
eleventyConfig.addPlugin(pluginRss)
eleventyConfig.addPlugin(pluginNavigation)
eleventyConfig.addPlugin(pluginDrafts)
eleventyConfig.addPlugin(pluginSprite)
/**
* 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/*.ico')
eleventyConfig.addPassthroughCopy('src/robots.txt')
eleventyConfig.addPassthroughCopy({ 'seo_config/*.html': '/' })
eleventyConfig.addPassthroughCopy({ 'netlify_config/**/*': '/' })
eleventyConfig.addPassthroughCopy('src/assets/images/')
eleventyConfig.addPassthroughCopy('src/assets/video/')
/**
* Add JS minified. Call this filter in a (e.g. base) NJK file to include minified JS file
*/
eleventyConfig.addNunjucksAsyncFilter('jsmin', async function (code, callback) {
if (process.env.NODE_ENV?.trim() === 'production') {
try {
const minified = await minify(code, {})
callback(null, minified.code)
} catch (err) {
console.error('JS minify failed to minify')
console.error('Terser error: ', err)
// Fail gracefully.
callback(null, code)
}
} else {
callback(null, code)
}
})
eleventyConfig.addTransform('htmlmin', function (content) {
if (process.env.NODE_ENV?.trim() === 'production') {
if ((this.page.outputPath || '').endsWith('.html')) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
})
return minified
}
// If not an HTML output, return content as-is
return content
}
//if not production, return content.
return content
})
/**
* 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)
.use(markdownItFigureCaption, { figcaption: 'alt' })
.use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
placement: 'after',
class: structure.g_markdownItAnchor_classes,
symbol: '#',
ariaHidden: false,
}),
level: [1, 2, 3, 4],
slugify: eleventyConfig.getFilter('slugify'),
})
eleventyConfig.setLibrary('md', markdownLib)
const njkGlobals = njkGlobalsFactory.init(eleventyConfig)
Object.keys(njkGlobals).forEach((filterName) => {
eleventyConfig.addNunjucksGlobal(filterName, njkGlobals[filterName])
})
const njkFilters = njkFilterFactory.init(eleventyConfig, markdownLib)
Object.keys(njkFilters).forEach((filterName) => {
eleventyConfig.addNunjucksFilter(filterName, njkFilters[filterName])
})
const filters = filterFactory.init(eleventyConfig, markdownLib) //use a factory so we can pass the eleventyConfig, which could be used in filters to access other filters. see https://www.11ty.dev/docs/filters/
/**
* Filters
* @link https://www.11ty.io/docs/filters/
*/
Object.keys(filters).forEach((filterName) => {
eleventyConfig.addFilter(filterName, filters[filterName])
})
const shortcodes = shortcodesFactory.init(eleventyConfig, markdownLib)
/**
* Shortcodes
* @link https://www.11ty.io/docs/shortcodes/
*/
Object.keys(shortcodes).forEach((shortcodeName) => {
eleventyConfig.addShortcode(shortcodeName, shortcodes[shortcodeName])
})
const pairedshortcodes = pairedshortcodesFactory.init(eleventyConfig, markdownLib)
/**
* Paired Shortcodes
* @link https://www.11ty.dev/docs/languages/nunjucks/#paired-shortcode
*/
Object.keys(pairedshortcodes).forEach((shortcodeName) => {
eleventyConfig.addPairedShortcode(shortcodeName, pairedshortcodes[shortcodeName])
})
/**
* 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('member', 'layouts/member.njk')
return {
dir: {
input: 'src',
output: 'dist',
includes: '_includes',
data: '_data',
},
passthroughFileCopy: true,
templateFormats: ['html', 'njk', 'md'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
}
}