-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
143 lines (109 loc) · 3.86 KB
/
.eleventy.js
File metadata and controls
143 lines (109 loc) · 3.86 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
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
require('dotenv').config()
const { PAGE_STATE } = process.env
const STATIC_FOLDERS = require('./_helper/paths')
const IS_LIVE = PAGE_STATE === 'production'
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(require('./_libraries'))
eleventyConfig.addPlugin(require('./_templates'))
eleventyConfig.addPlugin(require('./_filters'))
eleventyConfig.addPlugin(require('./_functions'))
eleventyConfig.addPlugin(require('./_shortcodes'))
eleventyConfig.addPlugin(require('./_plugins'))
eleventyConfig.addPlugin(require('./_transforms'))
eleventyConfig.addCollection('publishedPosts', function (collectionAPI) {
/** @type Array */
const posts = collectionAPI.getFilteredByGlob(
'_src/pages/text/blog/**/*.md',
)
const published = posts.filter((post) => {
if (!IS_LIVE) {
return true
}
const hasPastPublishDate = post.date && new Date(post.date) <= Date.now()
const isPublished =
hasPastPublishDate && !post.data.tags.includes('state:draft')
return isPublished
})
return published
})
eleventyConfig.addCollection('internalPosts', function (collectionAPI) {
/** @type Array */
const posts = collectionAPI.getFilteredByGlob(
'_src/pages/text/blog/**/*.md',
)
const published = posts.filter((post) => {
const isFuture = post.date && new Date(post.data.date) > Date.now()
return IS_LIVE
? !post.data.tags.includes('state:draft') && !isFuture
: true
})
return published.filter(function (post) {
if (post.data.external) {
return false
}
return true
})
})
const allCategories = new Set()
const categories = [
{ name: 'noteCategories', glob: '_src/pages/notes/notes/*.md' },
{ name: 'atwCategories', glob: '_src/pages/around-the-web/posts/*.md' },
{ name: 'blogCategories', glob: '_src/pages/text/blog/**/*.md' },
]
categories.forEach(function ({ name, glob }) {
eleventyConfig.addCollection(name, function (collectionAPI) {
/** @type Array */
const posts = collectionAPI.getFilteredByGlob(glob)
const categories = new Set()
for (const post of posts) {
const { tags } = post.data
if (!tags) {
continue
}
tags
.filter((tag) => tag.startsWith('cat:'))
.forEach((tag) => categories.add(tag) && allCategories.add(tag))
}
return [...categories]
})
})
eleventyConfig.addCollection('categories', function (collectionAPI) {
const categories = new Set()
const posts = collectionAPI.getFilteredByGlob('_src/pages/**/*.md')
for (const post of posts) {
const { tags } = post.data
if (!tags) {
continue
}
tags
.filter((tag) => tag.startsWith('cat:'))
.forEach((tag) => categories.add(tag) && allCategories.add(tag))
}
return [...categories]
})
eleventyConfig.addLayoutAlias('base', 'layouts/base.njk')
eleventyConfig.addLayoutAlias('digest', 'layouts/digest.njk')
eleventyConfig.addLayoutAlias('feed', 'layouts/feed.njk')
eleventyConfig.addLayoutAlias('note', 'layouts/note.njk')
eleventyConfig.addLayoutAlias('post', 'layouts/post.njk')
eleventyConfig.addWatchTarget(`./${STATIC_FOLDERS.js}**/*`)
eleventyConfig.addWatchTarget(`./${STATIC_FOLDERS.img}**/*`)
eleventyConfig.addWatchTarget('./_helper/**/*')
// copy static assets to dist folder
eleventyConfig.addPassthroughCopy({ [`./${STATIC_FOLDERS.img}`]: '/img/' })
eleventyConfig.addPassthroughCopy({ [`./${STATIC_FOLDERS.js}`]: '/js/' })
eleventyConfig.addPassthroughCopy({
[`./${STATIC_FOLDERS.files}`]: '/files/',
})
return {
templateFormats: ['md', '11ty.js', 'njk'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
dir: {
input: '_src',
output: 'dist',
data: '_data',
includes: '_includes',
},
}
}