-
Notifications
You must be signed in to change notification settings - Fork 34
/
eleventy.config.js
236 lines (205 loc) · 8.7 KB
/
eleventy.config.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import {execSync} from 'child_process';
import fs from 'node:fs';
import yaml from 'js-yaml';
import dotenv from 'dotenv';
dotenv.config();
// all translation files
const en = JSON.parse(fs.readFileSync('./translations/pages/en.json'))
const ar = JSON.parse(fs.readFileSync('./translations/pages/ar/ar.json'))
const de = JSON.parse(fs.readFileSync('./translations/pages/de/de.json'))
const el = JSON.parse(fs.readFileSync('./translations/pages/el/el.json'))
const es = JSON.parse(fs.readFileSync('./translations/pages/es/es.json'))
const fr = JSON.parse(fs.readFileSync('./translations/pages/fr/fr.json'))
const it = JSON.parse(fs.readFileSync('./translations/pages/it/it.json'))
const ja = JSON.parse(fs.readFileSync('./translations/pages/ja/ja.json'))
const ko = JSON.parse(fs.readFileSync('./translations/pages/ko/ko.json'))
const pt = JSON.parse(fs.readFileSync('./translations/pages/pt/pt.json'))
const ru = JSON.parse(fs.readFileSync('./translations/pages/ru/ru.json'))
const uk = JSON.parse(fs.readFileSync('./translations/pages/uk/uk.json'))
const zh = JSON.parse(fs.readFileSync('./translations/pages/zh/zh.json'))
// config
import {
getDocs,
allDocs
} from './config/collections/index.js';
// shprtcodes
import {svgShortcode} from './config/shortcodes/image/index.js';
import {codeHelper} from './config/shortcodes/code-helper/index.js';
import {roboWikiNote} from './config/shortcodes/robo-wiki-note/index.js';
import {roboWikiButton} from './config/shortcodes/robo-wiki-button/index.js';
import {roboWikiPicture} from './config/shortcodes/robo-wiki-picture/index.js';
import {roboWikiVideo} from './config/shortcodes/robo-wiki-video/index.js';
import {roboWikiYoutube} from './config/shortcodes/robo-wiki-youtube/index.js';
import {roboWikiTabs} from './config/shortcodes/robo-wiki-tabs/index.js';
import {roboWikiTab} from './config/shortcodes/robo-wiki-tab/index.js';
import {roboWikiTitle} from './config/shortcodes/robo-wiki-title/index.js';
import {roboWikiGridWrapper} from './config/shortcodes/robo-wiki-grid-wrapper/index.js';
import {roboWikiGrid} from './config/shortcodes/robo-wiki-grid/index.js';
import {getOGImage} from './config/shortcodes/og-image/index.js';
import {
readableDate,
htmlDateString,
getAllTags,
filterTagList,
cssMin,
slugifyString,
toAbsoluteUrl,
getCleanPath,
flatten,
flattenAll,
convertStringWithoutSpaces,
getBreadcrumbs,
getCleanTitleLinkForBreadcrumbs,
getCleanPathForBreadcrumbs,
getDocIndex,
prevPage,
nextPage,
currentPage,
transformSummaryLinks,
trimFirstHundredCharacters
} from './config/filters/index.js';
import {
getCommit,
getTitleForIssue
} from './config/filters/github/index.js';
import { htmlMinify } from './config/transformations/index.js';
import { markdownLib } from './config/libs/index.js';
import {cssConfig} from './config/css-config.js'
import {jsConfig} from './config/js-config.js'
// plugins
import embedYouTube from "eleventy-plugin-youtube-embed";
import pluginSyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight"; // code syntax highlighting
import pluginBundle from "@11ty/eleventy-plugin-bundle";
import pluginNavigation from "@11ty/eleventy-navigation"; // helps with navigation and pagination as well
import { EleventyHtmlBasePlugin, EleventyI18nPlugin, EleventyRenderPlugin } from "@11ty/eleventy"; // base plugins + localization
import pluginRss from "@11ty/eleventy-plugin-rss";
import i18n from 'eleventy-i18n'; // for translations
import pluginTOC from 'eleventy-plugin-nesting-toc'; // table of content
import pluginWebc from '@11ty/eleventy-plugin-webc'; // for webc
import metagen from 'eleventy-plugin-metagen'; // for pages metadata
export default async function(eleventyConfig) {
eleventyConfig.setServerOptions({
// Show local network IP addresses for device testing
showAllHosts: true,
});
// eleventy copy assets
eleventyConfig.addPassthroughCopy("_redirects");
// same path
['src/assets/fonts/', 'src/assets/images/', 'src/assets/og/', 'src/assets/images/og/'].forEach(
path => eleventyConfig.addPassthroughCopy(path)
);
// to root
eleventyConfig.addPassthroughCopy({
'src/assets/images/favicon/*': '/'
});
// Watch content images for the image pipeline.
eleventyConfig.addWatchTarget("src/assets/**/*.{svg,webp,png,jpeg,jpg}");
eleventyConfig.addWatchTarget('src/_components/**/*.{webc}');
// plugins
eleventyConfig.addPlugin(pluginSyntaxHighlight, {
preAttributes: { tabindex: 0 }
});
eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.addPlugin(pluginBundle);
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(embedYouTube);
eleventyConfig.addPlugin(pluginRss, {
posthtmlRenderOptions: {
closingSingleTag: "default" // opt-out of <img/>-style XHTML single tags
}
});
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(EleventyI18nPlugin, {
defaultLanguage: 'en',
filters: {
// transform a URL with the current page’s locale code
url: "locale_url",
// find the other localized content for a specific input file
links: "locale_links",
},
errorMode: "never"
});
eleventyConfig.addPlugin(i18n, {
translations: {
en, ar, de, el, es, fr, it, ja, ko, pt, ru, uk, zh
},
fallbackLanguageTag: 'en',
});
eleventyConfig.addPlugin(pluginTOC);
eleventyConfig.addPlugin(pluginWebc, {
components: ['./src/_components/**/*.webc'],
useTransform: true
});
eleventyConfig.addPlugin(metagen);
// assets
eleventyConfig.addPlugin(cssConfig);
eleventyConfig.addPlugin(jsConfig);
// layout aliases
eleventyConfig.addLayoutAlias('home', 'page-index.njk');
eleventyConfig.addLayoutAlias('docs', 'page-docs.njk');
eleventyConfig.addLayoutAlias('doc', 'page-doc.njk');
// collections
eleventyConfig.addCollection('docs', getDocs);
eleventyConfig.addCollection('allDocs', allDocs);
// transformations
eleventyConfig.addTransform("htmlmin", htmlMinify);
// Filters
eleventyConfig.addFilter("readableDate", readableDate);
eleventyConfig.addFilter('htmlDateString', htmlDateString);
eleventyConfig.addFilter("getAllTags", getAllTags);
eleventyConfig.addFilter("filterTagList", filterTagList);
eleventyConfig.addFilter("cssmin", cssMin);
// eleventyConfig.addFilter('url', relativeUrl);
eleventyConfig.addFilter('slugify', slugifyString);
eleventyConfig.addFilter('toAbsoluteUrl', toAbsoluteUrl);
eleventyConfig.addFilter('getCleanPath', getCleanPath);
eleventyConfig.addFilter('flatten', flatten);
eleventyConfig.addFilter('flattenAll', flattenAll);
eleventyConfig.addFilter('convertStringWithoutSpaces', convertStringWithoutSpaces);
eleventyConfig.addFilter('getBreadcrumbs', getBreadcrumbs);
eleventyConfig.addFilter('getCleanTitleBC', getCleanTitleLinkForBreadcrumbs);
eleventyConfig.addFilter('getCleanPathBC', getCleanPathForBreadcrumbs);
eleventyConfig.addFilter('getDocIndex', getDocIndex);
eleventyConfig.addFilter('prevPage', prevPage);
eleventyConfig.addFilter('nextPage', nextPage);
eleventyConfig.addFilter('currentPage', currentPage);
eleventyConfig.addFilter('transformSummaryLinks', transformSummaryLinks);
eleventyConfig.addFilter('trimFirstHundredCharacters', trimFirstHundredCharacters);
// filters for github data
eleventyConfig.addFilter('getTitleForIssue', getTitleForIssue);
eleventyConfig.addFilter('getCommit', getCommit);
// Customize Markdown library settings:
eleventyConfig.setLibrary('md', markdownLib);
// shortcodes
eleventyConfig.addShortcode("svg", svgShortcode);
eleventyConfig.addPairedShortcode('codeHelper', codeHelper);
eleventyConfig.addPairedShortcode('roboWikiNote', roboWikiNote);
eleventyConfig.addPairedShortcode('roboWikiButton', roboWikiButton);
eleventyConfig.addPairedShortcode('roboWikiPicture', roboWikiPicture);
eleventyConfig.addPairedShortcode('roboWikiVideo', roboWikiVideo);
eleventyConfig.addPairedShortcode('roboWikiYoutube', roboWikiYoutube);
eleventyConfig.addPairedShortcode('roboWikiTabs', roboWikiTabs);
eleventyConfig.addPairedShortcode('roboWikiTab', roboWikiTab);
eleventyConfig.addPairedShortcode('roboWikiTitle', roboWikiTitle);
eleventyConfig.addPairedShortcode('roboWikiGridWrapper', roboWikiGridWrapper);
eleventyConfig.addPairedShortcode('roboWikiGrid', roboWikiGrid);
eleventyConfig.addPairedShortcode('getOGImage', getOGImage);
// Add support for YAML data files with .yaml extension
eleventyConfig.addDataExtension('yaml', contents => yaml.load(contents));
eleventyConfig.on('eleventy.after', () => {
execSync(`npx pagefind --site dist --glob \"**/*.html\"`, { encoding: 'utf-8' })
})
return {
addPassthroughFileCopy: true,
htmlTemplateEngine: 'njk',
markdownTemplateEngine: "njk",
templateFormats: ["html", "njk", "md"],
dir: {
input: "src",
output: "dist",
includes: "_includes",
layouts: "_layouts",
},
pathPrefix: "/",
}
}