-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
113 lines (87 loc) · 3.53 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
if (process.env.ELEVENTY_ENV !== 'production') {
require('dotenv').config();
}
// Flags whether we compress the output etc
const isProduction = process.env.ELEVENTY_ENV === 'production';
const markdownIt = require('markdown-it');
const markdownItAttrs = require('markdown-it-attrs');
const markdownItAnchor = require('markdown-it-anchor');
// Breadcrumb trail
const eleventyNavigationPlugin = require('@11ty/eleventy-navigation');
// Table of contents
const eleventyPluginTOC = require('@thedigitalman/eleventy-plugin-toc-a11y');
// Dates
const { DateTime } = require('luxon');
const markdownItOptions = {
html: true,
breaks: true,
linkify: false
};
const markdownItAnchorOptions = {
level: 2,
tabIndex: false
};
module.exports = function (eleventyConfig) {
// Watch for changes
eleventyConfig.addWatchTarget('./src/assets');
// Date published and updated formatting
eleventyConfig.addFilter('publishedDate', dateObj => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('LLLL yyyy');
});
eleventyConfig.setUseGitIgnore(false);
// Copy GOV.UK fonts
// eleventyConfig.addPassthroughCopy({'node_modules/govuk-frontend/govuk/assets/fonts': 'assets/fonts'});
// Copy GOV.UK assets
eleventyConfig.addPassthroughCopy({ 'node_modules/govuk-frontend/govuk/assets/images': 'assets/images' });
// Copy GOV.UK javascript
eleventyConfig.addPassthroughCopy({ 'node_modules/govuk-frontend/govuk/all.js': 'assets/scripts/govuk.js' });
// Copy HMCTS Cookies javascript
eleventyConfig.addPassthroughCopy({ './src/assets/scripts/cookie-manager-1.0.0.min.js': 'assets/scripts/cookie-manager-1.0.0.min.js' });
// Copy cookies javascript
eleventyConfig.addPassthroughCopy({ './components/cookies/cookies.js': 'assets/scripts/cookies.js' });
// Copy MOD.UK assets
eleventyConfig.addPassthroughCopy({ './src/assets/images': 'assets/images' });
// Copy downloads folder
eleventyConfig.addPassthroughCopy({ './src/downloads': 'downloads' });
// Table of contents
eleventyConfig.addPlugin(eleventyPluginTOC, {
tags: ['h2'],
wrapper: 'nav',
wrapperClass: 'moduk-contents-list',
heading: true,
headingClass: 'moduk-contents-list__title',
headingLevel: 'h2',
headingText: 'Contents',
listType: 'ol',
listClass: 'moduk-contents-list__list',
listItemClass: 'moduk-contents-list__list-item moduk-contents-list__list-item--dashed',
listItemAnchorClass: 'moduk-contents-list__link govuk-link govuk-link--no-visited-state',
});
// Macros used in markdown files
eleventyConfig.addCollection('everything', (collectionApi) => {
const macroImport = `{%- from 'system/component.njk' import component -%}{%- from 'system/modukcomponent.njk' import modukcomponent -%}`
let collMacros = collectionApi.getFilteredByGlob('src/**/*.md')
collMacros.forEach((item) => {
item.template.frontMatter.content = `${macroImport}\n${item.template.frontMatter.content}`
})
return collMacros
});
// Markdown configurations
eleventyConfig.setLibrary('md', markdownIt(markdownItOptions).use(markdownItAnchor, markdownItAnchorOptions).use(markdownItAttrs));
// Navigation
eleventyConfig.addPlugin(eleventyNavigationPlugin);
// Suppresses output of the paths of all generated files
eleventyConfig.setQuietMode(false);
// Configurations
return {
dir: {
input: 'src',
output: 'public',
includes: '_includes'
},
templateFormats: ['md', 'njk', 'html'],
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
dataTemplateEngine: 'njk'
};
};