generated from x-govuk/govuk-eleventy-plugin
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path.eleventy.js
182 lines (153 loc) · 6.78 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
module.exports = function (eleventyConfig) {
// Browser Sync
eleventyConfig.setBrowserSyncConfig({
rewriteRules: [{
match: /\/image\/(\d+)(x)?(\d+)?/g,
replace: '/images'
}],
serveStatic: ['public'],
serveStaticOptions: {
extensions: ['html']
}
})
// Template libraries
eleventyConfig.setLibrary('njk', require('./lib/libraries/nunjucks'))
eleventyConfig.setLibrary('md', require('./lib/libraries/markdown'))
// Plugins
eleventyConfig.addPlugin(require('@11ty/eleventy-plugin-syntaxhighlight'))
eleventyConfig.addPlugin(require('@11ty/eleventy-navigation'))
// Filters
eleventyConfig.addFilter('date', require('./lib/filters/date'))
eleventyConfig.addFilter('fixed', require('./lib/filters/fixed'))
eleventyConfig.addFilter('includes', require('./lib/filters/includes'))
eleventyConfig.addFilter('markdown', require('./lib/filters/markdown'))
eleventyConfig.addFilter('notifyPlaceholders', require('./lib/filters/notify-placeholders'))
eleventyConfig.addFilter('pretty', require('./lib/filters/pretty'))
eleventyConfig.addFilter('slug', require('./lib/filters/slug'))
eleventyConfig.addFilter('slugs', require('./lib/filters/slugs'))
eleventyConfig.addFilter('sort', require('./lib/filters/sort'))
eleventyConfig.addFilter('tokenize', require('./lib/filters/tokenize'))
eleventyConfig.addFilter('totalFromRows', require('./lib/filters/total-from-rows'))
eleventyConfig.addFilter('widont', require('./lib/filters/widont'))
// Passthrough
eleventyConfig.addPassthroughCopy('./app/assets/images')
eleventyConfig.addPassthroughCopy({ './app/images': '.' })
eleventyConfig.addPassthroughCopy({ 'node_modules/govuk-frontend/dist/govuk/assets': 'assets' })
// Enable data deep merge
eleventyConfig.setDataDeepMerge(true)
// Collections
eleventyConfig.addCollection('serviceLine', collection => {
return collection.getFilteredByGlob([
'app/posts/becoming-a-teacher/becoming-a-teacher.md'
])
})
// List of service index pages
eleventyConfig.addCollection('services', collection => {
return collection.getFilteredByGlob([
'app/posts/apply-for-teacher-training/apply-for-teacher-training.md',
'app/posts/find-teacher-training/find-teacher-training.md',
'app/posts/manage-teacher-training-applications/manage-teacher-training-applications.md',
'app/posts/publish-teacher-training-courses/publish-teacher-training-courses.md',
'app/posts/register-trainee-teachers/register-trainee-teachers.md',
'app/posts/manage-school-placements/manage-school-placements.md',
'app/posts/claim-funding-for-mentors/claim-funding-for-mentors.md',
'app/posts/support-for-apply/support-for-apply.md',
'app/posts/support-for-publish/support-for-publish.md'
])
})
// Collections of posts for the service line
eleventyConfig.addCollection('becoming-a-teacher', collection => {
return collection.getFilteredByGlob('app/posts/becoming-a-teacher/*.md')
})
// Collections of posts for each service
eleventyConfig.addCollection('apply-for-teacher-training', collection => {
return collection.getFilteredByGlob('app/posts/apply-for-teacher-training/*.md')
})
eleventyConfig.addCollection('find-teacher-training', collection => {
return collection.getFilteredByGlob('app/posts/find-teacher-training/*.md')
})
eleventyConfig.addCollection('manage-teacher-training-applications', collection => {
return collection.getFilteredByGlob('app/posts/manage-teacher-training-applications/*.md')
})
eleventyConfig.addCollection('publish-teacher-training-courses', collection => {
return collection.getFilteredByGlob('app/posts/publish-teacher-training-courses/*.md')
})
eleventyConfig.addCollection('register-trainee-teachers', collection => {
return collection.getFilteredByGlob('app/posts/register-trainee-teachers/*.md')
})
eleventyConfig.addCollection('manage-school-placements', collection => {
return collection.getFilteredByGlob('app/posts/manage-school-placements/*.md')
})
eleventyConfig.addCollection('claim-funding-for-mentors', collection => {
return collection.getFilteredByGlob('app/posts/claim-funding-for-mentors/*.md')
})
eleventyConfig.addCollection('support-for-apply', collection => {
return collection.getFilteredByGlob('app/posts/support-for-apply/*.md')
})
eleventyConfig.addCollection('support-for-publish', collection => {
return collection.getFilteredByGlob('app/posts/support-for-publish/*.md')
})
// A collection of reference pages
eleventyConfig.addCollection('reference', collectionApi => {
return collectionApi.getFilteredByGlob(['app/glossary.md',
'app/mission-patches.md',
'app/service-map.md',
'app/posts/how-to/how-to.md'
])
})
// Collections of posts for each reference section
eleventyConfig.addCollection('how-to', collection => {
return collection.getFilteredByGlob('app/posts/how-to/*.md')
})
// A collection of user need pages
// eleventyConfig.addCollection('user-need', collectionApi => {
// return collectionApi.getFilteredByGlob([
// 'app/posts/apply-for--teacher-training/user-needs/*.md',
// 'app/posts/manage-teacher-training-applications/user-needs/*.md',
// 'app/posts/publish-teacher-training-courses/user-needs/*.md'
// ])
// })
// A collection of unique tags used across all posts
eleventyConfig.addCollection('allTags', collectionApi => {
const posts = collectionApi.getAll()
// Set up empty list of tags
let tags = []
for (const post of posts) {
if ('tags' in post.data) {
// Add any new tags from the post to the array
for (const tag of post.data.tags) {
// skip if already added
if (tags.includes(tag)) { continue }
// check that there’s not a tag which matches it except for capitlisation
const existingTag = tags.find(existingTag => existingTag.toLowerCase() === tag.toLowerCase())
if (existingTag) {
throw new Error('The post "' + post.data.title + '" contains tag "' + tag + '" which matches "' + existingTag + '" but capitalisation is different')
}
// otherwise add the new tag
tags.push(tag)
}
}
}
// Filter out any tags in the form of MN999 -
// these were used for tagging user needs.
// (TODO: rethink this feature?)
tags = tags.filter(tag => !tag.match(/[MPAS]N\d{3}/))
// sort tags alphabetically
tags = tags.sort((a, b) => a.localeCompare(b, 'en'))
return tags
})
// Config
return {
dataTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
dir: {
input: 'app',
output: 'public',
layouts: '_layouts',
includes: '_components'
},
templateFormats: ['njk', 'md'],
passthroughFileCopy: true
}
}