/
.eleventy.js
138 lines (123 loc) · 3.82 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
const markdownIt = require('markdown-it')
const markdownItAnchor = require('markdown-it-anchor')
const EleventyPluginNavigation = require('@11ty/eleventy-navigation')
const EleventyPluginRss = require('@11ty/eleventy-plugin-rss')
const EleventyPluginSyntaxhighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
const EleventyVitePlugin = require('@11ty/eleventy-plugin-vite')
const rollupPluginCritical = require('rollup-plugin-critical').default
const filters = require('./utils/filters.js')
const transforms = require('./utils/transforms.js')
const shortcodes = require('./utils/shortcodes.js')
const { resolve } = require('path')
module.exports = function (eleventyConfig) {
eleventyConfig.setServerPassthroughCopyBehavior('copy');
eleventyConfig.addPassthroughCopy("public");
// Plugins
eleventyConfig.addPlugin(EleventyPluginNavigation)
eleventyConfig.addPlugin(EleventyPluginRss)
eleventyConfig.addPlugin(EleventyPluginSyntaxhighlight)
eleventyConfig.addPlugin(EleventyVitePlugin, {
tempFolderName: '.11ty-vite', // Default name of the temp folder
// Vite options (equal to vite.config.js inside project root)
viteOptions: {
publicDir: 'public',
clearScreen: false,
server: {
mode: 'development',
middlewareMode: true,
},
appType: 'custom',
assetsInclude: ['**/*.xml', '**/*.txt'],
build: {
mode: 'production',
sourcemap: 'true',
manifest: true,
// This puts CSS and JS in subfolders – remove if you want all of it to be in /assets instead
rollupOptions: {
output: {
assetFileNames: 'assets/css/main.[hash].css',
chunkFileNames: 'assets/js/[name].[hash].js',
entryFileNames: 'assets/js/[name].[hash].js'
},
plugins: [rollupPluginCritical({
criticalUrl: './_site/',
criticalBase: './_site/',
criticalPages: [
{ uri: 'index.html', template: 'index' },
{ uri: 'posts/index.html', template: 'posts/index' },
{ uri: '404.html', template: '404' },
],
criticalConfig: {
inline: true,
dimensions: [
{
height: 900,
width: 375,
},
{
height: 720,
width: 1280,
},
{
height: 1080,
width: 1920,
}
],
penthouse: {
forceInclude: ['.fonts-loaded-1 body', '.fonts-loaded-2 body'],
}
}
})
]
}
}
}
})
// Filters
Object.keys(filters).forEach((filterName) => {
eleventyConfig.addFilter(filterName, filters[filterName])
})
// Transforms
Object.keys(transforms).forEach((transformName) => {
eleventyConfig.addTransform(transformName, transforms[transformName])
})
// Shortcodes
Object.keys(shortcodes).forEach((shortcodeName) => {
eleventyConfig.addShortcode(shortcodeName, shortcodes[shortcodeName])
})
eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`)
// Customize Markdown library and settings:
let markdownLibrary = markdownIt({
html: true,
breaks: true,
linkify: true
}).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
placement: 'after',
class: 'direct-link',
symbol: '#',
level: [1, 2, 3, 4]
}),
slugify: eleventyConfig.getFilter('slug')
})
eleventyConfig.setLibrary('md', markdownLibrary)
// Layouts
eleventyConfig.addLayoutAlias('base', 'base.njk')
eleventyConfig.addLayoutAlias('post', 'post.njk')
// Copy/pass-through files
eleventyConfig.addPassthroughCopy('src/assets/css')
eleventyConfig.addPassthroughCopy('src/assets/js')
return {
templateFormats: ['md', 'njk', 'html', 'liquid'],
htmlTemplateEngine: 'njk',
passthroughFileCopy: true,
dir: {
input: 'src',
// better not use "public" as the name of the output folder (see above...)
output: '_site',
includes: '_includes',
layouts: 'layouts',
data: '_data'
}
}
}