-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.eleventy.js
191 lines (169 loc) · 7.02 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
183
184
185
186
187
188
189
190
191
const govukEleventyPlugin = require('@x-govuk/govuk-eleventy-plugin')
const { DateTime } = require("luxon");
const childProcess = require('child_process');
const fs = require("fs");
const path = require("path");
function injectGitSha(eleventyConfig, gitHubRepositoryUrl) {
let latestGitCommitHash = process.env.GITHUB_COMMIT_SHA;
if(!latestGitCommitHash) {
try {
latestGitCommitHash = childProcess.execSync('git rev-parse HEAD').toString().trim();
} catch (e) {
console.warn("Unable to determine current Git commit hash. Permalinks will not be generated.")
return;
}
}
eleventyConfig.addGlobalData(
'gitHashPath',
gitHubRepositoryUrl + '/blob/' + latestGitCommitHash + '/docs'
);
}
module.exports = function(eleventyConfig) {
const _siteRoot = process.env.SITE_ROOT ?? 'http://localhost/';
const gitHubRepositoryUrl = "https://github.com/UKHomeOffice/engineering-guidance-and-standards";
// Pass assets through to final build directory
eleventyConfig.addPassthroughCopy({ "docs/assets/logos": "assets/logos"});
// Register the plugins
let govukPluginOptions = {
scssSettingsPath: "/styles/_settings.scss",
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: {
logotype: {
html:
'<span class="govuk-header__logotype">' +
' <img src="/assets/logos/ho_logo.svg" height="34px" alt="Home Office Logo">' +
' <span class="govuk-header__logotype-text">Home Office</span>' +
'</span>'
},
productName: 'Engineering Guidance and Standards',
organisationName: 'Home Office',
search: {
label: 'Search site',
indexPath: '/search.json',
sitemapPath: '/sitemap.html'
}
},
footer: {
copyright: {
html: '© <a class="govuk-footer__link" href="https://github.com/UKHomeOffice/engineering-guidance-and-standards/blob/main/LICENCE">Crown Copyright (Home Office)</a>'
},
meta: {
items: [
{
href: '/about/',
text: 'About'
},
{
href: '/cookies/',
text: 'Cookies'
},
{
href: '/accessibility-statement/',
text: 'Accessibility'
},
{
href: gitHubRepositoryUrl,
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("postDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat('d MMMM yyyy');
});
// 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
});
});
fs.readdirSync(path.join(process.cwd(), path.join('lib', 'filters'))).map((file) => path.parse(file))
.filter(({ext}) => ext === '.js')
.forEach(({name, base}) =>
eleventyConfig.addFilter(
name,
require(path.join(process.cwd(), 'lib', 'filters', base)),
)
);
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: "New Service"
},
html: 'This is a new service – your ' +
'<a class="govuk-link" href="/provide-feedback/" target="_blank" rel="noopener">' +
'feedback (opens in a new tab)' +
'</a> ' +
'will help us to improve it.'
}
});
eleventyConfig.addGlobalData('siteRoot', _siteRoot);
injectGitSha(eleventyConfig, gitHubRepositoryUrl);
return {
dataTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
dir: {
data: '../_data',
layouts: '../_includes/layouts',
includes: '../_includes',
input: 'docs'
}
}
};