@forsakringskassan/docs-generator 2.11.4 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -8
- package/dist/compile-example.js +3 -3
- package/dist/{create-markdown-renderer-B1v_YUfy.js → create-markdown-renderer-CYEpF6C3.js} +230 -4
- package/dist/index.d.ts +46 -8
- package/dist/index.js +350 -242
- package/dist/markdown.d.ts +2 -1
- package/dist/markdown.js +6 -4
- package/dist/runtime.js +16045 -15097
- package/dist/{vendor-WsR_tA03.js → vendor-Bb38Rlio.js} +112 -48
- package/dist/{vue3-CGUitvvB.js → vue3-BqgRpcI0.js} +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var fs = require('node:fs/promises');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var path = require('node:path/posix');
|
|
5
|
+
var vendor = require('./vendor-Bb38Rlio.js');
|
|
6
|
+
var path$1 = require('node:path');
|
|
6
7
|
var require$$1 = require('crypto');
|
|
7
|
-
var createMarkdownRenderer = require('./create-markdown-renderer-B1v_YUfy.js');
|
|
8
|
-
var node_child_process = require('node:child_process');
|
|
9
|
-
var path$1 = require('node:path/posix');
|
|
10
8
|
require('node:crypto');
|
|
9
|
+
var createMarkdownRenderer = require('./create-markdown-renderer-CYEpF6C3.js');
|
|
10
|
+
var node_child_process = require('node:child_process');
|
|
11
11
|
var util = require('node:util');
|
|
12
12
|
var vueDocgenApi = require('vue-docgen-api');
|
|
13
13
|
var fs$1 = require('node:fs');
|
|
@@ -16,13 +16,13 @@ var node_url = require('node:url');
|
|
|
16
16
|
var Module = require('node:module');
|
|
17
17
|
var esbuild$1 = require('esbuild');
|
|
18
18
|
var nunjucks = require('nunjucks');
|
|
19
|
-
var vue = require('vue');
|
|
20
|
-
var vue3 = require('./vue3-CGUitvvB.js');
|
|
21
19
|
var express = require('express');
|
|
22
20
|
require('fs');
|
|
23
21
|
require('node:events');
|
|
24
22
|
require('node:stream');
|
|
25
23
|
require('node:string_decoder');
|
|
24
|
+
require('@vue/compiler-sfc');
|
|
25
|
+
require('typescript');
|
|
26
26
|
require('constants');
|
|
27
27
|
require('stream');
|
|
28
28
|
require('util');
|
|
@@ -32,8 +32,6 @@ require('readline');
|
|
|
32
32
|
require('events');
|
|
33
33
|
require('node:process');
|
|
34
34
|
require('node:stream/promises');
|
|
35
|
-
require('@vue/compiler-sfc');
|
|
36
|
-
require('typescript');
|
|
37
35
|
require('fs/promises');
|
|
38
36
|
require('os');
|
|
39
37
|
require('http');
|
|
@@ -44,6 +42,8 @@ require('net');
|
|
|
44
42
|
require('tls');
|
|
45
43
|
require('tty');
|
|
46
44
|
require('querystring');
|
|
45
|
+
require('vue');
|
|
46
|
+
require('./vue3-BqgRpcI0.js');
|
|
47
47
|
|
|
48
48
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
49
49
|
function toArray$2(value) {
|
|
@@ -225,21 +225,6 @@ function interpolate(value, data) {
|
|
|
225
225
|
});
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
function parseImport(raw) {
|
|
229
|
-
const comments = [];
|
|
230
|
-
const stripped = raw.replace(/<!--.*?-->/gms, (match) => {
|
|
231
|
-
comments.push(match);
|
|
232
|
-
return "";
|
|
233
|
-
});
|
|
234
|
-
const filename = stripped.trim();
|
|
235
|
-
const extension = path.parse(filename).ext.slice(1);
|
|
236
|
-
return {
|
|
237
|
-
filename,
|
|
238
|
-
extension,
|
|
239
|
-
comments
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
228
|
function quote(text) {
|
|
244
229
|
return String(text).replace(/"/g, """);
|
|
245
230
|
}
|
|
@@ -277,6 +262,108 @@ function slugify(value) {
|
|
|
277
262
|
return value.toLowerCase().replace(/\//g, "--").replace(/[^a-z]+/g, "-").replace(/(^-+|-+$)/, "");
|
|
278
263
|
}
|
|
279
264
|
|
|
265
|
+
const md$2 = vendor.MarkdownIt();
|
|
266
|
+
md$2.renderer.rules.fence = (tokens, idx, _options, collected) => {
|
|
267
|
+
const { content, info } = tokens[idx];
|
|
268
|
+
const { language, tags } = createMarkdownRenderer.parseInfostring(info);
|
|
269
|
+
if (language === "import") {
|
|
270
|
+
return "";
|
|
271
|
+
}
|
|
272
|
+
collected.push({
|
|
273
|
+
content,
|
|
274
|
+
language,
|
|
275
|
+
tags
|
|
276
|
+
});
|
|
277
|
+
return "";
|
|
278
|
+
};
|
|
279
|
+
function findExamples$1(doc) {
|
|
280
|
+
if (doc.format !== "markdown") {
|
|
281
|
+
return [];
|
|
282
|
+
}
|
|
283
|
+
const collected = [];
|
|
284
|
+
md$2.render(doc.body, collected);
|
|
285
|
+
return collected;
|
|
286
|
+
}
|
|
287
|
+
function getSuffix(tags) {
|
|
288
|
+
const relevant = tags.filter((it) => ["nocompile", "nolint"].includes(it));
|
|
289
|
+
if (relevant.length > 0) {
|
|
290
|
+
return `-${relevant.join("-")}`;
|
|
291
|
+
} else {
|
|
292
|
+
return "";
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function getExtension(lang) {
|
|
296
|
+
switch (lang) {
|
|
297
|
+
case "typescript":
|
|
298
|
+
return "ts";
|
|
299
|
+
case "javascript":
|
|
300
|
+
return "js";
|
|
301
|
+
default:
|
|
302
|
+
return lang;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function extractExamplesProcessor(options) {
|
|
306
|
+
const {
|
|
307
|
+
enabled = true,
|
|
308
|
+
outputFolder,
|
|
309
|
+
languages = ["javascript", "typescript", "css", "scss"]
|
|
310
|
+
} = options;
|
|
311
|
+
function isRelevant(example) {
|
|
312
|
+
return languages.includes(example.language);
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
stage: "render",
|
|
316
|
+
name: "extract-examples-processor",
|
|
317
|
+
async handler(context) {
|
|
318
|
+
if (!enabled) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (!outputFolder) {
|
|
322
|
+
throw new Error(
|
|
323
|
+
`"outputFolder" not set in "extractExamplesProcessor(..)"`
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
await fs.rm(outputFolder, { recursive: true, force: true });
|
|
327
|
+
let total = 0;
|
|
328
|
+
for (const doc of context.docs.filter(haveOutput)) {
|
|
329
|
+
const examples = findExamples$1(doc).filter(isRelevant);
|
|
330
|
+
if (examples.length === 0) {
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const dir = createMarkdownRenderer.normalizePath(outputFolder, doc.fileInfo.fullPath);
|
|
334
|
+
await fs.mkdir(dir, { recursive: true });
|
|
335
|
+
let n = 1;
|
|
336
|
+
for (const example of examples) {
|
|
337
|
+
const suffix = getSuffix(example.tags);
|
|
338
|
+
const extension = getExtension(example.language);
|
|
339
|
+
const filename = `example-${String(n++)}${suffix}.${extension}`;
|
|
340
|
+
const filePath = path.join(dir, filename);
|
|
341
|
+
await fs.writeFile(filePath, example.content, "utf-8");
|
|
342
|
+
total++;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
context.log(total, "examples extracted");
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const md$1 = vendor.MarkdownIt();
|
|
351
|
+
md$1.renderer.rules.fence = (tokens, idx, _options, collected) => {
|
|
352
|
+
const { content, info, map } = tokens[idx];
|
|
353
|
+
const { language, tags } = createMarkdownRenderer.parseInfostring(info);
|
|
354
|
+
const hashContent = `${map?.[0]}:${map?.[1]}:${info}:${content}`;
|
|
355
|
+
const fingerprint = createMarkdownRenderer.getFingerprint(hashContent);
|
|
356
|
+
let extension = void 0;
|
|
357
|
+
if (language === "import") {
|
|
358
|
+
extension = content.split(".").at(-1)?.trim();
|
|
359
|
+
}
|
|
360
|
+
collected.push({
|
|
361
|
+
selector: `#example-${fingerprint}`,
|
|
362
|
+
language: extension ?? language,
|
|
363
|
+
tags
|
|
364
|
+
});
|
|
365
|
+
return "";
|
|
366
|
+
};
|
|
280
367
|
function flattenOutline(outline) {
|
|
281
368
|
return outline.flatMap((entry) => {
|
|
282
369
|
return [
|
|
@@ -290,36 +377,26 @@ function findExamples(doc) {
|
|
|
290
377
|
return [];
|
|
291
378
|
}
|
|
292
379
|
const collected = [];
|
|
293
|
-
|
|
294
|
-
md.renderer.rules.fence = (tokens, idx) => {
|
|
295
|
-
const { content, info, map } = tokens[idx];
|
|
296
|
-
const [language, ...tags] = info.split(/\s+/);
|
|
297
|
-
const hashContent = `${map?.[0]}:${map?.[1]}:${info}:${content}`;
|
|
298
|
-
const fingerprint = createMarkdownRenderer.getFingerprint(hashContent);
|
|
299
|
-
let extension = void 0;
|
|
300
|
-
if (language === "import") {
|
|
301
|
-
extension = content.split(".").at(-1)?.trim();
|
|
302
|
-
}
|
|
303
|
-
collected.push({
|
|
304
|
-
selector: `#example-${fingerprint}`,
|
|
305
|
-
language: extension ?? language,
|
|
306
|
-
tags
|
|
307
|
-
});
|
|
308
|
-
return "";
|
|
309
|
-
};
|
|
310
|
-
md.render(doc.body);
|
|
380
|
+
md$1.render(doc.body, collected);
|
|
311
381
|
return collected;
|
|
312
382
|
}
|
|
313
383
|
function manifestPageFromDocument(doc) {
|
|
314
|
-
const { fileInfo } = doc;
|
|
384
|
+
const { body, fileInfo, format } = doc;
|
|
315
385
|
return {
|
|
316
386
|
path: createMarkdownRenderer.getOutputFilePath("", fileInfo),
|
|
317
387
|
title: doc.attributes.title ?? doc.name ?? "",
|
|
388
|
+
redirect: format === "redirect" ? body : null,
|
|
318
389
|
outline: flattenOutline(doc.outline),
|
|
319
390
|
examples: findExamples(doc)
|
|
320
391
|
};
|
|
321
392
|
}
|
|
322
393
|
|
|
394
|
+
function line(page) {
|
|
395
|
+
if (page.redirect) {
|
|
396
|
+
return `${page.path} -> ${page.redirect}`;
|
|
397
|
+
}
|
|
398
|
+
return page.path;
|
|
399
|
+
}
|
|
323
400
|
function renderMarkdown(manifest) {
|
|
324
401
|
return [
|
|
325
402
|
"## Documentation manifest",
|
|
@@ -327,7 +404,7 @@ function renderMarkdown(manifest) {
|
|
|
327
404
|
"> Do not edit this file. It is a automatically generated by `@forsakringskassan/docs-generator`.",
|
|
328
405
|
"",
|
|
329
406
|
"```",
|
|
330
|
-
...manifest.pages.map(
|
|
407
|
+
...manifest.pages.map(line),
|
|
331
408
|
"```",
|
|
332
409
|
""
|
|
333
410
|
].join("\n");
|
|
@@ -367,7 +444,7 @@ function normalizeOptions(options) {
|
|
|
367
444
|
};
|
|
368
445
|
return { ...defaults, ...options };
|
|
369
446
|
}
|
|
370
|
-
function motdProcessor(options) {
|
|
447
|
+
function motdProcessor(options = {}) {
|
|
371
448
|
const { enabled, container, message } = normalizeOptions(options);
|
|
372
449
|
return {
|
|
373
450
|
name: "motd-processor",
|
|
@@ -433,6 +510,157 @@ function themeSelectProcessor() {
|
|
|
433
510
|
};
|
|
434
511
|
}
|
|
435
512
|
|
|
513
|
+
function dump(value) {
|
|
514
|
+
return `<pre>${JSON.stringify(value, null, 2)}</pre>`;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function json(value) {
|
|
518
|
+
return JSON.stringify(value, null, 2);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function isExternalUrl(url) {
|
|
522
|
+
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//");
|
|
523
|
+
}
|
|
524
|
+
function isAbsoluteUrl(url) {
|
|
525
|
+
return url.startsWith("/");
|
|
526
|
+
}
|
|
527
|
+
function relative(url, { fileInfo }) {
|
|
528
|
+
if (isExternalUrl(url)) {
|
|
529
|
+
return url;
|
|
530
|
+
}
|
|
531
|
+
if (isAbsoluteUrl(url)) {
|
|
532
|
+
url = `.${url}`;
|
|
533
|
+
}
|
|
534
|
+
url = createMarkdownRenderer.normalizePath(url);
|
|
535
|
+
const outputPath = createMarkdownRenderer.normalizePath(fileInfo.path);
|
|
536
|
+
if (outputPath === url || `${outputPath}/` === url) {
|
|
537
|
+
return "./";
|
|
538
|
+
}
|
|
539
|
+
const relative2 = path.relative(outputPath, url);
|
|
540
|
+
const prefix = relative2.startsWith(".") ? "" : "./";
|
|
541
|
+
const suffix = url.endsWith("/") ? "/" : "";
|
|
542
|
+
return [prefix, relative2, suffix].join("");
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
function take(haystack, key, value) {
|
|
546
|
+
return haystack.filter((it) => it[key] === value);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const template = (dst) => (
|
|
550
|
+
/* HTML */
|
|
551
|
+
`
|
|
552
|
+
<!doctype html>
|
|
553
|
+
<html lang="en">
|
|
554
|
+
<head>
|
|
555
|
+
<meta http-equiv="refresh" content="0; url=${dst}" />
|
|
556
|
+
</head>
|
|
557
|
+
<body>
|
|
558
|
+
<p>
|
|
559
|
+
This page has moved to
|
|
560
|
+
<a href="${dst}"> ${dst} </a>.
|
|
561
|
+
</p>
|
|
562
|
+
</body>
|
|
563
|
+
</html>
|
|
564
|
+
`
|
|
565
|
+
);
|
|
566
|
+
function htmlRedirectProcessor() {
|
|
567
|
+
return {
|
|
568
|
+
name: "html-redirect-processor",
|
|
569
|
+
after: "render",
|
|
570
|
+
async handler(context) {
|
|
571
|
+
const { docs, outputFolder } = context;
|
|
572
|
+
for (const doc of docs.filter(haveOutput)) {
|
|
573
|
+
if (doc.format !== "redirect") {
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
const filePath = createMarkdownRenderer.getOutputFilePath(outputFolder, doc.fileInfo);
|
|
577
|
+
const dst = relative(doc.body, doc);
|
|
578
|
+
const content = template(dst);
|
|
579
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
580
|
+
await fs.writeFile(filePath, vendor.dedent(content), "utf-8");
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function isRedirect(doc) {
|
|
587
|
+
return doc.format === "redirect";
|
|
588
|
+
}
|
|
589
|
+
function redirectFileProcessor(prefix = "/", filename = "_redirects") {
|
|
590
|
+
return {
|
|
591
|
+
name: "redirect-file-processor",
|
|
592
|
+
after: "render",
|
|
593
|
+
async handler(context) {
|
|
594
|
+
const { docs } = context;
|
|
595
|
+
const lines = docs.filter(haveOutput).filter(isRedirect).map((doc) => {
|
|
596
|
+
const src = createMarkdownRenderer.normalizePath(
|
|
597
|
+
doc.fileInfo.path,
|
|
598
|
+
doc.fileInfo.outputName
|
|
599
|
+
);
|
|
600
|
+
const dst = doc.body;
|
|
601
|
+
return `${prefix}${src} ${prefix}${dst} 301
|
|
602
|
+
`;
|
|
603
|
+
});
|
|
604
|
+
const filePath = path.join(context.outputFolder, filename);
|
|
605
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
606
|
+
await fs.writeFile(filePath, lines.join(""), "utf-8");
|
|
607
|
+
context.log(filename, "generated");
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
function getRedirects(docs) {
|
|
613
|
+
return docs.map((it) => {
|
|
614
|
+
const { fileInfo } = it;
|
|
615
|
+
const { path, outputName } = fileInfo;
|
|
616
|
+
if (outputName === false) {
|
|
617
|
+
return [];
|
|
618
|
+
}
|
|
619
|
+
return it.attributes.redirectFrom.map((jt) => {
|
|
620
|
+
return {
|
|
621
|
+
from: jt.startsWith("/") ? jt.slice(1) : jt,
|
|
622
|
+
to: createMarkdownRenderer.normalizePath(path, outputName)
|
|
623
|
+
};
|
|
624
|
+
});
|
|
625
|
+
}).flat();
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
function redirectProcessor() {
|
|
629
|
+
return {
|
|
630
|
+
name: "redirect-processor",
|
|
631
|
+
after: "generate-docs",
|
|
632
|
+
async handler(context) {
|
|
633
|
+
const redirects = getRedirects(context.docs);
|
|
634
|
+
for (const redirect of redirects) {
|
|
635
|
+
const { dir, base, name } = path.parse(redirect.from);
|
|
636
|
+
context.addDocument({
|
|
637
|
+
id: `redirect:${redirect.from}-${redirect.to}`,
|
|
638
|
+
name: `${redirect.from}-${redirect.to}`,
|
|
639
|
+
alias: [],
|
|
640
|
+
visible: false,
|
|
641
|
+
attributes: {
|
|
642
|
+
sortorder: Infinity,
|
|
643
|
+
redirectFrom: []
|
|
644
|
+
},
|
|
645
|
+
body: redirect.to,
|
|
646
|
+
outline: [],
|
|
647
|
+
format: "redirect",
|
|
648
|
+
tags: [],
|
|
649
|
+
template: "redirect",
|
|
650
|
+
fileInfo: {
|
|
651
|
+
path: dir,
|
|
652
|
+
name,
|
|
653
|
+
fullPath: "virtual:redirect",
|
|
654
|
+
outputName: base
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
const s = redirects.length === 1 ? "" : "s";
|
|
659
|
+
context.log(redirects.length, `redirect${s} found`);
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
436
664
|
function selectableVersionProcessor(pkg, container, options) {
|
|
437
665
|
const { enabled = true, message = "Det finns en nyare version" } = options ?? {};
|
|
438
666
|
return {
|
|
@@ -463,7 +691,7 @@ function selectableVersionProcessor(pkg, container, options) {
|
|
|
463
691
|
|
|
464
692
|
function generateNavigation(entries) {
|
|
465
693
|
const children = entries.map((it, index) => {
|
|
466
|
-
const key = path
|
|
694
|
+
const key = path.parse(it.path).name;
|
|
467
695
|
return {
|
|
468
696
|
key,
|
|
469
697
|
sortorder: index,
|
|
@@ -647,7 +875,7 @@ function toArray$1(value) {
|
|
|
647
875
|
return Array.isArray(value) ? value : [value];
|
|
648
876
|
}
|
|
649
877
|
function isIndexPage(parsed) {
|
|
650
|
-
const folder = path.basename(parsed.dir);
|
|
878
|
+
const folder = path$1.basename(parsed.dir);
|
|
651
879
|
if (parsed.name === folder) {
|
|
652
880
|
return true;
|
|
653
881
|
}
|
|
@@ -699,8 +927,8 @@ function getComponent(attrs) {
|
|
|
699
927
|
});
|
|
700
928
|
}
|
|
701
929
|
function parseFile$1(filePath, basePath, content) {
|
|
702
|
-
const relative = basePath ? path.relative(basePath, createMarkdownRenderer.normalizePath(filePath)) : createMarkdownRenderer.normalizePath(filePath);
|
|
703
|
-
const parsed = path.parse(relative);
|
|
930
|
+
const relative = basePath ? path$1.relative(basePath, createMarkdownRenderer.normalizePath(filePath)) : createMarkdownRenderer.normalizePath(filePath);
|
|
931
|
+
const parsed = path$1.parse(relative);
|
|
704
932
|
const blocks = vendor.fm(content);
|
|
705
933
|
const attributes = blocks.attributes;
|
|
706
934
|
const isIndex = isIndexPage(parsed);
|
|
@@ -721,6 +949,7 @@ function parseFile$1(filePath, basePath, content) {
|
|
|
721
949
|
status: attributes.status,
|
|
722
950
|
badge: getBadge(attributes),
|
|
723
951
|
component: getComponent(attributes),
|
|
952
|
+
redirectFrom: toArray$1(attributes.redirect_from ?? []),
|
|
724
953
|
sortorder: attributes.sortorder ?? Infinity
|
|
725
954
|
},
|
|
726
955
|
body: blocks.body,
|
|
@@ -879,7 +1108,7 @@ function parseAPIToArray(api) {
|
|
|
879
1108
|
}
|
|
880
1109
|
function parseAPI(filePath, api) {
|
|
881
1110
|
const relative = createMarkdownRenderer.normalizePath(filePath);
|
|
882
|
-
const parsedPath = path.parse(relative);
|
|
1111
|
+
const parsedPath = path$1.parse(relative);
|
|
883
1112
|
const componentName = parsedPath.name;
|
|
884
1113
|
let html = "";
|
|
885
1114
|
if (api.props.length) {
|
|
@@ -899,7 +1128,7 @@ function parseAPI(filePath, api) {
|
|
|
899
1128
|
name: `vue:${componentName}`,
|
|
900
1129
|
alias: [],
|
|
901
1130
|
visible: false,
|
|
902
|
-
attributes: { sortorder: Infinity },
|
|
1131
|
+
attributes: { sortorder: Infinity, redirectFrom: [] },
|
|
903
1132
|
body: html,
|
|
904
1133
|
outline: [],
|
|
905
1134
|
format: "html",
|
|
@@ -926,7 +1155,9 @@ async function globAll(pattern) {
|
|
|
926
1155
|
if (!Array.isArray(pattern)) {
|
|
927
1156
|
return globAll([pattern]);
|
|
928
1157
|
}
|
|
929
|
-
const results = await Promise.all(
|
|
1158
|
+
const results = await Promise.all(
|
|
1159
|
+
pattern.map((it) => vendor.glob(it, { nodir: true }))
|
|
1160
|
+
);
|
|
930
1161
|
return new Set(results.flat());
|
|
931
1162
|
}
|
|
932
1163
|
async function getDocumentsForSource(src) {
|
|
@@ -967,8 +1198,8 @@ function parseFile(filePath, basePath, content) {
|
|
|
967
1198
|
if (!title) {
|
|
968
1199
|
throw new Error(`No title property set in "${filePath}"`);
|
|
969
1200
|
}
|
|
970
|
-
const relative = basePath ? path.relative(basePath, createMarkdownRenderer.normalizePath(filePath)) : createMarkdownRenderer.normalizePath(filePath);
|
|
971
|
-
const parsed = path.parse(relative);
|
|
1201
|
+
const relative = basePath ? path$1.relative(basePath, createMarkdownRenderer.normalizePath(filePath)) : createMarkdownRenderer.normalizePath(filePath);
|
|
1202
|
+
const parsed = path$1.parse(relative);
|
|
972
1203
|
const filename = parsed.name.toLowerCase();
|
|
973
1204
|
const name = parsed.name;
|
|
974
1205
|
const urlpath = parsed.dir;
|
|
@@ -980,7 +1211,8 @@ function parseFile(filePath, basePath, content) {
|
|
|
980
1211
|
attributes: {
|
|
981
1212
|
title,
|
|
982
1213
|
href,
|
|
983
|
-
sortorder: attributes.sortorder ?? Infinity
|
|
1214
|
+
sortorder: attributes.sortorder ?? Infinity,
|
|
1215
|
+
redirectFrom: []
|
|
984
1216
|
},
|
|
985
1217
|
body: content,
|
|
986
1218
|
outline: [],
|
|
@@ -1002,7 +1234,7 @@ async function navigationFileReader(filePath, basePath) {
|
|
|
1002
1234
|
}
|
|
1003
1235
|
|
|
1004
1236
|
function resolveFrom(fromDirectory, moduleId) {
|
|
1005
|
-
const fromFile = path.join(fs$1.realpathSync(fromDirectory), "noop.js");
|
|
1237
|
+
const fromFile = path$1.join(fs$1.realpathSync(fromDirectory), "noop.js");
|
|
1006
1238
|
return Module._resolveFilename(moduleId, {
|
|
1007
1239
|
id: fromFile,
|
|
1008
1240
|
filename: fromFile,
|
|
@@ -1018,8 +1250,8 @@ function moduleImporter(options) {
|
|
|
1018
1250
|
if (url.startsWith(WEBPACK_NODE_MODULE_PREFIX)) {
|
|
1019
1251
|
findUrl = url.substring(1);
|
|
1020
1252
|
}
|
|
1021
|
-
const directory = path.dirname(findUrl);
|
|
1022
|
-
const fileName = path.basename(findUrl);
|
|
1253
|
+
const directory = path$1.dirname(findUrl);
|
|
1254
|
+
const fileName = path$1.basename(findUrl);
|
|
1023
1255
|
const search = [
|
|
1024
1256
|
`${fileName}.css`,
|
|
1025
1257
|
`${fileName}.scss`,
|
|
@@ -1028,7 +1260,7 @@ function moduleImporter(options) {
|
|
|
1028
1260
|
];
|
|
1029
1261
|
for (const variant of search) {
|
|
1030
1262
|
try {
|
|
1031
|
-
const moduleName = path.posix.join(directory, variant);
|
|
1263
|
+
const moduleName = path$1.posix.join(directory, variant);
|
|
1032
1264
|
const resolved = resolveFrom(cwd, moduleName);
|
|
1033
1265
|
return new URL(node_url.pathToFileURL(resolved));
|
|
1034
1266
|
} catch (err) {
|
|
@@ -1048,21 +1280,21 @@ async function compileSassString(dst, style, options = {}) {
|
|
|
1048
1280
|
style: "expanded",
|
|
1049
1281
|
importers: [new sass.NodePackageImporter(), moduleImporter({ cwd })]
|
|
1050
1282
|
});
|
|
1051
|
-
await fs.mkdir(path.dirname(dst), { recursive: true });
|
|
1283
|
+
await fs.mkdir(path$1.dirname(dst), { recursive: true });
|
|
1052
1284
|
await fs.writeFile(dst, result.css, "utf-8");
|
|
1053
1285
|
}
|
|
1054
1286
|
|
|
1055
1287
|
async function compileStyle(assetFolder, name, src, options) {
|
|
1056
1288
|
const { cwd } = options;
|
|
1057
1289
|
try {
|
|
1058
|
-
const outfile = path
|
|
1290
|
+
const outfile = path.join("temp", `asset-${name}.css`);
|
|
1059
1291
|
const source = await fs.readFile(src, "utf-8");
|
|
1060
1292
|
await compileSassString(outfile, source, { cwd });
|
|
1061
1293
|
const content = await fs.readFile(outfile, "utf-8");
|
|
1062
1294
|
const fingerprint = createMarkdownRenderer.getFingerprint(content);
|
|
1063
1295
|
const integrity = getIntegrity(content);
|
|
1064
1296
|
const filename = `${name}-${fingerprint}.css`;
|
|
1065
|
-
const dst = path
|
|
1297
|
+
const dst = path.join(assetFolder, filename);
|
|
1066
1298
|
await fs.rename(outfile, dst);
|
|
1067
1299
|
const stat = await fs.stat(dst);
|
|
1068
1300
|
return {
|
|
@@ -1138,7 +1370,7 @@ async function compileScript(options) {
|
|
|
1138
1370
|
const iconLib = process.env.DOCS_ICON_LIB ?? "@fkui/icon-lib-default";
|
|
1139
1371
|
try {
|
|
1140
1372
|
const entryPoints = [src instanceof URL ? node_url.fileURLToPath(src) : src];
|
|
1141
|
-
const outfile = path.join("temp", `asset-${name}.js`);
|
|
1373
|
+
const outfile = path$1.join("temp", `asset-${name}.js`);
|
|
1142
1374
|
await esbuild({
|
|
1143
1375
|
entryPoints,
|
|
1144
1376
|
outfile,
|
|
@@ -1146,7 +1378,7 @@ async function compileScript(options) {
|
|
|
1146
1378
|
format: "iife",
|
|
1147
1379
|
platform: "browser",
|
|
1148
1380
|
external: ["vue", "@fkui/vue"],
|
|
1149
|
-
tsconfig: path.join(__dirname, "../tsconfig-examples.json"),
|
|
1381
|
+
tsconfig: path$1.join(__dirname, "../tsconfig-examples.json"),
|
|
1150
1382
|
...buildOptions,
|
|
1151
1383
|
define: {
|
|
1152
1384
|
"process.env.DOCS_ICON_LIB": JSON.stringify(iconLib),
|
|
@@ -1157,8 +1389,8 @@ async function compileScript(options) {
|
|
|
1157
1389
|
const fingerprint = createMarkdownRenderer.getFingerprint(content);
|
|
1158
1390
|
const integrity = getIntegrity(content);
|
|
1159
1391
|
const filename = `${name}-${fingerprint}.js`;
|
|
1160
|
-
const dst = path.join(assetFolder, filename);
|
|
1161
|
-
await fs$1.mkdir(path.dirname(dst), { recursive: true });
|
|
1392
|
+
const dst = path$1.join(assetFolder, filename);
|
|
1393
|
+
await fs$1.mkdir(path$1.dirname(dst), { recursive: true });
|
|
1162
1394
|
await fs$1.rename(outfile, dst);
|
|
1163
1395
|
const stat = await fs$1.stat(dst);
|
|
1164
1396
|
return {
|
|
@@ -1224,7 +1456,7 @@ function staticResourcesProcessor(assetFolder, resources) {
|
|
|
1224
1456
|
async handler(context) {
|
|
1225
1457
|
for (const resource of [...resources, ...context.resources]) {
|
|
1226
1458
|
const src = resource.from;
|
|
1227
|
-
const dst = path
|
|
1459
|
+
const dst = path.join(assetFolder, resource.to);
|
|
1228
1460
|
await fs.cp(src, dst, {
|
|
1229
1461
|
recursive: true
|
|
1230
1462
|
});
|
|
@@ -1250,7 +1482,7 @@ function compileProcessorRuntime(generator, distDir, processors) {
|
|
|
1250
1482
|
const assetName = [
|
|
1251
1483
|
"processors",
|
|
1252
1484
|
processor.name.replace(/-processor/, ""),
|
|
1253
|
-
entry.name ?? path.parse(entry.src).name
|
|
1485
|
+
entry.name ?? path$1.parse(entry.src).name
|
|
1254
1486
|
].join("/");
|
|
1255
1487
|
const name = processorRuntimeName(processor, entry);
|
|
1256
1488
|
const bundled = new URL(`${name}.js`, distDir);
|
|
@@ -1270,110 +1502,6 @@ function compileProcessorRuntime(generator, distDir, processors) {
|
|
|
1270
1502
|
}
|
|
1271
1503
|
}
|
|
1272
1504
|
|
|
1273
|
-
function getExampleImport(searchDirs, filename) {
|
|
1274
|
-
const pattern = searchDirs.map((dir) => `${dir}/**/${filename}`);
|
|
1275
|
-
const matches = vendor.globSync(pattern);
|
|
1276
|
-
if (matches.length === 0) {
|
|
1277
|
-
const message = `No files matched import "${filename}"`;
|
|
1278
|
-
throw new Error(message);
|
|
1279
|
-
} else if (matches.length > 1) {
|
|
1280
|
-
const message = `Multiple files matched import "${filename}"`;
|
|
1281
|
-
throw new Error(message);
|
|
1282
|
-
} else {
|
|
1283
|
-
return createMarkdownRenderer.normalizePath(matches[0]);
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
function getExampleName(filename) {
|
|
1288
|
-
return path.parse(filename).name;
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
const vueMajor = parseInt(vue.version.split(".", 2)[0], 10);
|
|
1292
|
-
function vueGenerator() {
|
|
1293
|
-
switch (vueMajor) {
|
|
1294
|
-
case 2:
|
|
1295
|
-
throw new Error(
|
|
1296
|
-
"Vue 2 is no longer supported, upgrade to Vue 3 or downgrade docs-generator"
|
|
1297
|
-
);
|
|
1298
|
-
case 3:
|
|
1299
|
-
return vue3.generateCode;
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
function generateExample(options) {
|
|
1303
|
-
const { language } = options;
|
|
1304
|
-
if (language === "import") {
|
|
1305
|
-
const parsed = parseImport(options.source);
|
|
1306
|
-
const filename = getExampleImport(
|
|
1307
|
-
options.exampleFolders,
|
|
1308
|
-
parsed.filename
|
|
1309
|
-
);
|
|
1310
|
-
const source = fs$1.readFileSync(filename, "utf-8");
|
|
1311
|
-
const language2 = parsed.extension;
|
|
1312
|
-
const comments = parsed.comments;
|
|
1313
|
-
const example = generateExample({
|
|
1314
|
-
...options,
|
|
1315
|
-
source,
|
|
1316
|
-
language: language2,
|
|
1317
|
-
filename
|
|
1318
|
-
});
|
|
1319
|
-
return { ...example, comments };
|
|
1320
|
-
}
|
|
1321
|
-
switch (language) {
|
|
1322
|
-
case "vue":
|
|
1323
|
-
return generateVueExample(options);
|
|
1324
|
-
case "html":
|
|
1325
|
-
return generateStaticExample(options);
|
|
1326
|
-
default:
|
|
1327
|
-
return generateStaticExample(options);
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
function generateVueExample(options) {
|
|
1331
|
-
const { filename, source, parent, setupPath, tags } = options;
|
|
1332
|
-
const fn = vueGenerator();
|
|
1333
|
-
const slug = getExampleName(filename);
|
|
1334
|
-
const fingerprint = createMarkdownRenderer.getFingerprint(source);
|
|
1335
|
-
const { markup, sourcecode, output } = fn({
|
|
1336
|
-
filename,
|
|
1337
|
-
slug,
|
|
1338
|
-
fingerprint,
|
|
1339
|
-
code: source,
|
|
1340
|
-
setupPath
|
|
1341
|
-
});
|
|
1342
|
-
return {
|
|
1343
|
-
source,
|
|
1344
|
-
language: options.language,
|
|
1345
|
-
comments: [],
|
|
1346
|
-
tags,
|
|
1347
|
-
markup,
|
|
1348
|
-
output,
|
|
1349
|
-
runtime: true,
|
|
1350
|
-
task: {
|
|
1351
|
-
outputFile: output,
|
|
1352
|
-
sourcecode,
|
|
1353
|
-
sourceFile: filename,
|
|
1354
|
-
parent
|
|
1355
|
-
}
|
|
1356
|
-
};
|
|
1357
|
-
}
|
|
1358
|
-
function generateStaticExample(options) {
|
|
1359
|
-
const { filename, source, language, tags } = options;
|
|
1360
|
-
const slug = getExampleName(filename);
|
|
1361
|
-
const fingerprint = createMarkdownRenderer.getFingerprint(source);
|
|
1362
|
-
const asset = `${slug}-${fingerprint}.${language}`;
|
|
1363
|
-
const runtimeLanguages = ["html"];
|
|
1364
|
-
const runtime = runtimeLanguages.includes(language);
|
|
1365
|
-
return {
|
|
1366
|
-
source,
|
|
1367
|
-
language: options.language,
|
|
1368
|
-
comments: [],
|
|
1369
|
-
tags,
|
|
1370
|
-
markup: source,
|
|
1371
|
-
output: runtime ? asset : null,
|
|
1372
|
-
runtime,
|
|
1373
|
-
task: null
|
|
1374
|
-
};
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
1505
|
function isNavigationSection(node) {
|
|
1378
1506
|
return "key" in node;
|
|
1379
1507
|
}
|
|
@@ -1382,7 +1510,7 @@ function pathFromDoc({ fileInfo }) {
|
|
|
1382
1510
|
return [fileInfo.path.replace(/\\/g, "/"), true];
|
|
1383
1511
|
} else {
|
|
1384
1512
|
return [
|
|
1385
|
-
`./${path.join(fileInfo.path, fileInfo.name).replace(/\\/g, "/")}`,
|
|
1513
|
+
`./${path$1.join(fileInfo.path, fileInfo.name).replace(/\\/g, "/")}`,
|
|
1386
1514
|
false
|
|
1387
1515
|
];
|
|
1388
1516
|
}
|
|
@@ -1451,6 +1579,9 @@ function generateNavtree(docs) {
|
|
|
1451
1579
|
return parent;
|
|
1452
1580
|
}
|
|
1453
1581
|
for (const doc of docs) {
|
|
1582
|
+
if (doc.format === "redirect") {
|
|
1583
|
+
continue;
|
|
1584
|
+
}
|
|
1454
1585
|
const [name, isSection] = pathFromDoc(doc);
|
|
1455
1586
|
const title = doc.attributes.shortTitle ?? doc.attributes.title ?? doc.fileInfo.name;
|
|
1456
1587
|
const sortorder = doc.attributes.sortorder;
|
|
@@ -1577,7 +1708,7 @@ class TemplateLoader {
|
|
|
1577
1708
|
folders;
|
|
1578
1709
|
templateCache;
|
|
1579
1710
|
constructor(folders = []) {
|
|
1580
|
-
this.folders = [...folders, path.join(__dirname, "../templates")];
|
|
1711
|
+
this.folders = [...folders, path$1.join(__dirname, "../templates")];
|
|
1581
1712
|
this.templateCache = /* @__PURE__ */ new Map();
|
|
1582
1713
|
}
|
|
1583
1714
|
async getSource(name, callback) {
|
|
@@ -1628,47 +1759,11 @@ Make sure the name is correct and the template file exists in one of the listed
|
|
|
1628
1759
|
}
|
|
1629
1760
|
findTemplateFile(name) {
|
|
1630
1761
|
const { folders } = this;
|
|
1631
|
-
const searchPaths = folders.map((it) => path.join(it, name));
|
|
1762
|
+
const searchPaths = folders.map((it) => path$1.join(it, name));
|
|
1632
1763
|
return searchPaths.find((it) => fs$1.existsSync(it));
|
|
1633
1764
|
}
|
|
1634
1765
|
}
|
|
1635
1766
|
|
|
1636
|
-
function dump(value) {
|
|
1637
|
-
return `<pre>${JSON.stringify(value, null, 2)}</pre>`;
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
|
-
function json(value) {
|
|
1641
|
-
return JSON.stringify(value, null, 2);
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
function isExternalUrl(url) {
|
|
1645
|
-
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//");
|
|
1646
|
-
}
|
|
1647
|
-
function isAbsoluteUrl(url) {
|
|
1648
|
-
return url.startsWith("/");
|
|
1649
|
-
}
|
|
1650
|
-
function relative(url, { fileInfo }) {
|
|
1651
|
-
if (isExternalUrl(url)) {
|
|
1652
|
-
return url;
|
|
1653
|
-
}
|
|
1654
|
-
if (isAbsoluteUrl(url)) {
|
|
1655
|
-
url = `.${url}`;
|
|
1656
|
-
}
|
|
1657
|
-
url = createMarkdownRenderer.normalizePath(url);
|
|
1658
|
-
const outputPath = createMarkdownRenderer.normalizePath(fileInfo.path);
|
|
1659
|
-
if (outputPath === url || `${outputPath}/` === url) {
|
|
1660
|
-
return "./";
|
|
1661
|
-
}
|
|
1662
|
-
const relative2 = path$1.relative(outputPath, url);
|
|
1663
|
-
const prefix = relative2.startsWith(".") ? "" : "./";
|
|
1664
|
-
const suffix = url.endsWith("/") ? "/" : "";
|
|
1665
|
-
return [prefix, relative2, suffix].join("");
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
function take(haystack, key, value) {
|
|
1669
|
-
return haystack.filter((it) => it[key] === value);
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
1767
|
class MissingTemplateError extends Error {
|
|
1673
1768
|
searchDir;
|
|
1674
1769
|
constructor(fileInfo, template, format, searchDir) {
|
|
@@ -1686,7 +1781,7 @@ class MissingTemplateError extends Error {
|
|
|
1686
1781
|
].join("\n");
|
|
1687
1782
|
}
|
|
1688
1783
|
}
|
|
1689
|
-
const templateDirectory = path.join(__dirname, "../templates");
|
|
1784
|
+
const templateDirectory = path$1.join(__dirname, "../templates");
|
|
1690
1785
|
const cache$1 = /* @__PURE__ */ new Map();
|
|
1691
1786
|
function cacheKey(layout, extension) {
|
|
1692
1787
|
return [layout, extension].join("|");
|
|
@@ -1708,7 +1803,7 @@ function findTemplate(folders, from, src, format) {
|
|
|
1708
1803
|
folders = [...folders, templateDirectory];
|
|
1709
1804
|
const template = `${layout}.template.${format}`;
|
|
1710
1805
|
const searchPaths = folders.map((it) => {
|
|
1711
|
-
return path.join(it, template);
|
|
1806
|
+
return path$1.join(it, template);
|
|
1712
1807
|
});
|
|
1713
1808
|
const found = searchPaths.find((it) => fs$1.existsSync(it));
|
|
1714
1809
|
if (!found) {
|
|
@@ -1718,7 +1813,7 @@ function findTemplate(folders, from, src, format) {
|
|
|
1718
1813
|
return template;
|
|
1719
1814
|
}
|
|
1720
1815
|
|
|
1721
|
-
const scriptPath = path.join(__dirname, "compile-example.js");
|
|
1816
|
+
const scriptPath = path$1.join(__dirname, "compile-example.js");
|
|
1722
1817
|
let loader = null;
|
|
1723
1818
|
function haveOutputFile(fileInfo) {
|
|
1724
1819
|
return fileInfo.outputName !== false;
|
|
@@ -1752,8 +1847,8 @@ function findSidenav(doc, tree) {
|
|
|
1752
1847
|
}
|
|
1753
1848
|
function cache(cacheFolder, outputFolder) {
|
|
1754
1849
|
return (it) => {
|
|
1755
|
-
const cacheFile = path.join(cacheFolder, it.outputFile);
|
|
1756
|
-
const outputFile = path.join(outputFolder, it.outputFile);
|
|
1850
|
+
const cacheFile = path$1.join(cacheFolder, it.outputFile);
|
|
1851
|
+
const outputFile = path$1.join(outputFolder, it.outputFile);
|
|
1757
1852
|
if (fs$1.existsSync(cacheFile)) {
|
|
1758
1853
|
fs$1.copyFileSync(cacheFile, outputFile);
|
|
1759
1854
|
return false;
|
|
@@ -1767,8 +1862,8 @@ async function compileExamples(options) {
|
|
|
1767
1862
|
if (tasks.length === 0) {
|
|
1768
1863
|
return;
|
|
1769
1864
|
}
|
|
1770
|
-
const cacheFolder = path.posix.join(options.cacheFolder, fileInfo.path);
|
|
1771
|
-
const outputFolder = path.posix.join(options.outputFolder, fileInfo.path);
|
|
1865
|
+
const cacheFolder = path$1.posix.join(options.cacheFolder, fileInfo.path);
|
|
1866
|
+
const outputFolder = path$1.posix.join(options.outputFolder, fileInfo.path);
|
|
1772
1867
|
const cacheMiss = cache(cacheFolder, outputFolder);
|
|
1773
1868
|
const dirtyTasks = tasks.filter(cacheMiss);
|
|
1774
1869
|
if (dirtyTasks.length === 0) {
|
|
@@ -1791,8 +1886,8 @@ async function compileStandalones(options) {
|
|
|
1791
1886
|
if (tasks.length === 0) {
|
|
1792
1887
|
return;
|
|
1793
1888
|
}
|
|
1794
|
-
const cacheFolder = path.posix.join(options.cacheFolder, fileInfo.path);
|
|
1795
|
-
const outputFolder = path.posix.join(options.outputFolder, fileInfo.path);
|
|
1889
|
+
const cacheFolder = path$1.posix.join(options.cacheFolder, fileInfo.path);
|
|
1890
|
+
const outputFolder = path$1.posix.join(options.outputFolder, fileInfo.path);
|
|
1796
1891
|
const cacheMiss = cache(cacheFolder, outputFolder);
|
|
1797
1892
|
const dirtyTasks = tasks.filter(cacheMiss);
|
|
1798
1893
|
const standaloneTemplate = findTemplate(
|
|
@@ -1801,7 +1896,7 @@ async function compileStandalones(options) {
|
|
|
1801
1896
|
"example"
|
|
1802
1897
|
);
|
|
1803
1898
|
for (const task of dirtyTasks) {
|
|
1804
|
-
const outputFile = path.join(outputFolder, task.outputFile);
|
|
1899
|
+
const outputFile = path$1.join(outputFolder, task.outputFile);
|
|
1805
1900
|
const content = await renderTemplate(standaloneTemplate, {
|
|
1806
1901
|
...templateData,
|
|
1807
1902
|
content: task.content
|
|
@@ -1820,7 +1915,7 @@ async function render(doc, docs, nav, vendors, options) {
|
|
|
1820
1915
|
return null;
|
|
1821
1916
|
}
|
|
1822
1917
|
const dst = createMarkdownRenderer.getOutputFilePath(outputFolder, fileInfo);
|
|
1823
|
-
const mkdir = fs.mkdir(path.dirname(dst), { recursive: true });
|
|
1918
|
+
const mkdir = fs.mkdir(path$1.dirname(dst), { recursive: true });
|
|
1824
1919
|
const topnav = nav.topnav;
|
|
1825
1920
|
const sidenav = findSidenav(doc, nav.sidenav);
|
|
1826
1921
|
if (sidenav && isNavigationSection(sidenav)) {
|
|
@@ -1837,7 +1932,7 @@ async function render(doc, docs, nav, vendors, options) {
|
|
|
1837
1932
|
topnav,
|
|
1838
1933
|
rootUrl(doc2) {
|
|
1839
1934
|
const { fileInfo: fileInfo2 } = doc2;
|
|
1840
|
-
const relative = path
|
|
1935
|
+
const relative = path.relative(fileInfo2.path, ".");
|
|
1841
1936
|
return relative !== "" ? relative : ".";
|
|
1842
1937
|
},
|
|
1843
1938
|
sidenav,
|
|
@@ -1848,7 +1943,7 @@ async function render(doc, docs, nav, vendors, options) {
|
|
|
1848
1943
|
const markdownRenderer = createMarkdownRenderer.createMarkdownRenderer({
|
|
1849
1944
|
docs,
|
|
1850
1945
|
generateExample({ source, language, filename, tags }) {
|
|
1851
|
-
const example = generateExample({
|
|
1946
|
+
const example = createMarkdownRenderer.generateExample({
|
|
1852
1947
|
source,
|
|
1853
1948
|
language,
|
|
1854
1949
|
filename,
|
|
@@ -1858,12 +1953,12 @@ async function render(doc, docs, nav, vendors, options) {
|
|
|
1858
1953
|
tags
|
|
1859
1954
|
});
|
|
1860
1955
|
if (example.output) {
|
|
1861
|
-
const { dir, name } = path.parse(example.output);
|
|
1956
|
+
const { dir, name } = path$1.parse(example.output);
|
|
1862
1957
|
if (example.task) {
|
|
1863
1958
|
generatedExamples.push(example.task);
|
|
1864
1959
|
}
|
|
1865
1960
|
generatedStandalone.push({
|
|
1866
|
-
outputFile: path.join(dir, `${name}.html`),
|
|
1961
|
+
outputFile: path$1.join(dir, `${name}.html`),
|
|
1867
1962
|
content: example.markup
|
|
1868
1963
|
});
|
|
1869
1964
|
}
|
|
@@ -1990,7 +2085,11 @@ function nunjucksProcessor(options) {
|
|
|
1990
2085
|
}
|
|
1991
2086
|
});
|
|
1992
2087
|
}
|
|
2088
|
+
const formats = ["markdown", "json"];
|
|
1993
2089
|
const docs = context.docs.filter((it) => {
|
|
2090
|
+
if (!formats.includes(it.format)) {
|
|
2091
|
+
return false;
|
|
2092
|
+
}
|
|
1994
2093
|
return it.fileInfo.outputName;
|
|
1995
2094
|
});
|
|
1996
2095
|
progressbar.start(docs.length, 0, {
|
|
@@ -1998,7 +2097,7 @@ function nunjucksProcessor(options) {
|
|
|
1998
2097
|
});
|
|
1999
2098
|
const generatedFiles = [];
|
|
2000
2099
|
try {
|
|
2001
|
-
for (const doc of
|
|
2100
|
+
for (const doc of docs) {
|
|
2002
2101
|
const filePath = await renderDocument(doc);
|
|
2003
2102
|
if (filePath) {
|
|
2004
2103
|
generatedFiles.push(filePath);
|
|
@@ -2059,12 +2158,12 @@ function getAssetSource(asset, require) {
|
|
|
2059
2158
|
return lines.join("\n");
|
|
2060
2159
|
}
|
|
2061
2160
|
async function compileVendor(assetFolder, vendor, options) {
|
|
2062
|
-
const name = path.isAbsolute(vendor.package) ? path.basename(vendor.package) : vendor.package;
|
|
2161
|
+
const name = path$1.isAbsolute(vendor.package) ? path$1.basename(vendor.package) : vendor.package;
|
|
2063
2162
|
const slug = slugify(name);
|
|
2064
2163
|
const outfile = `temp/vendor-${slug}.out.js`;
|
|
2065
2164
|
const tmpfile = `temp/vendor-${slug}.in.js`;
|
|
2066
2165
|
const source = getAssetSource(vendor, customRequire.toString());
|
|
2067
|
-
const tsconfig = path.resolve(__dirname, "../tsconfig-examples.json");
|
|
2166
|
+
const tsconfig = path$1.resolve(__dirname, "../tsconfig-examples.json");
|
|
2068
2167
|
await fs.writeFile(tmpfile, source, "utf-8");
|
|
2069
2168
|
await esbuild$1.build({
|
|
2070
2169
|
entryPoints: [tmpfile],
|
|
@@ -2086,7 +2185,7 @@ async function compileVendor(assetFolder, vendor, options) {
|
|
|
2086
2185
|
const fingerprint = createMarkdownRenderer.getFingerprint(content);
|
|
2087
2186
|
const integrity = getIntegrity(content);
|
|
2088
2187
|
const filename = `vendor-${slug}-${fingerprint}.js`;
|
|
2089
|
-
const dst = path.join(assetFolder, filename).replace(/\\/g, "/");
|
|
2188
|
+
const dst = path$1.join(assetFolder, filename).replace(/\\/g, "/");
|
|
2090
2189
|
await fs.rename(outfile, dst);
|
|
2091
2190
|
const stat = await fs.stat(dst);
|
|
2092
2191
|
return {
|
|
@@ -2139,7 +2238,7 @@ function vendorProcessor(assetFolder, vendor) {
|
|
|
2139
2238
|
const assets = await generateVendorAssets(assetFolder, vendor);
|
|
2140
2239
|
context.addVendorAsset(assets);
|
|
2141
2240
|
for (const asset of assets) {
|
|
2142
|
-
const filename = path
|
|
2241
|
+
const filename = path.basename(asset.publicPath);
|
|
2143
2242
|
context.log(filename, formatSize(asset.size));
|
|
2144
2243
|
}
|
|
2145
2244
|
}
|
|
@@ -2219,7 +2318,7 @@ async function serve(options) {
|
|
|
2219
2318
|
const watcher = vendor.watch(options.watch);
|
|
2220
2319
|
const rebuild = createRebuilder(options.rebuild, (filePath) => {
|
|
2221
2320
|
const files = filePath.map((it) => {
|
|
2222
|
-
return path
|
|
2321
|
+
return path.relative(options.outputFolder, it);
|
|
2223
2322
|
});
|
|
2224
2323
|
livereload.changed({ body: { files } });
|
|
2225
2324
|
});
|
|
@@ -2296,7 +2395,7 @@ async function stage(stage2, context, processors, { verbose } = { verbose: true
|
|
|
2296
2395
|
}
|
|
2297
2396
|
return generatedFiles;
|
|
2298
2397
|
}
|
|
2299
|
-
function createContext(templateLoader) {
|
|
2398
|
+
function createContext(outputFolder, templateLoader) {
|
|
2300
2399
|
let docs = [];
|
|
2301
2400
|
let vendors = [];
|
|
2302
2401
|
const resources = [];
|
|
@@ -2334,6 +2433,7 @@ function createContext(templateLoader) {
|
|
|
2334
2433
|
get sidenav() {
|
|
2335
2434
|
return sidenav;
|
|
2336
2435
|
},
|
|
2436
|
+
outputFolder,
|
|
2337
2437
|
addDocument(document) {
|
|
2338
2438
|
docs = [...docs, ...toArray(document)];
|
|
2339
2439
|
},
|
|
@@ -2397,10 +2497,10 @@ class Generator {
|
|
|
2397
2497
|
throw new Error("site metadata not set in configuration");
|
|
2398
2498
|
}
|
|
2399
2499
|
this.site = options.site;
|
|
2400
|
-
this.outputFolder = options.outputFolder;
|
|
2401
|
-
this.cacheFolder = options.cacheFolder;
|
|
2402
|
-
this.assetFolder = path.posix.join(
|
|
2403
|
-
this.exampleFolders = options.exampleFolders;
|
|
2500
|
+
this.outputFolder = options.outputFolder ?? "./public";
|
|
2501
|
+
this.cacheFolder = options.cacheFolder ?? "./temp/docs";
|
|
2502
|
+
this.assetFolder = path$1.posix.join(this.outputFolder, "assets");
|
|
2503
|
+
this.exampleFolders = options.exampleFolders ?? [];
|
|
2404
2504
|
this.templateFolders = options.templateFolders ?? [];
|
|
2405
2505
|
this.processors = options.processors ?? [];
|
|
2406
2506
|
this.vendor = options.vendor ?? [];
|
|
@@ -2464,10 +2564,11 @@ class Generator {
|
|
|
2464
2564
|
async manifest(sourceFiles) {
|
|
2465
2565
|
const processors = [
|
|
2466
2566
|
fileReaderProcessor(sourceFiles),
|
|
2567
|
+
redirectProcessor(),
|
|
2467
2568
|
...this.processors
|
|
2468
2569
|
];
|
|
2469
2570
|
const templateLoader = createTemplateLoader([]);
|
|
2470
|
-
const context = createContext(templateLoader);
|
|
2571
|
+
const context = createContext("", templateLoader);
|
|
2471
2572
|
await stage("generate-docs", context, processors, { verbose: false });
|
|
2472
2573
|
const docs = context.docs.filter(haveOutput);
|
|
2473
2574
|
const pages = docs.map(manifestPageFromDocument);
|
|
@@ -2488,6 +2589,7 @@ class Generator {
|
|
|
2488
2589
|
await this._prepareFolders();
|
|
2489
2590
|
const processors = [
|
|
2490
2591
|
fileReaderProcessor(sourceFiles),
|
|
2592
|
+
redirectProcessor(),
|
|
2491
2593
|
vendorProcessor(assetFolder, this.vendor),
|
|
2492
2594
|
cssAssetProcessor(assetFolder, this.styles, { cwd }),
|
|
2493
2595
|
jsAssetProcessor(assetFolder, this.scripts),
|
|
@@ -2509,7 +2611,7 @@ class Generator {
|
|
|
2509
2611
|
];
|
|
2510
2612
|
compileProcessorRuntime(this, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)), processors);
|
|
2511
2613
|
const templateLoader = createTemplateLoader(templateFolders);
|
|
2512
|
-
const context = createContext(templateLoader);
|
|
2614
|
+
const context = createContext(outputFolder, templateLoader);
|
|
2513
2615
|
const generatedFiles = [
|
|
2514
2616
|
await stage("generate-docs", context, processors),
|
|
2515
2617
|
await stage("generate-nav", context, processors),
|
|
@@ -2536,7 +2638,7 @@ class Generator {
|
|
|
2536
2638
|
const { outputFolder, cacheFolder, assetFolder } = this;
|
|
2537
2639
|
await fs.rm(cacheFolder, { force: true, recursive: true });
|
|
2538
2640
|
if (fs$1.existsSync(outputFolder)) {
|
|
2539
|
-
await fs.mkdir(path.dirname(cacheFolder), { recursive: true });
|
|
2641
|
+
await fs.mkdir(path$1.dirname(cacheFolder), { recursive: true });
|
|
2540
2642
|
await vendor.fse.copy(outputFolder, cacheFolder);
|
|
2541
2643
|
await fs.rm(outputFolder, { recursive: true });
|
|
2542
2644
|
}
|
|
@@ -2580,7 +2682,9 @@ function extractTerms(doc) {
|
|
|
2580
2682
|
}
|
|
2581
2683
|
}
|
|
2582
2684
|
function isIndexable(doc) {
|
|
2583
|
-
return Boolean(
|
|
2685
|
+
return Boolean(
|
|
2686
|
+
doc.visible && doc.fileInfo.outputName && doc.format !== "redirect"
|
|
2687
|
+
);
|
|
2584
2688
|
}
|
|
2585
2689
|
function getTerms(doc) {
|
|
2586
2690
|
return {
|
|
@@ -2609,7 +2713,8 @@ function searchProcessor() {
|
|
|
2609
2713
|
alias: [],
|
|
2610
2714
|
visible: false,
|
|
2611
2715
|
attributes: {
|
|
2612
|
-
sortorder: Infinity
|
|
2716
|
+
sortorder: Infinity,
|
|
2717
|
+
redirectFrom: []
|
|
2613
2718
|
},
|
|
2614
2719
|
body,
|
|
2615
2720
|
outline: [],
|
|
@@ -2638,13 +2743,16 @@ exports.Generator = Generator;
|
|
|
2638
2743
|
exports.availableProcessors = availableProcessors;
|
|
2639
2744
|
exports.cookieProcessor = cookieProcessor;
|
|
2640
2745
|
exports.defineSources = defineSources;
|
|
2746
|
+
exports.extractExamplesProcessor = extractExamplesProcessor;
|
|
2641
2747
|
exports.frontMatterFileReader = frontMatterFileReader;
|
|
2748
|
+
exports.htmlRedirectProcessor = htmlRedirectProcessor;
|
|
2642
2749
|
exports.livereloadProcessor = livereloadProcessor;
|
|
2643
2750
|
exports.manifestProcessor = manifestProcessor;
|
|
2644
2751
|
exports.matomoProcessor = matomoProcessor;
|
|
2645
2752
|
exports.motdProcessor = motdProcessor;
|
|
2646
2753
|
exports.navigationFileReader = navigationFileReader;
|
|
2647
2754
|
exports.processorRuntimeName = processorRuntimeName;
|
|
2755
|
+
exports.redirectFileProcessor = redirectFileProcessor;
|
|
2648
2756
|
exports.searchProcessor = searchProcessor;
|
|
2649
2757
|
exports.selectableVersionProcessor = selectableVersionProcessor;
|
|
2650
2758
|
exports.sourceUrlProcessor = sourceUrlProcessor;
|