-
Notifications
You must be signed in to change notification settings - Fork 1
/
eleventy.config.drafts.js
56 lines (48 loc) · 1.6 KB
/
eleventy.config.drafts.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
function eleventyComputedPermalink() {
// When using `addGlobalData` and you *want* to return a function, you must nest functions like this.
// `addGlobalData` acts like a global data file and runs the top level function it receives.
return (data) => {
// Always skip during non-watch/serve builds
if (data.draft && !process.env.BUILD_DRAFTS) {
return false
}
return data.permalink
}
}
function eleventyComputedExcludeFromCollections() {
// When using `addGlobalData` and you *want* to return a function, you must nest functions like this.
// `addGlobalData` acts like a global data file and runs the top level function it receives.
return (data) => {
// Always exclude from non-watch/serve builds
if (data.draft && !process.env.BUILD_DRAFTS) {
return true
}
return data.eleventyExcludeFromCollections
}
}
export { eleventyComputedPermalink }
export { eleventyComputedExcludeFromCollections }
export default (eleventyConfig) => {
eleventyConfig.addGlobalData(
'eleventyComputed.permalink',
eleventyComputedPermalink
)
eleventyConfig.addGlobalData(
'eleventyComputed.eleventyExcludeFromCollections',
eleventyComputedExcludeFromCollections
)
let logged = false
eleventyConfig.on('eleventy.before', ({ runMode }) => {
let text = 'Excluding'
// Only show drafts in serve/watch modes
if (runMode === 'serve' || runMode === 'watch') {
process.env.BUILD_DRAFTS = true
text = 'Including'
}
// Only log once.
if (!logged) {
console.log(`[11ty/eleventy-base-blog] ${text} drafts.`)
}
logged = true
})
}