-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheleventy.config.js
More file actions
83 lines (71 loc) · 2.74 KB
/
eleventy.config.js
File metadata and controls
83 lines (71 loc) · 2.74 KB
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
/**
* @file Configuration file for Eleventy
* @author Reuben L. Lillie <rlillie@loopnaz.org>
* @since 2.0.0
* @see {@link https://www.11ty.dev/docs/config/ Eleventy configuration}
*/
// Import native Node.js modules
import fs from 'node:fs/promises'
// Import Eleventy plugins
import {EleventyI18nPlugin} from '@11ty/eleventy'
// Import local modules
import i18n from './_data/i18n.js'
import toCamelCase from './_includes/filters/to-camel-case.js'
/** @type {Object} Destructure internationalization data */
var {defaultLanguage: {tag}} = i18n
/**
* Configure Eleventy
* @module .eleventy
* @param {Object} eleventyConfig Eleventy’s Config API
* @returns {void|Object} Eleventy’s optional `config` object
*/
export default async eleventyConfig => {
/**
* Set the directory for layouts
* @see {@link https://www.11ty.dev/docs/config/#directory-for-layouts-optional Layouts directory in Eleventy}
*/
eleventyConfig.setLayoutsDirectory('_layouts')
/**
* Configure Eleventy’s internationalization (i18n) plugin
* @see _data/i18n
*/
eleventyConfig.addPlugin(EleventyI18nPlugin, {
defaultLanguage: tag
})
/**
* Import default modules from a directory and configure them with Eleventy
* @since 2.0.0
* @param {string} dir Directory path from which to import files
* @param {function} [callback=addJavaScriptFunction] `eleventyConfig` method
* @return {Promise<function>} Passes each default export to the `callback`
* @see toCamelCase
* @see {@link https://discord.com/channels/741017160297611315/1276983631184662663 Eleventy Discord}
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import Dynamic `import()` on MDN}
*/
async function importFromDir(dir, callback = 'addJavaScriptFunction') {
/** @type {string[]} List the files in a directory */
var files = await fs.readdir(dir)
// Run on each of the files
return await Promise.all(files.map(async fileName => {
/** @type {string} Format fileName to pass to eleventyConfig[callback] */
var name = toCamelCase(fileName)
/** @type {Promise<function>} Import the module dynamically */
var module = await import(`${dir}/${fileName}`)
eleventyConfig[callback](name, module.default)
}))
}
/*
* Configure Filters
*/
await importFromDir('./_includes/filters')
/**
* Copy files directly to Eleventy output
* @see {@link https://www.11ty.dev/docs/copy/ Passtrough files in Eleventy}
*/
eleventyConfig.addPassthroughCopy('admin')
eleventyConfig.addPassthroughCopy('css')
eleventyConfig.addPassthroughCopy('js')
eleventyConfig.addPassthroughCopy('_data/geojson')
eleventyConfig.addPassthroughCopy('favicons')
eleventyConfig.addPassthroughCopy('fonts')
}