forked from axios/axios-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inert.config.js
344 lines (333 loc) · 9.05 KB
/
inert.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/**
* The inert object is provided to us by the inert compiler. It contains a whole lot of helper functions
* to do all kinds of things for us, like optimize images and compile sass or markdown
*/
const {
sass,
write,
writeFile,
copy,
imgOptimize,
htmlBuild,
singleHTMLBuild,
markdown,
halt,
} = inert;
const fs = require("fs");
const arConfig = require("./ar.lang.js");
const enConfig = require("./en.lang.js");
const deConfig = require("./de.lang.js");
const zhConfig = require("./zh.lang.js");
const ukConfig = require("./uk.lang.js");
const ptBRConfig = require("./ptBR.lang.js");
const kuConfig = require("./ku.lang.js");
const esConfig = require('./es.lang.js');
const frConfig = require("./fr.lang.js");
const trConfig = require("./tr.lang.js");
const krConfig = require("./kr.lang.js");
const viConfig = require("./vi.lang.js");
const faConfig = require("./fa.lang.js");
const ruConfig = require("./ru.lang.js");
const jaConfig = require("./ja.lang.js");
const data = fs.existsSync('./temp/data.json') ? require('./temp/data.json') : {
sponsors: []
};
// List of languages
const langs = [
{
dir: "ltr",
name: "English",
prefix: "/",
postsDir: "en", // Not required if prefix is `/<name of folder containing documentation files>/`
config: enConfig,
},
{
dir: "ltr",
name: "Brazilian Portuguese",
prefix: "/ptBR/",
config: ptBRConfig,
},
{
dir: "ltr",
name: "Deutsch",
prefix: "/de/",
config: deConfig,
},
{
dir: "ltr",
name: "中文",
prefix: "/zh/",
config: zhConfig,
},
{
dir: "ltr",
name: "Українська",
prefix: "/uk/",
config: ukConfig,
},
{
name: "کوردی",
prefix: "/ku/",
config: kuConfig,
dir: "rtl",
},
{
dir: "ltr",
name: "Español",
prefix: "/es/",
config: esConfig,
},
{
dir: "ltr",
name: "Français",
prefix: "/fr/",
config: frConfig,
},
{
dir: "ltr",
name: "Türkçe",
prefix: "/tr/",
config: trConfig,
},
{
dir: "ltr",
name: "한국어",
prefix: "/kr/",
config: krConfig,
},
{
dir: "ltr",
name: "Tiếng Việt",
prefix: "/vi/",
config: viConfig,
},
{
dir: "rtl",
name: "فارسی",
prefix: "/fa/",
config: faConfig,
},
{
dir: "ltr",
name: "Русский",
prefix: "/ru/",
config: ruConfig
},{
dir: "rtl",
name: "Arabic",
prefix: "/ar/",
postsDir: "ar",
config: arConfig,
},
{
dir: "ltr",
name: "日本語",
prefix: "/ja/",
config: jaConfig
}
];
/**
* This is the inert configuration file. It contains all the information inert needs to build this template.
*/
module.exports = {
/**
* This field contains additional configuration. The inert compiler itsself ignores this info,
* but any given part of the pipeline is free to use this data.
*/
custom: {
/**
* Site Title
*/
title: "Axios Docs",
// List of languages
langs: langs,
...data
},
build: {
/**
* A list of additional methods and objects that will be available in ejs tags inside the templates
*/
globals: [require, inert],
templates: {
home: "templates/home.ejs",
post: "templates/post.ejs",
},
sourceDirs: {
/**
* Directory containing style files. This template uses SCSS (sass) for styling.
*/
scss: "scss",
/**
* Directory containing additional static assets. These will be copied to the `assets`
* output directory and some image might be optimized
*/
assets: "assets",
/**
* Since this is a blog template, this directory will contain posts.
*/
posts: "posts",
},
/**
* Output directories. Each key can be referenced from helper methods.
*/
outDirs: {
/**
* Main output directory. MUST be named output
*/
output: "public",
/**
* Output for SASS Files. :output: will be replaced with the value of the output property.
* This also applies to all other properties of this object.
*/
sassOutput: ":output:/style",
/**
* Output for other static assets
*/
assets: ":output:/assets",
/**
* Here, we'll store optimized static assets
*/
optimizedAssets: ":assets:/optimized",
/**
* Output for internationalized files
*/
...langs.reduce(
(acc, lang) =>
lang.prefix === "/"
? acc
: {
...acc,
[lang.prefix.slice(1, -1) +
"Output"]: `:output:/${lang.prefix.slice(1, -1)}`,
},
{}
),
/**
* Output for posts
*/
postOutput: ":output:/docs",
...langs.reduce(
(acc, lang) =>
lang.prefix === "/"
? acc
: {
...acc,
[lang.prefix.slice(1, -1) + "Posts"]: `:${lang.prefix.slice(
1,
-1
)}Output:/docs`,
},
{}
),
},
rootFile: "templates/home.ejs",
/**
* Like the `filePipeline` porperty of the `folders`, but only runs once, for the root file.
*/
slashPipeline: [
/**
* Builds the given file using the EJS library.
*/
singleHTMLBuild(enConfig),
/**
* Like `write`, but writes only a single file.
*/
writeFile(":output:/index.html"),
/**
* Build for other languages
*/
halt("templates/index.ejs"), // This makes sure that the output from the previous methods isn't passed into singleHTMLBuild
...langs
.map((lang) => [
singleHTMLBuild(lang.config),
writeFile(lang.prefix === '/'
? ':output:/index.html'
: `:${lang.prefix.slice(1, -1)}Output:/index.html`
),
])
.flat(),
],
/**
* A list of objects.
*
* Each object point to a specfic folder and contains info about how to build it.
*/
folders: [
{
/**
* A key in the `sourceDirs` object which point to the path to the folder
*/
folder: "scss",
/**
* How to build the folder
*/
build: {
/**
* How to traverse the folder.
* Acceptable values: `flat` (single-level traversal) and `recursive` (also traverse subfolders)
*
* `flat` is a little faster, so If you can, you should use it.
*/
traverseLevel: "recursive", // There will be no subfolders, at least in this template
/**
* A list of methods.
*
* After the folder is traversed, the first method is called with the entire configuration as a
* first argument and the first file as the second argument, then the second function is called
* with the first method's result as an addition third argument, then the third method with the
* result from the second as third argument, and so on. This is repeated for each file.
*/
filePipeline: [
/**
* Uses the `sass` package to compile the file. Will always throw on sass compiler error.
*/
sass(),
/**
* Writes the previous method's output to a file with the same name in the specified directory.
* The `directory` option should **not** contain a path to a directory, but instead point to a
* key in the `outDirs` object, which in turn contains a path.
*/
write("sassOutput", ".css"),
],
},
},
{
folder: "assets",
build: {
traverseLevel: "recursive",
filePipeline: [
/**
* This helper method copies the file into the assets folder. Again, don't specify a path, but
* rather a key from `outDirs` object
*/
copy("assets"),
/**
* This method converts any PNG and JPEG images into optimized WebP. The old images are also kept.
* Non-PNG/JPEG assets are completely ignored.
*
* The method will also create scaled copies of the image: 460w, 720w, 1080w and 2048w, although
* widths higher than the original image width are dropped (for an image 740px wide, only 460w
* and 720w versions are generated, not 1080w and 2048w)
*
* The `ignore` options contains a list of files or globs to ignore
*/
imgOptimize("optimizedAssets", { ignore: [] }),
],
},
},
...langs.map(
(lang) => ({
folder: `posts/${lang.postsDir || lang.prefix.slice(1, -1)}`,
build: {
traverseLevel: "recursive",
filePipeline: [
markdown(),
htmlBuild("post", lang.config),
write(lang.prefix === '/' ? 'postOutput' : `${lang.prefix.slice(1, -1)}Posts`, ".html"),
],
},
})
),
],
},
};