@t8/docsgen 0.1.93 → 0.1.95
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 +24 -17
- package/package.json +1 -1
- package/src/bin/setContent.ts +27 -18
package/dist/bin.js
CHANGED
|
@@ -680,6 +680,14 @@ function toFileContent(x) {
|
|
|
680
680
|
|
|
681
681
|
// src/bin/setContent.ts
|
|
682
682
|
var exec = (0, import_node_util.promisify)(import_node_child_process.exec);
|
|
683
|
+
function getDefaultCodeStyleContent(cssRoot) {
|
|
684
|
+
return `
|
|
685
|
+
<link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/base16/material.min.css">
|
|
686
|
+
<link rel="stylesheet" href="${cssRoot}/code.css">
|
|
687
|
+
<script src="https://unpkg.com/@highlightjs/cdn-assets@11.11.1/highlight.min.js"></script>
|
|
688
|
+
<script>hljs.highlightAll()</script>
|
|
689
|
+
`.trim();
|
|
690
|
+
}
|
|
683
691
|
async function setContent(ctx) {
|
|
684
692
|
let {
|
|
685
693
|
dir = "",
|
|
@@ -699,24 +707,23 @@ async function setContent(ctx) {
|
|
|
699
707
|
let escapedTitle = title ? escapeHTML(title) : escapedName;
|
|
700
708
|
let escapedPackageDescription = escapeHTML(packageDescription);
|
|
701
709
|
let rootAttrs = "";
|
|
702
|
-
let cssRoot =
|
|
710
|
+
let cssRoot = {
|
|
711
|
+
index: "",
|
|
712
|
+
content: ""
|
|
713
|
+
};
|
|
703
714
|
if (assetsDir) {
|
|
704
|
-
cssRoot = assetsDir;
|
|
705
|
-
|
|
715
|
+
cssRoot.index = assetsDir;
|
|
716
|
+
cssRoot.content = `../${assetsDir}`;
|
|
717
|
+
await (0, import_promises4.cp)((0, import_node_path3.join)(__dirname, "css"), (0, import_node_path3.join)(dir, cssRoot.index), {
|
|
706
718
|
force: true,
|
|
707
719
|
recursive: true
|
|
708
720
|
});
|
|
709
721
|
} else {
|
|
710
722
|
let packageVersion = (await exec(`npm view ${packageName} version`)).stdout.trim().split(".").slice(0, 2).join(".");
|
|
711
723
|
let packageUrl = `https://unpkg.com/${packageName}@${packageVersion}`;
|
|
712
|
-
cssRoot = `${packageUrl}/dist/css`;
|
|
724
|
+
cssRoot.index = `${packageUrl}/dist/css`;
|
|
725
|
+
cssRoot.content = `${packageUrl}/dist/css`;
|
|
713
726
|
}
|
|
714
|
-
let defaultCodeStyleContent = `
|
|
715
|
-
<link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/base16/material.min.css">
|
|
716
|
-
<link rel="stylesheet" href="${cssRoot}/code.css">
|
|
717
|
-
<script src="https://unpkg.com/@highlightjs/cdn-assets@11.11.1/highlight.min.js"></script>
|
|
718
|
-
<script>hljs.highlightAll()</script>
|
|
719
|
-
`.trim();
|
|
720
727
|
if (theme) rootAttrs += ` data-theme="${escapeHTML(theme)}"`;
|
|
721
728
|
if (baseColor) rootAttrs += ` style="--base-color: ${escapeHTML(baseColor)}"`;
|
|
722
729
|
let icon = getIcon(ctx);
|
|
@@ -780,8 +787,8 @@ ${getInjectedContent(ctx, "redirect", "body")}
|
|
|
780
787
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
781
788
|
<meta name="description" content="${escapedTitle}: ${escapeHTML(stripHTML(nav[i]?.title))}">
|
|
782
789
|
<title>${escapeHTML(stripHTML(nav[i]?.title))} | ${escapedTitle}</title>
|
|
783
|
-
<link rel="stylesheet" href="${cssRoot}/base.css">
|
|
784
|
-
<link rel="stylesheet" href="${cssRoot}/section.css">
|
|
790
|
+
<link rel="stylesheet" href="${cssRoot.content}/base.css">
|
|
791
|
+
<link rel="stylesheet" href="${cssRoot.content}/section.css">
|
|
785
792
|
${iconTag}
|
|
786
793
|
${nav[i + 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[i + 1]?.id}">` : ""}
|
|
787
794
|
${nav[i - 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[i - 1]?.id}">` : ""}
|
|
@@ -813,7 +820,7 @@ ${navContent.replace(
|
|
|
813
820
|
</div>
|
|
814
821
|
</div>
|
|
815
822
|
|
|
816
|
-
${content.includes("<pre><code ") ? getInjectedContent(ctx, "section", ":has-code") ||
|
|
823
|
+
${content.includes("<pre><code ") ? getInjectedContent(ctx, "section", ":has-code") || getDefaultCodeStyleContent(cssRoot.content) : ""}
|
|
817
824
|
${counterContent}
|
|
818
825
|
${getInjectedContent(ctx, "section", "body")}
|
|
819
826
|
</body>
|
|
@@ -831,8 +838,8 @@ ${getInjectedContent(ctx, "section", "body")}
|
|
|
831
838
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
832
839
|
<meta name="description" content="${escapedTitle}${escapedPackageDescription ? `: ${escapedPackageDescription}` : ""}">
|
|
833
840
|
<title>${escapedTitle}${escapedPackageDescription ? ` | ${escapedPackageDescription}` : ""}</title>
|
|
834
|
-
<link rel="stylesheet" href="${cssRoot}/base.css">
|
|
835
|
-
<link rel="stylesheet" href="${cssRoot}/index.css">
|
|
841
|
+
<link rel="stylesheet" href="${cssRoot.index}/base.css">
|
|
842
|
+
<link rel="stylesheet" href="${cssRoot.index}/index.css">
|
|
836
843
|
${iconTag}
|
|
837
844
|
<link rel="prefetch" href="${root}start">
|
|
838
845
|
${nav[0] ? `<link rel="prefetch" href="${root}${contentDir}/${nav[0]?.id ?? ""}">` : ""}
|
|
@@ -873,7 +880,7 @@ ${intro || features || note ? `
|
|
|
873
880
|
</main>
|
|
874
881
|
</div>
|
|
875
882
|
|
|
876
|
-
${[description, intro, features, note].some((s) => s.includes("<pre><code ")) ? getInjectedContent(ctx, "index", ":has-code") ||
|
|
883
|
+
${[description, intro, features, note].some((s) => s.includes("<pre><code ")) ? getInjectedContent(ctx, "index", ":has-code") || getDefaultCodeStyleContent(cssRoot.index) : ""}
|
|
877
884
|
${counterContent}
|
|
878
885
|
${getInjectedContent(ctx, "index", "body")}
|
|
879
886
|
</body>
|
|
@@ -890,7 +897,7 @@ ${getInjectedContent(ctx, "index", "body")}
|
|
|
890
897
|
<meta name="viewport" content="width=device-width">
|
|
891
898
|
<meta http-equiv="refresh" content="0; URL=${root}${contentDir}/${nav[0]?.id}">
|
|
892
899
|
<title>${escapedTitle}</title>
|
|
893
|
-
<link rel="stylesheet" href="${cssRoot}/base.css">
|
|
900
|
+
<link rel="stylesheet" href="${cssRoot.index}/base.css">
|
|
894
901
|
${iconTag}
|
|
895
902
|
<script>window.location.replace("${root}${contentDir}/${nav[0]?.id}");</script>
|
|
896
903
|
${getInjectedContent(ctx, "start", "head")}
|
package/package.json
CHANGED
package/src/bin/setContent.ts
CHANGED
|
@@ -18,6 +18,15 @@ import { toFileContent } from "./toFileContent";
|
|
|
18
18
|
|
|
19
19
|
const exec = promisify(defaultExec);
|
|
20
20
|
|
|
21
|
+
function getDefaultCodeStyleContent(cssRoot: string) {
|
|
22
|
+
return `
|
|
23
|
+
<link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/base16/material.min.css">
|
|
24
|
+
<link rel="stylesheet" href="${cssRoot}/code.css">
|
|
25
|
+
<script src="https://unpkg.com/@highlightjs/cdn-assets@11.11.1/highlight.min.js"></script>
|
|
26
|
+
<script>hljs.highlightAll()</script>
|
|
27
|
+
`.trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
21
30
|
export async function setContent(ctx: Context) {
|
|
22
31
|
let {
|
|
23
32
|
dir = "",
|
|
@@ -39,12 +48,16 @@ export async function setContent(ctx: Context) {
|
|
|
39
48
|
let escapedPackageDescription = escapeHTML(packageDescription);
|
|
40
49
|
|
|
41
50
|
let rootAttrs = "";
|
|
42
|
-
let cssRoot =
|
|
51
|
+
let cssRoot = {
|
|
52
|
+
index: "",
|
|
53
|
+
content: "",
|
|
54
|
+
};
|
|
43
55
|
|
|
44
56
|
if (assetsDir) {
|
|
45
|
-
cssRoot = assetsDir;
|
|
57
|
+
cssRoot.index = assetsDir;
|
|
58
|
+
cssRoot.content = `../${assetsDir}`;
|
|
46
59
|
|
|
47
|
-
await cp(join(__dirname, "css"), join(dir, cssRoot), {
|
|
60
|
+
await cp(join(__dirname, "css"), join(dir, cssRoot.index), {
|
|
48
61
|
force: true,
|
|
49
62
|
recursive: true,
|
|
50
63
|
});
|
|
@@ -57,16 +70,10 @@ export async function setContent(ctx: Context) {
|
|
|
57
70
|
|
|
58
71
|
let packageUrl = `https://unpkg.com/${packageName}@${packageVersion}`;
|
|
59
72
|
|
|
60
|
-
cssRoot = `${packageUrl}/dist/css`;
|
|
73
|
+
cssRoot.index = `${packageUrl}/dist/css`;
|
|
74
|
+
cssRoot.content = `${packageUrl}/dist/css`;
|
|
61
75
|
}
|
|
62
76
|
|
|
63
|
-
let defaultCodeStyleContent = `
|
|
64
|
-
<link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/base16/material.min.css">
|
|
65
|
-
<link rel="stylesheet" href="${cssRoot}/code.css">
|
|
66
|
-
<script src="https://unpkg.com/@highlightjs/cdn-assets@11.11.1/highlight.min.js"></script>
|
|
67
|
-
<script>hljs.highlightAll()</script>
|
|
68
|
-
`.trim();
|
|
69
|
-
|
|
70
77
|
if (theme) rootAttrs += ` data-theme="${escapeHTML(theme)}"`;
|
|
71
78
|
|
|
72
79
|
if (baseColor) rootAttrs += ` style="--base-color: ${escapeHTML(baseColor)}"`;
|
|
@@ -142,8 +149,8 @@ ${getInjectedContent(ctx, "redirect", "body")}
|
|
|
142
149
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
143
150
|
<meta name="description" content="${escapedTitle}: ${escapeHTML(stripHTML(nav[i]?.title))}">
|
|
144
151
|
<title>${escapeHTML(stripHTML(nav[i]?.title))} | ${escapedTitle}</title>
|
|
145
|
-
<link rel="stylesheet" href="${cssRoot}/base.css">
|
|
146
|
-
<link rel="stylesheet" href="${cssRoot}/section.css">
|
|
152
|
+
<link rel="stylesheet" href="${cssRoot.content}/base.css">
|
|
153
|
+
<link rel="stylesheet" href="${cssRoot.content}/section.css">
|
|
147
154
|
${iconTag}
|
|
148
155
|
${nav[i + 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[i + 1]?.id}">` : ""}
|
|
149
156
|
${nav[i - 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[i - 1]?.id}">` : ""}
|
|
@@ -177,7 +184,8 @@ ${navContent.replace(
|
|
|
177
184
|
|
|
178
185
|
${
|
|
179
186
|
content.includes("<pre><code ")
|
|
180
|
-
? getInjectedContent(ctx, "section", ":has-code") ||
|
|
187
|
+
? getInjectedContent(ctx, "section", ":has-code") ||
|
|
188
|
+
getDefaultCodeStyleContent(cssRoot.content)
|
|
181
189
|
: ""
|
|
182
190
|
}
|
|
183
191
|
${counterContent}
|
|
@@ -197,8 +205,8 @@ ${getInjectedContent(ctx, "section", "body")}
|
|
|
197
205
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
198
206
|
<meta name="description" content="${escapedTitle}${escapedPackageDescription ? `: ${escapedPackageDescription}` : ""}">
|
|
199
207
|
<title>${escapedTitle}${escapedPackageDescription ? ` | ${escapedPackageDescription}` : ""}</title>
|
|
200
|
-
<link rel="stylesheet" href="${cssRoot}/base.css">
|
|
201
|
-
<link rel="stylesheet" href="${cssRoot}/index.css">
|
|
208
|
+
<link rel="stylesheet" href="${cssRoot.index}/base.css">
|
|
209
|
+
<link rel="stylesheet" href="${cssRoot.index}/index.css">
|
|
202
210
|
${iconTag}
|
|
203
211
|
<link rel="prefetch" href="${root}start">
|
|
204
212
|
${nav[0] ? `<link rel="prefetch" href="${root}${contentDir}/${nav[0]?.id ?? ""}">` : ""}
|
|
@@ -245,7 +253,8 @@ ${
|
|
|
245
253
|
|
|
246
254
|
${
|
|
247
255
|
[description, intro, features, note].some((s) => s.includes("<pre><code "))
|
|
248
|
-
? getInjectedContent(ctx, "index", ":has-code") ||
|
|
256
|
+
? getInjectedContent(ctx, "index", ":has-code") ||
|
|
257
|
+
getDefaultCodeStyleContent(cssRoot.index)
|
|
249
258
|
: ""
|
|
250
259
|
}
|
|
251
260
|
${counterContent}
|
|
@@ -264,7 +273,7 @@ ${getInjectedContent(ctx, "index", "body")}
|
|
|
264
273
|
<meta name="viewport" content="width=device-width">
|
|
265
274
|
<meta http-equiv="refresh" content="0; URL=${root}${contentDir}/${nav[0]?.id}">
|
|
266
275
|
<title>${escapedTitle}</title>
|
|
267
|
-
<link rel="stylesheet" href="${cssRoot}/base.css">
|
|
276
|
+
<link rel="stylesheet" href="${cssRoot.index}/base.css">
|
|
268
277
|
${iconTag}
|
|
269
278
|
<script>window.location.replace("${root}${contentDir}/${nav[0]?.id}");</script>
|
|
270
279
|
${getInjectedContent(ctx, "start", "head")}
|