forked from UKHomeOffice/engineering-guidance-and-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
164 lines (147 loc) · 6.35 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
const govukEleventyPlugin = require('@x-govuk/govuk-eleventy-plugin')
const { DateTime } = require("luxon");
module.exports = function(eleventyConfig) {
// Set custom variable to decide the path prefix as it is used in a couple of places.
const _customPathPrefix = process.env.PATH_PREFIX ?? '';
const _siteRoot = process.env.SITE_ROOT ?? 'http://localhost/';
// Pass assets through to final build directory
eleventyConfig.addPassthroughCopy({ "docs/assets/logos": "assets/logos"});
// Register the plugins
let govukPluginOptions = {
brandColour: '#8f23b3',
fontFamily: 'roboto, system-ui, sans-serif',
icons: {
mask: '/assets/logos/ho-mask-icon.svg',
shortcut: '/assets/logos/ho-favicon.ico',
touch: '/assets/logos/ho-apple-touch-icon.png'
},
opengraphImageUrl: '/assets/logos/ho-opengraph-image.png',
homeKey: 'Home',
header: {
organisationLogo: '<img src="' + _customPathPrefix + '/assets/logos/ho_logo.svg" height="34px" alt="Home Office Logo">',
organisationName: 'Home Office',
productName: 'Engineering Guidance and Standards',
search: {
label: 'Search site',
indexPath: '/search.json',
sitemapPath: '/sitemap'
}
},
footer: {
copyright: {
html: '© <a class="govuk-footer__link" href="https://github.com/HO-CTO/engineering-guidance-and-standards/blob/main/LICENCE">Crown Copyright (Home Office)</a>'
},
meta: {
items: [
{
href: _customPathPrefix + '/about/',
text: 'About'
},
{
href: _customPathPrefix + '/cookies/',
text: 'Cookies'
},
{
href: _customPathPrefix + '/accessibility-statement/',
text: 'Accessibility'
},
{
href: 'https://github.com/HO-CTO/engineering-guidance-and-standards',
text: 'GitHub repository'
}
]
}
},
stylesheets: ['/styles/base.css'],
};
eleventyConfig.addPlugin(govukEleventyPlugin, govukPluginOptions)
// Customise markdown-it renderer provided by x-gov 11ty plugin. Plugin execution is
// deferred, so this needs to be a plugin, and added after the x-gov plugin is.
eleventyConfig.addPlugin((eleventyConfig) => {
const md = require('@x-govuk/govuk-eleventy-plugin/lib/markdown-it.js')(govukPluginOptions)
md.use(require('./lib/markdown/dl-as-govuk-summary-list'));
eleventyConfig.setLibrary('md', md);
})
eleventyConfig.addFilter("itemsFromPaginationWithPathPrefix", (pagination) => {
const items = []
pagination.pages.forEach((item, index) => {
items.push({
current: index === pagination.pageNumber,
number: index + 1,
href: _customPathPrefix + pagination.hrefs[index]
})
})
return items;
});
eleventyConfig.addFilter("postDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toLocaleString(DateTime.DATE_FULL);
});
// Used for tag page generation
eleventyConfig.addFilter("getAllTags", collection => {
let tagSet = new Set();
for(let item of collection) {
(item.data.tags || []).forEach(tag => tagSet.add(tag));
}
return Array.from(tagSet).sort(function(a, b) {
return a.localeCompare(b); // sort by tag name
});
});
eleventyConfig.addFilter("filterTagList", function filterTagList(tags) {
// Tags in array are ignored, no tag list page is generated for these
return (tags || []).filter(tag => ["homepage"].indexOf(tag) === -1);
});
eleventyConfig.addFilter("orderPagesByTitle", function orderByTitle(collection) {
return collection.sort(function(a, b) {
return a.data.title.localeCompare(b.data.title); // sort by title ascending
});
});
eleventyConfig.addCollection("homepageLinks", function(collectionApi) {
return [
...collectionApi.getFilteredByGlob(["**/principles.md"]),
...collectionApi.getFilteredByGlob(["**/standards.md"]),
...collectionApi.getFilteredByGlob(["**/patterns.md"]),
];
});
eleventyConfig.addCollection("getAllStandardsOrderedByID", function(collectionApi) {
return collectionApi.getFilteredByGlob("**/standards/*.md").sort(function(a, b) {
return a.data.id.localeCompare(b.data.id); // sort by ID ascending
});
});
eleventyConfig.addCollection("getAllStandardsOrderedByTitle", function(collectionApi) {
return collectionApi.getFilteredByGlob("**/standards/*.md").sort(function(a, b) {
return a.data.title.localeCompare(b.data.title); // sort by title ascending
});
});
eleventyConfig.addCollection("getAllPrinciplesOrderedByTitle", function(collectionApi) {
return collectionApi.getFilteredByGlob("**/principles/*.md").sort(function(a, b) {
return a.data.title.localeCompare(b.data.title); // sort by title ascending
});
});
eleventyConfig.addCollection("getAllPatternsOrderedByTitle", function(collectionApi) {
return collectionApi.getFilteredByGlob("**/patterns/*.md").sort(function(a, b) {
return a.data.title.localeCompare(b.data.title); // sort by title ascending
});
});
eleventyConfig.addGlobalData("phaseBannerConfiguration", () => {
return {
tag: {
text: "Alpha"
},
html: 'This is a new service – your <a class="govuk-link" target="_blank" href="' + _customPathPrefix + '/provide-feedback/">feedback (opens in a new tab)</a> will help us to improve it.'
}
});
eleventyConfig.addGlobalData('pathPrefix', _customPathPrefix);
eleventyConfig.addGlobalData('siteRoot', _siteRoot);
return {
dataTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
dir: {
data: '../_data',
layouts: '../_includes/layouts',
includes: '../_includes',
input: 'docs'
},
pathPrefix: _customPathPrefix
}
};