@t8/docsgen 0.4.1 → 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 +35 -5
- package/dist/css/section.css +23 -6
- package/package.json +4 -4
- package/src/bin/content/getSectionContent.ts +9 -3
- package/src/bin/getRepoMetadata.ts +19 -0
- package/src/css/section.css +23 -6
- package/src/types/RepoMetadata.ts +3 -0
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";
|
|
@@ -810,10 +832,18 @@ ${navContent}
|
|
|
810
832
|
</nav>`;
|
|
811
833
|
}
|
|
812
834
|
|
|
835
|
+
// src/bin/content/tweakTypography.ts
|
|
836
|
+
function tweakTypography(s = "") {
|
|
837
|
+
return s.replace(/\b(for|in|on|at|to|with|a|an|the|its)\s+/gi, "$1\xA0").replace(/\b(React)\s+(apps?)\b/gi, "$1\xA0$2");
|
|
838
|
+
}
|
|
839
|
+
|
|
813
840
|
// src/bin/content/getSectionContent.ts
|
|
814
841
|
async function getSectionContent(ctx, index) {
|
|
815
842
|
let { root, contentDir = "" } = ctx;
|
|
816
|
-
let
|
|
843
|
+
let repoDescription = index === 0 ? (await getRepoMetadata(ctx)).description : "";
|
|
844
|
+
let descriptionContent = escapeHTML(
|
|
845
|
+
tweakTypography(repoDescription || ctx.description)
|
|
846
|
+
);
|
|
817
847
|
let cssRoot = await getCSSRoot(ctx, "content");
|
|
818
848
|
let { sections, nav } = await getParsedContent(ctx);
|
|
819
849
|
let content = sections[index];
|
|
@@ -842,7 +872,7 @@ ${getInjectedContent(ctx, "section", "body", "prepend")}
|
|
|
842
872
|
<header class="aux">
|
|
843
873
|
<h1>${mainTitle}</h1>
|
|
844
874
|
<div class="description">
|
|
845
|
-
<p>${
|
|
875
|
+
<p>${descriptionContent}</p>
|
|
846
876
|
</div>
|
|
847
877
|
</header>
|
|
848
878
|
<div class="${navContent ? "" : "no-nav "}body">
|
|
@@ -863,7 +893,7 @@ ${content}
|
|
|
863
893
|
<div class="header" hidden>
|
|
864
894
|
<h1>${mainTitle}</h1>
|
|
865
895
|
<div class="description">
|
|
866
|
-
<p>${
|
|
896
|
+
<p>${descriptionContent}</p>
|
|
867
897
|
<p class="installation">${await getInstallationContent(ctx)}</p>
|
|
868
898
|
</div>
|
|
869
899
|
</div>
|
package/dist/css/section.css
CHANGED
|
@@ -11,17 +11,32 @@ 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
|
-
font-size: 1.
|
|
18
|
+
font-size: 1.3rem;
|
|
19
19
|
font-weight: 900;
|
|
20
|
+
color: var(--aux-emphatic-color);
|
|
20
21
|
margin: 0;
|
|
21
22
|
}
|
|
23
|
+
header h1 > a,
|
|
24
|
+
header h1 > a:link,
|
|
25
|
+
header h1 > a:hover,
|
|
26
|
+
header h1 > a:visited,
|
|
27
|
+
header h1 > a:active {
|
|
28
|
+
--color: var(--aux-emphatic-color);
|
|
29
|
+
text-decoration: underline;
|
|
30
|
+
border-bottom: none;
|
|
31
|
+
}
|
|
32
|
+
header h1 sup {
|
|
33
|
+
font-size: 0.5em;
|
|
34
|
+
}
|
|
22
35
|
header .description {
|
|
36
|
+
max-width: 36em;
|
|
23
37
|
font-size: 0.8em;
|
|
24
|
-
|
|
38
|
+
line-height: 1.2;
|
|
39
|
+
margin: 0.35em auto 0;
|
|
25
40
|
}
|
|
26
41
|
header .description p {
|
|
27
42
|
margin: 0;
|
|
@@ -87,8 +102,9 @@ aside > .header .installation code {
|
|
|
87
102
|
margin: 0;
|
|
88
103
|
}
|
|
89
104
|
aside h1 {
|
|
90
|
-
font-size: 1.
|
|
105
|
+
font-size: 1.3rem;
|
|
91
106
|
font-weight: 900;
|
|
107
|
+
color: var(--aux-emphatic-color);
|
|
92
108
|
margin: 0;
|
|
93
109
|
}
|
|
94
110
|
aside h1 > a,
|
|
@@ -96,7 +112,7 @@ aside h1 > a:link,
|
|
|
96
112
|
aside h1 > a:hover,
|
|
97
113
|
aside h1 > a:visited,
|
|
98
114
|
aside h1 > a:active {
|
|
99
|
-
--color: var(--aux-color);
|
|
115
|
+
--color: var(--aux-emphatic-color);
|
|
100
116
|
text-decoration: underline;
|
|
101
117
|
border-bottom: none;
|
|
102
118
|
}
|
|
@@ -251,6 +267,7 @@ main h1 + h2 {
|
|
|
251
267
|
margin-top: 0.5rem;
|
|
252
268
|
}
|
|
253
269
|
main h2 {
|
|
270
|
+
font-weight: 900;
|
|
254
271
|
border-bottom: var(--sep-line);
|
|
255
272
|
padding-bottom: 0.1em;
|
|
256
273
|
}
|
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";
|
|
@@ -14,10 +15,15 @@ import { getMainTitle } from "./getMainTitle.ts";
|
|
|
14
15
|
import { getNav } from "./getNav.ts";
|
|
15
16
|
import { getPlainTitle } from "./getPlainTitle.ts";
|
|
16
17
|
import { toFileContent } from "./toFileContent.ts";
|
|
18
|
+
import { tweakTypography } from "./tweakTypography.ts";
|
|
17
19
|
|
|
18
20
|
export async function getSectionContent(ctx: Context, index: number) {
|
|
19
21
|
let { root, contentDir = "" } = ctx;
|
|
20
|
-
let
|
|
22
|
+
let repoDescription =
|
|
23
|
+
index === 0 ? (await getRepoMetadata(ctx)).description : "";
|
|
24
|
+
let descriptionContent = escapeHTML(
|
|
25
|
+
tweakTypography(repoDescription || ctx.description),
|
|
26
|
+
);
|
|
21
27
|
|
|
22
28
|
let cssRoot = await getCSSRoot(ctx, "content");
|
|
23
29
|
let { sections, nav } = await getParsedContent(ctx);
|
|
@@ -50,7 +56,7 @@ ${getInjectedContent(ctx, "section", "body", "prepend")}
|
|
|
50
56
|
<header class="aux">
|
|
51
57
|
<h1>${mainTitle}</h1>
|
|
52
58
|
<div class="description">
|
|
53
|
-
<p>${
|
|
59
|
+
<p>${descriptionContent}</p>
|
|
54
60
|
</div>
|
|
55
61
|
</header>
|
|
56
62
|
<div class="${navContent ? "" : "no-nav "}body">
|
|
@@ -71,7 +77,7 @@ ${content}
|
|
|
71
77
|
<div class="header" hidden>
|
|
72
78
|
<h1>${mainTitle}</h1>
|
|
73
79
|
<div class="description">
|
|
74
|
-
<p>${
|
|
80
|
+
<p>${descriptionContent}</p>
|
|
75
81
|
<p class="installation">${await getInstallationContent(ctx)}</p>
|
|
76
82
|
</div>
|
|
77
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,17 +11,32 @@ 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
|
-
font-size: 1.
|
|
18
|
+
font-size: 1.3rem;
|
|
19
19
|
font-weight: 900;
|
|
20
|
+
color: var(--aux-emphatic-color);
|
|
20
21
|
margin: 0;
|
|
21
22
|
}
|
|
23
|
+
header h1 > a,
|
|
24
|
+
header h1 > a:link,
|
|
25
|
+
header h1 > a:hover,
|
|
26
|
+
header h1 > a:visited,
|
|
27
|
+
header h1 > a:active {
|
|
28
|
+
--color: var(--aux-emphatic-color);
|
|
29
|
+
text-decoration: underline;
|
|
30
|
+
border-bottom: none;
|
|
31
|
+
}
|
|
32
|
+
header h1 sup {
|
|
33
|
+
font-size: 0.5em;
|
|
34
|
+
}
|
|
22
35
|
header .description {
|
|
36
|
+
max-width: 36em;
|
|
23
37
|
font-size: 0.8em;
|
|
24
|
-
|
|
38
|
+
line-height: 1.2;
|
|
39
|
+
margin: 0.35em auto 0;
|
|
25
40
|
}
|
|
26
41
|
header .description p {
|
|
27
42
|
margin: 0;
|
|
@@ -87,8 +102,9 @@ aside > .header .installation code {
|
|
|
87
102
|
margin: 0;
|
|
88
103
|
}
|
|
89
104
|
aside h1 {
|
|
90
|
-
font-size: 1.
|
|
105
|
+
font-size: 1.3rem;
|
|
91
106
|
font-weight: 900;
|
|
107
|
+
color: var(--aux-emphatic-color);
|
|
92
108
|
margin: 0;
|
|
93
109
|
}
|
|
94
110
|
aside h1 > a,
|
|
@@ -96,7 +112,7 @@ aside h1 > a:link,
|
|
|
96
112
|
aside h1 > a:hover,
|
|
97
113
|
aside h1 > a:visited,
|
|
98
114
|
aside h1 > a:active {
|
|
99
|
-
--color: var(--aux-color);
|
|
115
|
+
--color: var(--aux-emphatic-color);
|
|
100
116
|
text-decoration: underline;
|
|
101
117
|
border-bottom: none;
|
|
102
118
|
}
|
|
@@ -251,6 +267,7 @@ main h1 + h2 {
|
|
|
251
267
|
margin-top: 0.5rem;
|
|
252
268
|
}
|
|
253
269
|
main h2 {
|
|
270
|
+
font-weight: 900;
|
|
254
271
|
border-bottom: var(--sep-line);
|
|
255
272
|
padding-bottom: 0.1em;
|
|
256
273
|
}
|