@t8/docsgen 0.1.17 → 0.1.19
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 +37 -17
- package/dist/css/base.css +1 -1
- package/package.json +1 -1
- package/src/bin/getConfig.ts +23 -4
- package/src/bin/setContent.ts +2 -3
- package/src/bin/setImages.ts +2 -5
- package/src/bin/stripHTML.ts +7 -0
- package/src/css/base.css +1 -1
- package/src/types/EntryConfig.ts +1 -1
package/dist/bin.js
CHANGED
|
@@ -104,6 +104,15 @@ function getLocation(ctx, path, preferredLocation) {
|
|
|
104
104
|
return path;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
// src/bin/stripHTML.ts
|
|
108
|
+
var import_jsdom = require("jsdom");
|
|
109
|
+
function stripHTML(content) {
|
|
110
|
+
try {
|
|
111
|
+
return new import_jsdom.JSDOM(content).window.document.body.textContent;
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
107
116
|
// src/bin/toRepoURL.ts
|
|
108
117
|
function toRepoURL(x) {
|
|
109
118
|
if (!x) return "";
|
|
@@ -143,6 +152,22 @@ async function addMetadata(config2) {
|
|
|
143
152
|
return config2;
|
|
144
153
|
}
|
|
145
154
|
}
|
|
155
|
+
function deriveMissingProps(config2) {
|
|
156
|
+
let { dir, root, title, htmlTitle } = config2;
|
|
157
|
+
if (htmlTitle && !title) title = stripHTML(htmlTitle);
|
|
158
|
+
if (dir && !root) root = `/${dir}/`;
|
|
159
|
+
if (!root?.endsWith("/")) root = `${root ?? ""}/`;
|
|
160
|
+
return {
|
|
161
|
+
...config2,
|
|
162
|
+
dir,
|
|
163
|
+
root,
|
|
164
|
+
title,
|
|
165
|
+
htmlTitle
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
async function reviseConfig(config2) {
|
|
169
|
+
return deriveMissingProps(await addMetadata(config2));
|
|
170
|
+
}
|
|
146
171
|
var config = null;
|
|
147
172
|
async function getConfig() {
|
|
148
173
|
if (config) return config;
|
|
@@ -165,9 +190,8 @@ async function getConfig() {
|
|
|
165
190
|
...A(args)
|
|
166
191
|
};
|
|
167
192
|
if (config.entries)
|
|
168
|
-
config.entries = await Promise.all(config.entries.map(
|
|
169
|
-
else await
|
|
170
|
-
if (!config.root?.endsWith("/")) config.root = `${config.root ?? ""}/`;
|
|
193
|
+
config.entries = await Promise.all(config.entries.map(reviseConfig));
|
|
194
|
+
else config = await reviseConfig(config);
|
|
171
195
|
return config;
|
|
172
196
|
}
|
|
173
197
|
|
|
@@ -268,7 +292,7 @@ function getIcon({ favicon, faviconType }) {
|
|
|
268
292
|
}
|
|
269
293
|
|
|
270
294
|
// src/bin/getNav.ts
|
|
271
|
-
var
|
|
295
|
+
var import_jsdom2 = require("jsdom");
|
|
272
296
|
|
|
273
297
|
// src/bin/getRepoLink.ts
|
|
274
298
|
function getRepoLink({ repo }, className) {
|
|
@@ -283,7 +307,7 @@ async function getNav(ctx, navItems) {
|
|
|
283
307
|
let navContent = await fetchText(nav);
|
|
284
308
|
let s = "";
|
|
285
309
|
if (navContent) {
|
|
286
|
-
let navDom = new
|
|
310
|
+
let navDom = new import_jsdom2.JSDOM(navContent).window.document.body;
|
|
287
311
|
for (let link of navDom.querySelectorAll("a")) {
|
|
288
312
|
if (link.dataset.name === name) {
|
|
289
313
|
let parent = link.parentElement;
|
|
@@ -331,7 +355,7 @@ ${navContent}
|
|
|
331
355
|
}
|
|
332
356
|
|
|
333
357
|
// src/bin/getParsedContent.ts
|
|
334
|
-
var
|
|
358
|
+
var import_jsdom3 = require("jsdom");
|
|
335
359
|
var import_markdown_it = __toESM(require("markdown-it"));
|
|
336
360
|
|
|
337
361
|
// src/bin/getSlug.ts
|
|
@@ -415,7 +439,7 @@ function getSectionPostprocess(linkMap) {
|
|
|
415
439
|
};
|
|
416
440
|
}
|
|
417
441
|
function postprocessBadges(content) {
|
|
418
|
-
let { document } = new
|
|
442
|
+
let { document } = new import_jsdom3.JSDOM(content).window;
|
|
419
443
|
for (let img of document.querySelectorAll("img")) {
|
|
420
444
|
let parent = img.parentElement;
|
|
421
445
|
if (!parent) continue;
|
|
@@ -430,7 +454,7 @@ async function getParsedContent(ctx) {
|
|
|
430
454
|
let { singlePage } = ctx;
|
|
431
455
|
let rawContent = await fetchText(getLocation(ctx, "README.md", ctx.source));
|
|
432
456
|
let content = md.render(rawContent);
|
|
433
|
-
let dom = new
|
|
457
|
+
let dom = new import_jsdom3.JSDOM(content);
|
|
434
458
|
let { nav, linkMap } = buildNav(ctx, dom);
|
|
435
459
|
let badges = [];
|
|
436
460
|
let title = "";
|
|
@@ -520,7 +544,7 @@ var exec = (0, import_node_util.promisify)(import_node_child_process.exec);
|
|
|
520
544
|
async function setContent(ctx) {
|
|
521
545
|
let {
|
|
522
546
|
dir = "",
|
|
523
|
-
|
|
547
|
+
baseColor,
|
|
524
548
|
theme,
|
|
525
549
|
root,
|
|
526
550
|
contentDir = "",
|
|
@@ -537,8 +561,7 @@ async function setContent(ctx) {
|
|
|
537
561
|
let packageUrl = `https://unpkg.com/${packageName}@${packageVersion}`;
|
|
538
562
|
let rootAttrs = "";
|
|
539
563
|
if (theme) rootAttrs += ` data-theme="${escapeHTML(theme)}"`;
|
|
540
|
-
if (
|
|
541
|
-
rootAttrs += ` style="--color-scheme: ${escapeHTML(colorScheme)}"`;
|
|
564
|
+
if (baseColor) rootAttrs += ` style="--base-color: ${escapeHTML(baseColor)}"`;
|
|
542
565
|
let icon = getIcon(ctx);
|
|
543
566
|
let iconTag = icon.url ? `<link rel="icon"${icon.type ? ` type="${icon.type}"` : ""} href="${icon.url}">` : "";
|
|
544
567
|
if (redirect) {
|
|
@@ -737,13 +760,10 @@ function getIconContent(baseColor = "gray") {
|
|
|
737
760
|
}
|
|
738
761
|
|
|
739
762
|
// src/bin/setImages.ts
|
|
740
|
-
async function setImages({ dir = "",
|
|
763
|
+
async function setImages({ dir = "", baseColor, favicon }) {
|
|
741
764
|
if (favicon) return;
|
|
742
|
-
await (0, import_promises5.writeFile)(
|
|
743
|
-
|
|
744
|
-
`${getIconContent(colorScheme)}
|
|
745
|
-
`
|
|
746
|
-
);
|
|
765
|
+
await (0, import_promises5.writeFile)((0, import_node_path4.join)(dir, "./favicon.svg"), `${getIconContent(baseColor)}
|
|
766
|
+
`);
|
|
747
767
|
}
|
|
748
768
|
|
|
749
769
|
// src/bin/createFiles.ts
|
package/dist/css/base.css
CHANGED
package/package.json
CHANGED
package/src/bin/getConfig.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { EntryConfig } from "../types/EntryConfig";
|
|
|
4
4
|
import type { PackageMetadata } from "../types/PackageMetadata";
|
|
5
5
|
import { fetchText } from "./fetchText";
|
|
6
6
|
import { getLocation } from "./getLocation";
|
|
7
|
+
import { stripHTML } from "./stripHTML";
|
|
7
8
|
import { toConfig } from "./toConfig";
|
|
8
9
|
|
|
9
10
|
async function addMetadata(config: EntryConfig) {
|
|
@@ -20,6 +21,26 @@ async function addMetadata(config: EntryConfig) {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
function deriveMissingProps(config: EntryConfig) {
|
|
25
|
+
let { dir, root, title, htmlTitle } = config;
|
|
26
|
+
|
|
27
|
+
if (htmlTitle && !title) title = stripHTML(htmlTitle);
|
|
28
|
+
if (dir && !root) root = `/${dir}/`;
|
|
29
|
+
if (!root?.endsWith("/")) root = `${root ?? ""}/`;
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
...config,
|
|
33
|
+
dir,
|
|
34
|
+
root,
|
|
35
|
+
title,
|
|
36
|
+
htmlTitle,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function reviseConfig(config: EntryConfig) {
|
|
41
|
+
return deriveMissingProps(await addMetadata(config));
|
|
42
|
+
}
|
|
43
|
+
|
|
23
44
|
let config: BinConfig | null = null;
|
|
24
45
|
|
|
25
46
|
export async function getConfig(): Promise<BinConfig> {
|
|
@@ -48,10 +69,8 @@ export async function getConfig(): Promise<BinConfig> {
|
|
|
48
69
|
};
|
|
49
70
|
|
|
50
71
|
if (config.entries)
|
|
51
|
-
config.entries = await Promise.all(config.entries.map(
|
|
52
|
-
else await
|
|
53
|
-
|
|
54
|
-
if (!config.root?.endsWith("/")) config.root = `${config.root ?? ""}/`;
|
|
72
|
+
config.entries = await Promise.all(config.entries.map(reviseConfig));
|
|
73
|
+
else config = await reviseConfig(config);
|
|
55
74
|
|
|
56
75
|
return config;
|
|
57
76
|
}
|
package/src/bin/setContent.ts
CHANGED
|
@@ -19,7 +19,7 @@ const exec = promisify(defaultExec);
|
|
|
19
19
|
export async function setContent(ctx: Context) {
|
|
20
20
|
let {
|
|
21
21
|
dir = "",
|
|
22
|
-
|
|
22
|
+
baseColor,
|
|
23
23
|
theme,
|
|
24
24
|
root,
|
|
25
25
|
contentDir = "",
|
|
@@ -45,8 +45,7 @@ export async function setContent(ctx: Context) {
|
|
|
45
45
|
|
|
46
46
|
if (theme) rootAttrs += ` data-theme="${escapeHTML(theme)}"`;
|
|
47
47
|
|
|
48
|
-
if (
|
|
49
|
-
rootAttrs += ` style="--color-scheme: ${escapeHTML(colorScheme)}"`;
|
|
48
|
+
if (baseColor) rootAttrs += ` style="--base-color: ${escapeHTML(baseColor)}"`;
|
|
50
49
|
|
|
51
50
|
let icon = getIcon(ctx);
|
|
52
51
|
let iconTag = icon.url
|
package/src/bin/setImages.ts
CHANGED
|
@@ -3,11 +3,8 @@ import { join } from "node:path";
|
|
|
3
3
|
import type { Context } from "../types/Context";
|
|
4
4
|
import { getIconContent } from "../utils/getIconContent";
|
|
5
5
|
|
|
6
|
-
export async function setImages({ dir = "",
|
|
6
|
+
export async function setImages({ dir = "", baseColor, favicon }: Context) {
|
|
7
7
|
if (favicon) return;
|
|
8
8
|
|
|
9
|
-
await writeFile(
|
|
10
|
-
join(dir, "./favicon.svg"),
|
|
11
|
-
`${getIconContent(colorScheme)}\n`,
|
|
12
|
-
);
|
|
9
|
+
await writeFile(join(dir, "./favicon.svg"), `${getIconContent(baseColor)}\n`);
|
|
13
10
|
}
|
package/src/css/base.css
CHANGED