-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
87 lines (72 loc) · 2.41 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
const { getSpeedlifyComponent } = require('./src/speedlify.js')
const fs = require('fs')
const eleventyAutoCacheBuster = require("eleventy-auto-cache-buster");
module.exports = function (config) {
config.addPlugin(eleventyAutoCacheBuster);
if (fs.existsSync('_site')) {
fs.rmdirSync('_site/', { recursive: true })
}
config.setLiquidOptions({
dynamicPartials: true,
})
// Blog tags
config.addFilter('postTags', posts => {
const blogPosts = posts.blog
const allTags = Array.from(new Set(blogPosts.map(post => post.data.tags).reduce((acc, val) => acc.concat(val), [])))
// Populate new array with tag info, sort by count
const tagList = allTags.map(tag => ({
name: tag,
count: posts[tag]?.length ?? 0,
})).filter(tag => tag.count > 0)
tagList.sort((a, b) => b.count - a.count)
return tagList
})
// Projects tags
config.addFilter('projectTags', posts => {
const projectPosts = posts.projects
const allTags = Array.from(new Set(projectPosts.map(post => post.data.tags).reduce((acc, val) => acc.concat(val), [])))
// Populate new array with tag info, sort by count
const tagList = allTags.map(tag => ({
name: tag,
count: posts[tag]?.length ?? 0,
})).filter(tag => tag.count > 0)
tagList.sort((a, b) => b.count - a.count)
return tagList
})
// Static assets to pass through
config.addPassthroughCopy('./src/fonts')
config.addPassthroughCopy('./src/images')
config.addPassthroughCopy('./src/videos')
config.addPassthroughCopy('./src/public')
config.addPassthroughCopy('./src/styles')
config.addPassthroughCopy('./src/scripts')
config.addPassthroughCopy('./src/main.js')
config.addCollection('blog', function (collectionApi) {
return collectionApi
.getFilteredByGlob('./src/blog/*.md')
.sort(function (a, b) {
return b.date - a.date
})
})
config.addCollection('projects', function (collectionApi) {
return collectionApi
.getFilteredByGlob('./src/projects/*.md')
.sort(function (a, b) {
return b.date - a.date
})
})
config.addGlobalData("speedlify", async () => {
return await getSpeedlifyComponent()
})
return {
dir: {
input: 'src',
output: '_site',
},
passthroughFileCopy: true,
templateFormats: ['html', 'md', 'liquid'],
htmlTemplateEngine: 'liquid',
dataTemplateEngine: 'liquid',
markdownTemplateEngine: 'liquid',
}
}