-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
283 lines (257 loc) · 10.4 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
require('module-alias/register')
const copy = require('rollup-plugin-copy')
const fs = require('fs-extra')
const packageJSON = require('./package.json');
const path = require('path')
const scss = require('rollup-plugin-scss')
const chalkFactory = require('~lib/chalk')
/**
* Quire features are implemented as Eleventy plugins
*/
const {
EleventyHtmlBasePlugin,
EleventyRenderPlugin
} = require('@11ty/eleventy')
const citationsPlugin = require('~plugins/citations')
const collectionsPlugin = require('~plugins/collections')
const componentsPlugin = require('~plugins/components')
const dataExtensionsPlugin = require('~plugins/dataExtensions')
const directoryOutputPlugin = require('@11ty/eleventy-plugin-directory-output')
const figuresPlugin = require('~plugins/figures')
const filtersPlugin = require('~plugins/filters')
const frontmatterPlugin = require('~plugins/frontmatter')
const globalDataPlugin = require('~plugins/globalData')
const i18nPlugin = require('~plugins/i18n')
const lintersPlugin = require('~plugins/linters')
const markdownPlugin = require('~plugins/markdown')
const navigationPlugin = require('@11ty/eleventy-navigation')
const pluginWebc = require('@11ty/eleventy-plugin-webc')
const searchPlugin = require('~plugins/search')
const shortcodesPlugin = require('~plugins/shortcodes')
const syntaxHighlightPlugin = require('@11ty/eleventy-plugin-syntaxhighlight')
const transformsPlugin = require('~plugins/transforms')
const vitePlugin = require('~plugins/vite')
const { error } = chalkFactory('eleventy config')
const inputDir = process.env.ELEVENTY_INPUT || 'content'
const outputDir = process.env.ELEVENTY_OUTPUT || '_site'
const publicDir = process.env.ELEVENTY_ENV === 'production' ? 'public' : false // publicDir should be set explicitly to false in development
/**
* Eleventy configuration
* @see {@link https://www.11ty.dev/docs/config/ Configuring 11ty}
*
* @param {Object} base eleventy configuration
* @return {Object} A modified eleventy configuation
*/
module.exports = function(eleventyConfig) {
/**
* Override addPassthroughCopy to use _absolute_ system paths.
* @see https://www.11ty.dev/docs/copy/#passthrough-file-copy
* Nota bene: Eleventy addPassthroughCopy assumes paths are _relative_
* to the `config` file however the quire-cli separates 11ty from the
* project directory (`input`) and needs to use absolute system paths.
*/
// @TODO Fix path resolution issue, disabling for now
// const addPassthroughCopy = eleventyConfig.addPassthroughCopy.bind(eleventyConfig)
//
// eleventyConfig.addPassthroughCopy = (entry) => {
// if (typeof entry === 'string') {
// const filePath = path.resolve(entry)
// console.debug('[11ty:config] passthrough copy %s', filePath)
// return addPassthroughCopy(filePath, { expand: true })
// } else {
// console.debug('[11ty:config] passthrough copy %o', entry)
// entry = Object.fromEntries(
// Object.entries(entry).map(([ src, dest ]) => {
// return [
// path.join(__dirname, src),
// path.resolve(path.join(outputDir, dest))
// ]
// })
// )
// console.debug('[11ty:config] passthrough copy %o', entry)
// return addPassthroughCopy(entry, { expand: true })
// }
// }
eleventyConfig.addGlobalData('application', {
name: 'Quire',
version: packageJSON.version
})
/**
* Ignore README files when processing templates
* @see {@link https://www.11ty.dev/docs/ignores/ Ignoring Template Files }
*/
eleventyConfig.ignores.add('**/README.md')
/**
* Configure the Liquid template engine
* @see https://www.11ty.dev/docs/languages/liquid/#liquid-options
* @see https://github.com/11ty/eleventy/blob/master/src/Engines/Liquid.js
*
* @property {boolean} [dynamicPartials=false]
* @property {boolean} [strictFilters=false]
*/
eleventyConfig.setLiquidOptions({
dynamicPartials: true,
strictFilters: true
})
/**
* Configure build output
* @see https://www.11ty.dev/docs/plugins/directory-output/#directory-output
*/
eleventyConfig.setQuietMode(true)
eleventyConfig.addPlugin(directoryOutputPlugin)
/**
* @see https://www.11ty.dev/docs/plugins/html-base/
*/
eleventyConfig.addPlugin(EleventyHtmlBasePlugin)
/**
* Plugins are loaded in this order:
* 1) immediately invoked
* 2) addPlugin statements
* Plugins that mutate globalData must be added before other plugins
*
* Note: The config does **not** have access to collections or global,
* to get around this we invoke some plugins immediately and return a value
* so that data can be provided to the config or another plugin.
*/
dataExtensionsPlugin(eleventyConfig)
const globalData = globalDataPlugin(eleventyConfig, { inputDir, outputDir, publicDir })
const collections = collectionsPlugin(eleventyConfig)
vitePlugin(eleventyConfig, globalData)
eleventyConfig.addPlugin(i18nPlugin)
eleventyConfig.addPlugin(figuresPlugin)
/**
* Load plugin for custom configuration of the markdown library
*/
eleventyConfig.addPlugin(markdownPlugin)
/**
* Load plugins for the Quire template shortcodes and filters
*/
eleventyConfig.addPlugin(componentsPlugin, collections)
eleventyConfig.addPlugin(filtersPlugin)
eleventyConfig.addPlugin(frontmatterPlugin)
eleventyConfig.addPlugin(shortcodesPlugin, collections)
/**
* Load additional plugins used for Quire projects
*/
eleventyConfig.addPlugin(citationsPlugin)
eleventyConfig.addPlugin(navigationPlugin)
eleventyConfig.addPlugin(searchPlugin, collections)
eleventyConfig.addPlugin(syntaxHighlightPlugin)
/**
* Add shortcodes to render an Eleventy template inside of another template,
* allowing JavaScript, Liquid, and Nunjucks templates to be freely mixed.
* @see {@link https://www.11ty.dev/docs/_plugins/render/}
*/
eleventyConfig.addPlugin(EleventyRenderPlugin)
/**
* Add plugin for WebC support
* @see https://www.11ty.dev/docs/languages/webc/#installation
*
* @typedef {PluginWebcOptions}
* @property {String} components - Glob pattern for no-import global components
* @property {Object} transformData - Additional global data for WebC transform
* @property {Boolean} useTransform - Use WebC transform to process all HTML output
*/
eleventyConfig.addPlugin(pluginWebc, {
components: '_includes/components/**/*.webc',
transformData: {},
useTransform: false,
})
/**
* Register a plugin to run linters on input templates
* Nota bene: linters are run *before* applying layouts
*/
eleventyConfig.addPlugin(lintersPlugin)
/**
* Register plugin to run tranforms on build output
*/
eleventyConfig.addPlugin(transformsPlugin, collections)
/**
* Set eleventy dev server options
* @see https://www.11ty.dev/docs/dev-server/
*/
eleventyConfig.setServerOptions({
port: 8080
})
// @see https://www.11ty.dev/docs/copy/#passthrough-during-serve
// @todo resolve error when set to the default behavior 'passthrough'
eleventyConfig.setServerPassthroughCopyBehavior('copy')
/**
* Copy static assets to the output directory
* @see https://www.11ty.dev/docs/copy/
*/
if (process.env.ELEVENTY_ENV === 'production') eleventyConfig.addPassthroughCopy(publicDir)
eleventyConfig.addPassthroughCopy(`${inputDir}/_assets`)
eleventyConfig.addPassthroughCopy({ '_includes/web-components': '_assets/javascript' })
/**
* Watch the following additional files for changes and rerun server
* @see https://www.11ty.dev/docs/config/#add-your-own-watch-targets
* @see https://www.11ty.dev/docs/watch-serve/#ignore-watching-files
*/
eleventyConfig.addWatchTarget('./**/*.css')
eleventyConfig.addWatchTarget('./**/*.js')
eleventyConfig.addWatchTarget('./**/*.scss')
/**
* Ignore changes to programmatic build artifacts
* @see https://www.11ty.dev/docs/watch-serve/#ignore-watching-files
* @todo refactor to move these statements to the tranform plugins
*/
eleventyConfig.watchIgnores.add('_epub')
eleventyConfig.watchIgnores.add('_pdf')
eleventyConfig.watchIgnores.add('_temp')
const { pathname: pathPrefix } = globalData.publication
return {
/**
* @see {@link https://www.11ty.dev/docs/config/#configuration-options}
*/
dir: {
// ⚠️ input and output dirs are _relative_ to the `.eleventy.js` module
input: inputDir,
output: outputDir,
// ⚠️ the following directories are _relative_ to the `input` directory
data: process.env.ELEVENTY_DATA || '_computed',
includes: process.env.ELEVENTY_INCLUDES || path.join('..', '_includes'),
layouts: process.env.ELEVENTY_LAYOUTS || path.join('..', '_layouts'),
},
/**
* The default global template engine to pre-process HTML files.
* Use false to avoid pre-processing and passthrough copy the content (HTML is not transformed, so technically this could be any plaintext).
* @see {@link https://www.11ty.dev/docs/config/#default-template-engine-for-html-files}
*/
htmlTemplateEngine: 'liquid',
/**
* Suffix for template and directory specific data files
* @example '.data' will search for `*.data.js` and `*.data.json` data files.
* @see {@link https://www.11ty.dev/docs/data-template-dir/ Template and Directory Specific Data Files}
*/
jsDataFileSuffix: '.data',
/**
* The default global template engine to pre-process markdown files.
* Use false to avoid pre-processing and only transform markdown.
* @see {@link https://www.11ty.dev/docs/config/#default-template-engine-for-markdown-files}
*/
markdownTemplateEngine: 'liquid',
/**
* @see {@link https://www.11ty.dev/docs/config/#deploy-to-a-subdirectory-with-a-path-prefix}
*/
pathPrefix,
/**
* All of the following template formats support universal shortcodes.
*
* Nota bene:
* Markdown files are pre-processed as Liquid templates by default. This
* means that shortcodes available in Liquid templates are also available
* in Markdown files. Likewise, if you change the template engine for
* Markdown files, the shortcodes available for that templating language
* will also be available in Markdown files.
* @see {@link https://www.11ty.dev/docs/config/#template-formats}
*/
templateFormats: [
'11ty.js', // JavaScript
'hbs', // Handlebars
'liquid', // Liquid
'md', // Markdown
'njk', // Nunjucks
]
}
}