@t8/docsgen 0.3.33 → 0.3.34
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/dist/bin.js +75 -48
- package/package.json +1 -1
- package/src/bin/content/getCSSRoot.ts +16 -10
- package/src/bin/content/getNav.ts +39 -2
- package/src/bin/content/getSectionContent.ts +52 -52
package/dist/bin.js
CHANGED
|
@@ -572,6 +572,7 @@ var packageName = "@t8/docsgen";
|
|
|
572
572
|
var exec = promisify(defaultExec);
|
|
573
573
|
var __filename = fileURLToPath(import.meta.url);
|
|
574
574
|
var __dirname = dirname(__filename);
|
|
575
|
+
var packageURL = "";
|
|
575
576
|
async function getCSSRoot(ctx, type) {
|
|
576
577
|
let { dir = "", assetsDir } = ctx;
|
|
577
578
|
let cssRoot = {
|
|
@@ -586,10 +587,12 @@ async function getCSSRoot(ctx, type) {
|
|
|
586
587
|
recursive: true
|
|
587
588
|
});
|
|
588
589
|
} else {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
590
|
+
if (!packageURL) {
|
|
591
|
+
let packageVersion = (await exec(`npm view ${packageName} version`)).stdout.trim().split(".").slice(0, 2).join(".");
|
|
592
|
+
packageURL = `https://unpkg.com/${packageName}@${packageVersion}`;
|
|
593
|
+
}
|
|
594
|
+
cssRoot.index = `${packageURL}/dist/css`;
|
|
595
|
+
cssRoot.content = `${packageURL}/dist/css`;
|
|
593
596
|
}
|
|
594
597
|
return cssRoot[type];
|
|
595
598
|
}
|
|
@@ -798,9 +801,33 @@ function getNpmLink({ npm }, className) {
|
|
|
798
801
|
}
|
|
799
802
|
|
|
800
803
|
// src/bin/content/getNav.ts
|
|
804
|
+
var cachedNavContent = /* @__PURE__ */ new Map();
|
|
805
|
+
async function getNavContent({ name, nav }) {
|
|
806
|
+
if (!nav) return "";
|
|
807
|
+
let navContent = cachedNavContent.get(nav);
|
|
808
|
+
if (navContent !== void 0) return navContent;
|
|
809
|
+
navContent = await fetchContent(nav);
|
|
810
|
+
if (navContent) {
|
|
811
|
+
let navDom = new JSDOM3(navContent).window.document.body;
|
|
812
|
+
for (let link of navDom.querySelectorAll("a")) {
|
|
813
|
+
if (link.dataset.name === name) {
|
|
814
|
+
let parent = link.parentElement;
|
|
815
|
+
link.remove();
|
|
816
|
+
while (parent && parent.innerHTML.trim() === "") {
|
|
817
|
+
let nextParent = parent.parentElement;
|
|
818
|
+
parent.remove();
|
|
819
|
+
parent = nextParent;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
navContent = navDom.innerHTML;
|
|
824
|
+
}
|
|
825
|
+
cachedNavContent.set(nav, navContent);
|
|
826
|
+
return navContent;
|
|
827
|
+
}
|
|
801
828
|
async function getNav(ctx, navItems) {
|
|
802
|
-
let { name, root, contentDir, backstory
|
|
803
|
-
let navContent = await
|
|
829
|
+
let { name, root, contentDir, backstory } = ctx;
|
|
830
|
+
let navContent = await getNavContent(ctx);
|
|
804
831
|
let s = "";
|
|
805
832
|
if (navContent) {
|
|
806
833
|
let navDom = new JSDOM3(navContent).window.document.body;
|
|
@@ -880,53 +907,53 @@ async function getSectionContent(ctx, index) {
|
|
|
880
907
|
let navContent = await getNav(ctx, nav);
|
|
881
908
|
let plainTitle = await getPlainTitle(ctx);
|
|
882
909
|
return toFileContent(`
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
910
|
+
<!DOCTYPE html>
|
|
911
|
+
<html lang="en" data-layout="section">
|
|
912
|
+
<head>
|
|
913
|
+
${getInjectedContent(ctx, "section", "head", "prepend")}
|
|
914
|
+
<meta charset="utf-8">
|
|
915
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
916
|
+
<meta name="description" content="${plainTitle}: ${escapeHTML(stripHTML(nav[index]?.title, true))}">
|
|
917
|
+
<title>${escapeHTML(stripHTML(nav[index]?.title, true))} | ${plainTitle}</title>
|
|
918
|
+
<link rel="stylesheet" href="${cssRoot}/base.css">
|
|
919
|
+
<link rel="stylesheet" href="${cssRoot}/section.css">
|
|
920
|
+
${getIconTag(ctx)}
|
|
921
|
+
${nav[index + 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[index + 1]?.id}">` : ""}
|
|
922
|
+
${nav[index - 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[index - 1]?.id}">` : ""}
|
|
923
|
+
${getInjectedContent(ctx, "section", "head", "append")}
|
|
924
|
+
</head>
|
|
925
|
+
<body>
|
|
926
|
+
${getInjectedContent(ctx, "section", "body", "prepend")}
|
|
927
|
+
<div class="layout">
|
|
928
|
+
<div class="${navContent ? "" : "no-nav "}body">
|
|
929
|
+
<main>
|
|
930
|
+
<h1><a href="${root}">${plainTitle}</a></h1>
|
|
931
|
+
${content}
|
|
932
|
+
|
|
933
|
+
<p class="pagenav">
|
|
934
|
+
<span class="prev">
|
|
935
|
+
<span class="icon">\u2190</span>
|
|
936
|
+
${nav[index - 1]?.id ? `<a href="${root}${contentDir}/${nav[index - 1]?.id}">${nav[index - 1]?.title}</a>` : `<a href="${root}">Intro</a>`}
|
|
937
|
+
</span>
|
|
938
|
+
<span class="sep">|</span>
|
|
939
|
+
${nav[index + 1]?.id ? `<span class="next"><a href="${root}${contentDir}/${nav[index + 1]?.id}">${nav[index + 1]?.title}</a> <span class="icon">\u2192</span></span>` : `<span class="repo">${getRepoLink(ctx)}</span>`}
|
|
940
|
+
</p>
|
|
941
|
+
</main>
|
|
942
|
+
${navContent ? "<hr>" : ""}
|
|
943
|
+
${navContent.replace(
|
|
917
944
|
new RegExp(
|
|
918
945
|
`(<li data-id="${escapeRegExp(nav[index]?.id)}">)<a href="[^"]+">([^<]+)</a>`
|
|
919
946
|
),
|
|
920
947
|
"$1<strong>$2</strong>"
|
|
921
948
|
)}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
949
|
+
</div>
|
|
950
|
+
</div>
|
|
951
|
+
|
|
952
|
+
${content.includes("<pre><code ") ? getInjectedContent(ctx, "section", ":has-code", "append") || getDefaultCodeStyleContent(cssRoot) : ""}
|
|
953
|
+
${getCounterContent(ctx)}
|
|
954
|
+
${getInjectedContent(ctx, "section", "body", "append")}
|
|
955
|
+
</body>
|
|
956
|
+
</html>
|
|
930
957
|
`);
|
|
931
958
|
}
|
|
932
959
|
|
package/package.json
CHANGED
|
@@ -11,6 +11,8 @@ const exec = promisify(defaultExec);
|
|
|
11
11
|
const __filename = fileURLToPath(import.meta.url);
|
|
12
12
|
const __dirname = dirname(__filename);
|
|
13
13
|
|
|
14
|
+
let packageURL = "";
|
|
15
|
+
|
|
14
16
|
export async function getCSSRoot(ctx: Context, type: "index" | "content") {
|
|
15
17
|
let { dir = "", assetsDir } = ctx;
|
|
16
18
|
|
|
@@ -28,16 +30,20 @@ export async function getCSSRoot(ctx: Context, type: "index" | "content") {
|
|
|
28
30
|
recursive: true,
|
|
29
31
|
});
|
|
30
32
|
} else {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
if (!packageURL) {
|
|
34
|
+
let packageVersion = (
|
|
35
|
+
await exec(`npm view ${packageName} version`)
|
|
36
|
+
).stdout
|
|
37
|
+
.trim()
|
|
38
|
+
.split(".")
|
|
39
|
+
.slice(0, 2)
|
|
40
|
+
.join(".");
|
|
41
|
+
|
|
42
|
+
packageURL = `https://unpkg.com/${packageName}@${packageVersion}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
cssRoot.index = `${packageURL}/dist/css`;
|
|
46
|
+
cssRoot.content = `${packageURL}/dist/css`;
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
return cssRoot[type];
|
|
@@ -5,9 +5,46 @@ import { fetchContent } from "../fetchContent.ts";
|
|
|
5
5
|
import { getNpmLink } from "../getNpmLink.ts";
|
|
6
6
|
import { getRepoLink } from "../getRepoLink.ts";
|
|
7
7
|
|
|
8
|
+
let cachedNavContent = new Map<string, string>();
|
|
9
|
+
|
|
10
|
+
async function getNavContent({ name, nav }: Context) {
|
|
11
|
+
if (!nav) return "";
|
|
12
|
+
|
|
13
|
+
let navContent = cachedNavContent.get(nav);
|
|
14
|
+
|
|
15
|
+
if (navContent !== undefined) return navContent;
|
|
16
|
+
|
|
17
|
+
navContent = await fetchContent(nav);
|
|
18
|
+
|
|
19
|
+
if (navContent) {
|
|
20
|
+
let navDom = new JSDOM(navContent).window.document.body;
|
|
21
|
+
|
|
22
|
+
for (let link of navDom.querySelectorAll("a")) {
|
|
23
|
+
if (link.dataset.name === name) {
|
|
24
|
+
let parent = link.parentElement;
|
|
25
|
+
|
|
26
|
+
link.remove();
|
|
27
|
+
|
|
28
|
+
while (parent && parent.innerHTML.trim() === "") {
|
|
29
|
+
let nextParent = parent.parentElement;
|
|
30
|
+
|
|
31
|
+
parent.remove();
|
|
32
|
+
parent = nextParent;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
navContent = navDom.innerHTML;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
cachedNavContent.set(nav, navContent);
|
|
41
|
+
|
|
42
|
+
return navContent;
|
|
43
|
+
}
|
|
44
|
+
|
|
8
45
|
export async function getNav(ctx: Context, navItems: NavItem[]) {
|
|
9
|
-
let { name, root, contentDir, backstory
|
|
10
|
-
let navContent = await
|
|
46
|
+
let { name, root, contentDir, backstory } = ctx;
|
|
47
|
+
let navContent = await getNavContent(ctx);
|
|
11
48
|
let s = "";
|
|
12
49
|
|
|
13
50
|
if (navContent) {
|
|
@@ -24,57 +24,57 @@ export async function getSectionContent(ctx: Context, index: number) {
|
|
|
24
24
|
let plainTitle = await getPlainTitle(ctx);
|
|
25
25
|
|
|
26
26
|
return toFileContent(`
|
|
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
|
-
|
|
27
|
+
<!DOCTYPE html>
|
|
28
|
+
<html lang="en" data-layout="section">
|
|
29
|
+
<head>
|
|
30
|
+
${getInjectedContent(ctx, "section", "head", "prepend")}
|
|
31
|
+
<meta charset="utf-8">
|
|
32
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
33
|
+
<meta name="description" content="${plainTitle}: ${escapeHTML(stripHTML(nav[index]?.title, true))}">
|
|
34
|
+
<title>${escapeHTML(stripHTML(nav[index]?.title, true))} | ${plainTitle}</title>
|
|
35
|
+
<link rel="stylesheet" href="${cssRoot}/base.css">
|
|
36
|
+
<link rel="stylesheet" href="${cssRoot}/section.css">
|
|
37
|
+
${getIconTag(ctx)}
|
|
38
|
+
${nav[index + 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[index + 1]?.id}">` : ""}
|
|
39
|
+
${nav[index - 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[index - 1]?.id}">` : ""}
|
|
40
|
+
${getInjectedContent(ctx, "section", "head", "append")}
|
|
41
|
+
</head>
|
|
42
|
+
<body>
|
|
43
|
+
${getInjectedContent(ctx, "section", "body", "prepend")}
|
|
44
|
+
<div class="layout">
|
|
45
|
+
<div class="${navContent ? "" : "no-nav "}body">
|
|
46
|
+
<main>
|
|
47
|
+
<h1><a href="${root}">${plainTitle}</a></h1>
|
|
48
|
+
${content}
|
|
49
|
+
|
|
50
|
+
<p class="pagenav">
|
|
51
|
+
<span class="prev">
|
|
52
|
+
<span class="icon">←</span>
|
|
53
|
+
${nav[index - 1]?.id ? `<a href="${root}${contentDir}/${nav[index - 1]?.id}">${nav[index - 1]?.title}</a>` : `<a href="${root}">Intro</a>`}
|
|
54
|
+
</span>
|
|
55
|
+
<span class="sep">|</span>
|
|
56
|
+
${nav[index + 1]?.id ? `<span class="next"><a href="${root}${contentDir}/${nav[index + 1]?.id}">${nav[index + 1]?.title}</a> <span class="icon">→</span></span>` : `<span class="repo">${getRepoLink(ctx)}</span>`}
|
|
57
|
+
</p>
|
|
58
|
+
</main>
|
|
59
|
+
${navContent ? "<hr>" : ""}
|
|
60
|
+
${navContent.replace(
|
|
61
|
+
new RegExp(
|
|
62
|
+
`(<li data-id="${escapeRegExp(nav[index]?.id)}">)<a href="[^"]+">([^<]+)</a>`,
|
|
63
|
+
),
|
|
64
|
+
"$1<strong>$2</strong>",
|
|
65
|
+
)}
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
${
|
|
70
|
+
content.includes("<pre><code ")
|
|
71
|
+
? getInjectedContent(ctx, "section", ":has-code", "append") ||
|
|
72
|
+
getDefaultCodeStyleContent(cssRoot)
|
|
73
|
+
: ""
|
|
74
|
+
}
|
|
75
|
+
${getCounterContent(ctx)}
|
|
76
|
+
${getInjectedContent(ctx, "section", "body", "append")}
|
|
77
|
+
</body>
|
|
78
|
+
</html>
|
|
79
79
|
`);
|
|
80
80
|
}
|