-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy patheleventy.config.js
141 lines (122 loc) · 4.38 KB
/
eleventy.config.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
import dotenv from 'dotenv'
dotenv.config()
import pluginRss from '@11ty/eleventy-plugin-rss'
import pluginNavigation from '@11ty/eleventy-navigation'
import pluginSyntaxHighlight from '@11ty/eleventy-plugin-syntaxhighlight'
import { eleventyImageTransformPlugin as pluginImageTransform } from '@11ty/eleventy-img'
import pluginPageAssets from 'eleventy-plugin-page-assets'
import pluginShareHighlight from 'eleventy-plugin-share-highlight'
import pluginSVGSprite from 'eleventy-plugin-svg-sprite'
import filters from './utils/filters.js'
import transforms from './utils/transforms.js'
import shortcodes from './utils/shortcodes.js'
import markdown from './utils/markdown.js'
import viteHelpers from './utils/vite.js'
const IS_PRODUCTION = process.env.NODE_ENV === 'production'
const CONTENT_GLOBS = {
posts: 'src/posts/**/*.md',
drafts: 'src/drafts/**/*.md',
notes: 'src/notes/*.md',
media: '*.jpg|*.png|*.gif|*.mp4|*.webp|*.webm'
}
export default function (config) {
// Plugins
config.addPlugin(pluginRss)
config.addPlugin(pluginNavigation)
config.addPlugin(pluginSyntaxHighlight)
config.addPlugin(pluginPageAssets, {
mode: 'directory',
postsMatching: 'src/posts/*/*.md',
assetsMatching: CONTENT_GLOBS.media,
silent: true
})
config.addPlugin(pluginSVGSprite, {
path: './src/assets/icons',
outputFilepath: './dist/assets/icons/icons.sprite.svg'
})
config.addPlugin(pluginImageTransform, {
extensions: 'html',
formats: ['avif', 'auto'],
outputDir: './dist/assets/images/processed/',
urlPath: '/assets/images/processed/',
widths: ['auto'],
defaultAttributes: {
loading: 'lazy',
decoding: 'async'
}
})
config.addPlugin(pluginShareHighlight)
// Filters
Object.keys(filters).forEach((filterName) => {
config.addFilter(filterName, filters[filterName])
})
// Transforms
Object.keys(transforms).forEach((transformName) => {
config.addTransform(transformName, transforms[transformName])
})
// Shortcodes
config.addShortcode('icon', shortcodes.icon)
config.addPairedShortcode('signup', shortcodes.signup)
config.addPairedShortcode('callout', shortcodes.callout)
// Vite Shortcodes
Object.keys(viteHelpers).forEach((shortcodeName) => {
config.addNunjucksAsyncShortcode(
shortcodeName,
viteHelpers[shortcodeName]
)
})
// Asset Watch Targets
config.addWatchTarget('./src/assets')
// Markdown Parsing
config.setLibrary('md', markdown)
// Layouts
config.addLayoutAlias('base', 'base.njk')
config.addLayoutAlias('page', 'page.njk')
config.addLayoutAlias('post', 'post.njk')
config.addLayoutAlias('draft', 'draft.njk')
config.addLayoutAlias('note', 'note.njk')
// Pass-through files
config.addPassthroughCopy('src/site.webmanifest')
config.addPassthroughCopy('src/robots.txt')
config.addPassthroughCopy('src/assets/images')
config.addPassthroughCopy('src/assets/fonts')
// Deep-Merge
config.setDataDeepMerge(true)
// Collections: Posts
config.addCollection('posts', function (collection) {
return collection
.getFilteredByGlob(CONTENT_GLOBS.posts)
.filter((item) => item.data.permalink !== false)
.filter((item) => !(item.data.draft && IS_PRODUCTION))
})
// Collections: Drafts
config.addCollection('drafts', function (collection) {
return collection
.getFilteredByGlob(CONTENT_GLOBS.drafts)
.filter((item) => item.data.permalink !== false)
})
// Collections: Notes
config.addCollection('notes', function (collection) {
return collection.getFilteredByGlob(CONTENT_GLOBS.notes).reverse()
})
// Collections: Featured Posts
config.addCollection('featured', function (collection) {
return collection
.getFilteredByGlob(CONTENT_GLOBS.posts)
.filter((item) => item.data.featured)
.sort((a, b) => b.date - a.date)
})
// Base Config
return {
dir: {
input: 'src',
output: 'dist',
includes: 'includes',
layouts: 'layouts',
data: 'data'
},
templateFormats: ['njk', 'md', '11ty.js'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk'
}
}