@t8/docsgen 0.4.2 → 0.4.3
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
|
@@ -39,6 +39,9 @@ var require_dist = __commonJS({
|
|
|
39
39
|
if (x.startsWith("-") && x.length === 2) return toCamelCase(x.slice(1));
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
function isKey(x) {
|
|
43
|
+
return Boolean(toKey(x));
|
|
44
|
+
}
|
|
42
45
|
function split(x) {
|
|
43
46
|
let words = [], word = "";
|
|
44
47
|
let hasOpenSingleQuote = false;
|
|
@@ -74,7 +77,10 @@ var require_dist = __commonJS({
|
|
|
74
77
|
let normalizedItem = item.trim();
|
|
75
78
|
let k = normalizedItem.indexOf("=");
|
|
76
79
|
if (k === -1) return normalizedItem;
|
|
77
|
-
|
|
80
|
+
let key2 = normalizedItem.slice(0, k);
|
|
81
|
+
let value = normalizedItem.slice(k + 1);
|
|
82
|
+
if (!isKey(key2)) return normalizedItem;
|
|
83
|
+
return [key2, value];
|
|
78
84
|
});
|
|
79
85
|
if (map) normalizedMap = map;
|
|
80
86
|
let key = "";
|
|
@@ -99,7 +105,7 @@ var require_dist = __commonJS({
|
|
|
99
105
|
else parsedValue = true;
|
|
100
106
|
let prevValue = parsedArgs[key];
|
|
101
107
|
let value;
|
|
102
|
-
if (prevValue === void 0) value = parsedValue;
|
|
108
|
+
if (prevValue === void 0) value = key === "" ? [parsedValue] : parsedValue;
|
|
103
109
|
else if (Array.isArray(prevValue)) value = [...prevValue, parsedValue];
|
|
104
110
|
else value = [prevValue, parsedValue];
|
|
105
111
|
parsedArgs[key] = value;
|
|
@@ -425,6 +431,22 @@ function getRepoLink({ repo }, className) {
|
|
|
425
431
|
return `<a href="${repo}"${className ? ` class="${className}"` : ""} target="_blank">${caption}</a>`;
|
|
426
432
|
}
|
|
427
433
|
|
|
434
|
+
// src/bin/getRepoMetadata.ts
|
|
435
|
+
async function getRepoMetadata({
|
|
436
|
+
repo
|
|
437
|
+
}) {
|
|
438
|
+
if (repo?.startsWith("https://github.com/")) {
|
|
439
|
+
try {
|
|
440
|
+
let repoMetadata = await fetchContent(
|
|
441
|
+
repo.replace("https://github.com/", "https://api.github.com/repos/")
|
|
442
|
+
);
|
|
443
|
+
return JSON.parse(repoMetadata);
|
|
444
|
+
} catch {
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return {};
|
|
448
|
+
}
|
|
449
|
+
|
|
428
450
|
// src/bin/parsing/getParsedContent.ts
|
|
429
451
|
import { JSDOM as JSDOM2 } from "jsdom";
|
|
430
452
|
import Markdown from "markdown-it";
|
|
@@ -818,7 +840,10 @@ function tweakTypography(s = "") {
|
|
|
818
840
|
// src/bin/content/getSectionContent.ts
|
|
819
841
|
async function getSectionContent(ctx, index) {
|
|
820
842
|
let { root, contentDir = "" } = ctx;
|
|
821
|
-
let
|
|
843
|
+
let repoDescription = index === 0 ? (await getRepoMetadata(ctx)).description : "";
|
|
844
|
+
let descriptionContent = escapeHTML(
|
|
845
|
+
tweakTypography(repoDescription || ctx.description)
|
|
846
|
+
);
|
|
822
847
|
let cssRoot = await getCSSRoot(ctx, "content");
|
|
823
848
|
let { sections, nav } = await getParsedContent(ctx);
|
|
824
849
|
let content = sections[index];
|
|
@@ -847,7 +872,7 @@ ${getInjectedContent(ctx, "section", "body", "prepend")}
|
|
|
847
872
|
<header class="aux">
|
|
848
873
|
<h1>${mainTitle}</h1>
|
|
849
874
|
<div class="description">
|
|
850
|
-
<p>${
|
|
875
|
+
<p>${descriptionContent}</p>
|
|
851
876
|
</div>
|
|
852
877
|
</header>
|
|
853
878
|
<div class="${navContent ? "" : "no-nav "}body">
|
|
@@ -868,7 +893,7 @@ ${content}
|
|
|
868
893
|
<div class="header" hidden>
|
|
869
894
|
<h1>${mainTitle}</h1>
|
|
870
895
|
<div class="description">
|
|
871
|
-
<p>${
|
|
896
|
+
<p>${descriptionContent}</p>
|
|
872
897
|
<p class="installation">${await getInstallationContent(ctx)}</p>
|
|
873
898
|
</div>
|
|
874
899
|
</div>
|
package/dist/css/section.css
CHANGED
|
@@ -11,8 +11,8 @@ footer {
|
|
|
11
11
|
header {
|
|
12
12
|
display: none;
|
|
13
13
|
text-align: center;
|
|
14
|
-
padding-top: 0.
|
|
15
|
-
padding-bottom: 0.
|
|
14
|
+
padding-top: 0.7em;
|
|
15
|
+
padding-bottom: 0.75em;
|
|
16
16
|
}
|
|
17
17
|
header h1 {
|
|
18
18
|
font-size: 1.3rem;
|
|
@@ -33,8 +33,10 @@ header h1 sup {
|
|
|
33
33
|
font-size: 0.5em;
|
|
34
34
|
}
|
|
35
35
|
header .description {
|
|
36
|
+
max-width: 36em;
|
|
36
37
|
font-size: 0.8em;
|
|
37
|
-
|
|
38
|
+
line-height: 1.2;
|
|
39
|
+
margin: 0.35em auto 0;
|
|
38
40
|
}
|
|
39
41
|
header .description p {
|
|
40
42
|
margin: 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t8/docsgen",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/bin.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/jsdom": "^27.0.0",
|
|
28
28
|
"@types/markdown-it": "^14.1.2",
|
|
29
|
-
"@types/node": "^25.
|
|
29
|
+
"@types/node": "^25.2.1"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"args-json": "^1.2.
|
|
33
|
-
"jsdom": "^
|
|
32
|
+
"args-json": "^1.2.12",
|
|
33
|
+
"jsdom": "^28.0.0",
|
|
34
34
|
"markdown-it": "^14.1.0"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -2,6 +2,7 @@ import type { Context } from "../../types/Context.ts";
|
|
|
2
2
|
import { escapeHTML } from "../../utils/escapeHTML.ts";
|
|
3
3
|
import { escapeRegExp } from "../../utils/escapeRegExp.ts";
|
|
4
4
|
import { getRepoLink } from "../getRepoLink.ts";
|
|
5
|
+
import { getRepoMetadata } from "../getRepoMetadata.ts";
|
|
5
6
|
import { getParsedContent } from "../parsing/getParsedContent.ts";
|
|
6
7
|
import { stripHTML } from "../stripHTML.ts";
|
|
7
8
|
import { getCounterContent } from "./getCounterContent.ts";
|
|
@@ -18,7 +19,11 @@ import { tweakTypography } from "./tweakTypography.ts";
|
|
|
18
19
|
|
|
19
20
|
export async function getSectionContent(ctx: Context, index: number) {
|
|
20
21
|
let { root, contentDir = "" } = ctx;
|
|
21
|
-
let
|
|
22
|
+
let repoDescription =
|
|
23
|
+
index === 0 ? (await getRepoMetadata(ctx)).description : "";
|
|
24
|
+
let descriptionContent = escapeHTML(
|
|
25
|
+
tweakTypography(repoDescription || ctx.description),
|
|
26
|
+
);
|
|
22
27
|
|
|
23
28
|
let cssRoot = await getCSSRoot(ctx, "content");
|
|
24
29
|
let { sections, nav } = await getParsedContent(ctx);
|
|
@@ -51,7 +56,7 @@ ${getInjectedContent(ctx, "section", "body", "prepend")}
|
|
|
51
56
|
<header class="aux">
|
|
52
57
|
<h1>${mainTitle}</h1>
|
|
53
58
|
<div class="description">
|
|
54
|
-
<p>${
|
|
59
|
+
<p>${descriptionContent}</p>
|
|
55
60
|
</div>
|
|
56
61
|
</header>
|
|
57
62
|
<div class="${navContent ? "" : "no-nav "}body">
|
|
@@ -72,7 +77,7 @@ ${content}
|
|
|
72
77
|
<div class="header" hidden>
|
|
73
78
|
<h1>${mainTitle}</h1>
|
|
74
79
|
<div class="description">
|
|
75
|
-
<p>${
|
|
80
|
+
<p>${descriptionContent}</p>
|
|
76
81
|
<p class="installation">${await getInstallationContent(ctx)}</p>
|
|
77
82
|
</div>
|
|
78
83
|
</div>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Context } from "../types/Context.ts";
|
|
2
|
+
import type { RepoMetadata } from "../types/RepoMetadata.ts";
|
|
3
|
+
import { fetchContent } from "./fetchContent.ts";
|
|
4
|
+
|
|
5
|
+
export async function getRepoMetadata({
|
|
6
|
+
repo,
|
|
7
|
+
}: Context): Promise<RepoMetadata> {
|
|
8
|
+
if (repo?.startsWith("https://github.com/")) {
|
|
9
|
+
try {
|
|
10
|
+
let repoMetadata = await fetchContent(
|
|
11
|
+
repo.replace("https://github.com/", "https://api.github.com/repos/"),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
return JSON.parse(repoMetadata) as RepoMetadata;
|
|
15
|
+
} catch {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {};
|
|
19
|
+
}
|
package/src/css/section.css
CHANGED
|
@@ -11,8 +11,8 @@ footer {
|
|
|
11
11
|
header {
|
|
12
12
|
display: none;
|
|
13
13
|
text-align: center;
|
|
14
|
-
padding-top: 0.
|
|
15
|
-
padding-bottom: 0.
|
|
14
|
+
padding-top: 0.7em;
|
|
15
|
+
padding-bottom: 0.75em;
|
|
16
16
|
}
|
|
17
17
|
header h1 {
|
|
18
18
|
font-size: 1.3rem;
|
|
@@ -33,8 +33,10 @@ header h1 sup {
|
|
|
33
33
|
font-size: 0.5em;
|
|
34
34
|
}
|
|
35
35
|
header .description {
|
|
36
|
+
max-width: 36em;
|
|
36
37
|
font-size: 0.8em;
|
|
37
|
-
|
|
38
|
+
line-height: 1.2;
|
|
39
|
+
margin: 0.35em auto 0;
|
|
38
40
|
}
|
|
39
41
|
header .description p {
|
|
40
42
|
margin: 0;
|