@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 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(addMetadata));
169
- else await addMetadata(config);
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 import_jsdom = require("jsdom");
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 import_jsdom.JSDOM(navContent).window.document.body;
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 import_jsdom2 = require("jsdom");
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 import_jsdom2.JSDOM(content).window;
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 import_jsdom2.JSDOM(content);
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
- colorScheme,
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 (colorScheme)
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 = "", colorScheme, favicon }) {
763
+ async function setImages({ dir = "", baseColor, favicon }) {
741
764
  if (favicon) return;
742
- await (0, import_promises5.writeFile)(
743
- (0, import_node_path4.join)(dir, "./favicon.svg"),
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
@@ -2,7 +2,7 @@
2
2
  color-scheme: light dark;
3
3
 
4
4
  --b0: light-dark(white, #1a1a1a);
5
- --b1: var(--color-scheme, gray);
5
+ --b1: var(--base-color, gray);
6
6
  --link-color: light-dark(royalblue, deepskyblue);
7
7
  --button-color: light-dark(royalblue, royalblue);
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/docsgen",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "",
5
5
  "main": "dist/bin.js",
6
6
  "bin": {
@@ -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(addMetadata));
52
- else await addMetadata(config);
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
  }
@@ -19,7 +19,7 @@ const exec = promisify(defaultExec);
19
19
  export async function setContent(ctx: Context) {
20
20
  let {
21
21
  dir = "",
22
- colorScheme,
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 (colorScheme)
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
@@ -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 = "", colorScheme, favicon }: Context) {
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
  }
@@ -0,0 +1,7 @@
1
+ import { JSDOM } from "jsdom";
2
+
3
+ export function stripHTML(content: string) {
4
+ try {
5
+ return new JSDOM(content).window.document.body.textContent;
6
+ } catch {}
7
+ }
package/src/css/base.css CHANGED
@@ -2,7 +2,7 @@
2
2
  color-scheme: light dark;
3
3
 
4
4
  --b0: light-dark(white, #1a1a1a);
5
- --b1: var(--color-scheme, gray);
5
+ --b1: var(--base-color, gray);
6
6
  --link-color: light-dark(royalblue, deepskyblue);
7
7
  --button-color: light-dark(royalblue, royalblue);
8
8
 
@@ -4,7 +4,7 @@ export type EntryConfig = {
4
4
  id?: string;
5
5
  source?: string;
6
6
  dir?: string;
7
- colorScheme?: string;
7
+ baseColor?: string;
8
8
  theme?: Theme;
9
9
  name?: string;
10
10
  title?: string;