@t8/docsgen 0.1.19 → 0.1.21
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/.biomeincludes +1 -0
- package/dist/bin.js +22 -1
- package/package.json +4 -3
- package/schema.json +1 -0
- package/src/bin/getConfig.ts +6 -6
- package/src/bin/getInjectedContent.ts +28 -0
- package/src/bin/setContent.ts +9 -0
- package/src/bin/toConfig.ts +2 -2
- package/src/bin/toFileContent.ts +1 -1
- package/src/types/{BinConfig.ts → Config.ts} +1 -1
- package/src/types/ContentInjectionMap.ts +14 -0
- package/src/types/ContentInjectionTarget.ts +1 -0
- package/src/types/Context.ts +2 -2
- package/src/types/EntryConfig.ts +2 -0
- package/src/types/Page.ts +1 -0
package/.biomeincludes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!schema.json
|
package/dist/bin.js
CHANGED
|
@@ -291,6 +291,19 @@ function getIcon({ favicon, faviconType }) {
|
|
|
291
291
|
return icon;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
// src/bin/getInjectedContent.ts
|
|
295
|
+
function getInjectedContent(ctx, page, target, mode = "append") {
|
|
296
|
+
let injectedContent = ctx[mode]?.[target];
|
|
297
|
+
if (!injectedContent) return "";
|
|
298
|
+
return (Array.isArray(injectedContent) ? injectedContent : [injectedContent]).reduce((s, item) => {
|
|
299
|
+
if (item === void 0) return s;
|
|
300
|
+
if (typeof item === "string") return `${s}${s ? "\n" : ""}${item}`;
|
|
301
|
+
let { content, pages } = item;
|
|
302
|
+
if (!content || pages && !pages.includes(page)) return s;
|
|
303
|
+
return `${s}${s ? "\n" : ""}${content}`;
|
|
304
|
+
}, "");
|
|
305
|
+
}
|
|
306
|
+
|
|
294
307
|
// src/bin/getNav.ts
|
|
295
308
|
var import_jsdom2 = require("jsdom");
|
|
296
309
|
|
|
@@ -535,7 +548,7 @@ function getTitle(ctx, { cover, originalContent, withPackageURL } = {}) {
|
|
|
535
548
|
|
|
536
549
|
// src/bin/toFileContent.ts
|
|
537
550
|
function toFileContent(x) {
|
|
538
|
-
return `${x.trim()}
|
|
551
|
+
return `${x.replace(/\s+(<\/(head|body)>)/g, "\n$1").trim()}
|
|
539
552
|
`;
|
|
540
553
|
}
|
|
541
554
|
|
|
@@ -576,9 +589,11 @@ async function setContent(ctx) {
|
|
|
576
589
|
<meta name="viewport" content="width=device-width">
|
|
577
590
|
<meta http-equiv="refresh" content="0; URL=${escapedRedirect}">
|
|
578
591
|
${iconTag}
|
|
592
|
+
${getInjectedContent(ctx, "redirect", "head")}
|
|
579
593
|
</head>
|
|
580
594
|
<body>
|
|
581
595
|
${counterContent}
|
|
596
|
+
${getInjectedContent(ctx, "redirect", "body")}
|
|
582
597
|
<script>window.location.replace("${escapedRedirect}");</script>
|
|
583
598
|
</body>
|
|
584
599
|
</html>
|
|
@@ -616,6 +631,7 @@ ${counterContent}
|
|
|
616
631
|
${iconTag}
|
|
617
632
|
${nav[i + 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[i + 1]?.id}">` : ""}
|
|
618
633
|
${nav[i - 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[i - 1]?.id}">` : ""}
|
|
634
|
+
${getInjectedContent(ctx, "section", "head")}
|
|
619
635
|
</head>
|
|
620
636
|
<body>
|
|
621
637
|
<div class="layout">
|
|
@@ -650,6 +666,7 @@ ${content.includes("<pre><code ") ? `
|
|
|
650
666
|
<script>hljs.highlightAll()</script>
|
|
651
667
|
`.trim() : ""}
|
|
652
668
|
${counterContent}
|
|
669
|
+
${getInjectedContent(ctx, "section", "body")}
|
|
653
670
|
</body>
|
|
654
671
|
</html>
|
|
655
672
|
`)
|
|
@@ -670,6 +687,7 @@ ${counterContent}
|
|
|
670
687
|
${iconTag}
|
|
671
688
|
<link rel="prefetch" href="${root}start">
|
|
672
689
|
${nav[0] ? `<link rel="prefetch" href="${root}${contentDir}/${nav[0]?.id ?? ""}">` : ""}
|
|
690
|
+
${getInjectedContent(ctx, "index", "head")}
|
|
673
691
|
</head>
|
|
674
692
|
<body>
|
|
675
693
|
<div class="layout">
|
|
@@ -709,6 +727,7 @@ ${[description, features].some((s) => s.includes("<pre><code ")) ? `
|
|
|
709
727
|
<script>hljs.highlightAll()</script>
|
|
710
728
|
`.trim() : ""}
|
|
711
729
|
${counterContent}
|
|
730
|
+
${getInjectedContent(ctx, "index", "body")}
|
|
712
731
|
</body>
|
|
713
732
|
</html>
|
|
714
733
|
`)
|
|
@@ -726,6 +745,7 @@ ${counterContent}
|
|
|
726
745
|
<link rel="stylesheet" href="${packageUrl}/dist/css/base.css">
|
|
727
746
|
${iconTag}
|
|
728
747
|
<script>window.location.replace("${root}${contentDir}/${nav[0]?.id}");</script>
|
|
748
|
+
${getInjectedContent(ctx, "start", "head")}
|
|
729
749
|
</head>
|
|
730
750
|
<body>
|
|
731
751
|
<div class="layout">
|
|
@@ -733,6 +753,7 @@ ${counterContent}
|
|
|
733
753
|
</div>
|
|
734
754
|
|
|
735
755
|
${counterContent}
|
|
756
|
+
${getInjectedContent(ctx, "start", "body")}
|
|
736
757
|
</body>
|
|
737
758
|
</html>
|
|
738
759
|
`)
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t8/docsgen",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/bin.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"docsgen": "dist/bin.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "npx npm-run-all clean build-bin -
|
|
10
|
+
"build": "npx npm-run-all clean build-bin -p build-css",
|
|
11
11
|
"build-bin": "npx esbuild ./src/bin/run.ts --bundle --outfile=dist/bin.js --platform=node --external:jsdom --external:markdown-it",
|
|
12
12
|
"build-css": "node -e \"require('node:fs').cpSync('src/css', 'dist/css', { force: true, recursive: true });\"",
|
|
13
|
+
"build-schema": "npx ts-json-schema-generator -p src/types/Config.ts -t Config -o schema.json --minify",
|
|
13
14
|
"clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
|
|
14
15
|
"prepublishOnly": "npm run build",
|
|
15
|
-
"preversion": "npx npm-run-all typecheck shape build",
|
|
16
|
+
"preversion": "npx npm-run-all typecheck build-schema shape build",
|
|
16
17
|
"shape": "npx codeshape",
|
|
17
18
|
"typecheck": "tsc --noEmit"
|
|
18
19
|
},
|
package/schema.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$ref":"#/definitions/Config","$schema":"http://json-schema.org/draft-07/schema#","definitions":{"Config":{"additionalProperties":false,"properties":{"append":{"$ref":"#/definitions/ContentInjectionMap%3C(%22head%22%7C%22body%22)%3E"},"backstory":{"description":"Backstory link URL to be added to the front page.","type":"string"},"baseColor":{"type":"string"},"cname":{"description":"Content of the './CNAME' file.","type":"string"},"contentDir":{"description":"Generated section content directory.","type":"string"},"description":{"type":"string"},"dir":{"type":"string"},"entries":{"items":{"$ref":"#/definitions/EntryConfig"},"type":"array"},"favicon":{"description":"Favicon URL.","type":"string"},"faviconType":{"type":"string"},"htmlTitle":{"type":"string"},"id":{"type":"string"},"jsorg":{"description":"As a boolean, it means whether to add the '<package_name>.js.org' domain to the './CNAME' file.\n\nAs a string, it sets the '<jsorg_value>.js.org' domain to the './CNAME' file.","type":["boolean","string"]},"mainBranch":{"type":"string"},"name":{"type":"string"},"nav":{"description":"URL of an HTML file inserted into the navigation bar.","type":"string"},"npm":{"type":"string"},"redirect":{"description":"Redirection URL.","type":"string"},"remove":{"description":"Whether to remove the GitHub Pages branch and quit.","type":"boolean"},"repo":{"type":"string"},"root":{"description":"Main page root path.","type":"string"},"scope":{"description":"Scope URL.","type":"string"},"singlePage":{"description":"Whether to show all sections on a single page.","type":"boolean"},"source":{"type":"string"},"targetBranch":{"description":"Target branch.","examples":["gh-pages"],"type":"string"},"targetId":{"type":"string"},"theme":{"type":"string"},"title":{"type":"string"},"version":{"type":"string"},"ymid":{"type":["number","string"]}},"type":"object"},"ContentInjectionMap<(\"head\"|\"body\")>":{"additionalProperties":false,"properties":{"body":{"anyOf":[{"type":"string"},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"},{"items":{"anyOf":[{"type":"string"},{"not":{}},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"}]},"type":"array"}]},"head":{"anyOf":[{"type":"string"},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"},{"items":{"anyOf":[{"type":"string"},{"not":{}},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"}]},"type":"array"}]}},"type":"object"},"EntryConfig":{"additionalProperties":false,"properties":{"append":{"$ref":"#/definitions/ContentInjectionMap%3C(%22head%22%7C%22body%22)%3E"},"backstory":{"description":"Backstory link URL to be added to the front page.","type":"string"},"baseColor":{"type":"string"},"cname":{"description":"Content of the './CNAME' file.","type":"string"},"contentDir":{"description":"Generated section content directory.","type":"string"},"description":{"type":"string"},"dir":{"type":"string"},"favicon":{"description":"Favicon URL.","type":"string"},"faviconType":{"type":"string"},"htmlTitle":{"type":"string"},"id":{"type":"string"},"jsorg":{"description":"As a boolean, it means whether to add the '<package_name>.js.org' domain to the './CNAME' file.\n\nAs a string, it sets the '<jsorg_value>.js.org' domain to the './CNAME' file.","type":["boolean","string"]},"mainBranch":{"type":"string"},"name":{"type":"string"},"nav":{"description":"URL of an HTML file inserted into the navigation bar.","type":"string"},"npm":{"type":"string"},"redirect":{"description":"Redirection URL.","type":"string"},"remove":{"description":"Whether to remove the GitHub Pages branch and quit.","type":"boolean"},"repo":{"type":"string"},"root":{"description":"Main page root path.","type":"string"},"scope":{"description":"Scope URL.","type":"string"},"singlePage":{"description":"Whether to show all sections on a single page.","type":"boolean"},"source":{"type":"string"},"targetBranch":{"description":"Target branch.","examples":["gh-pages"],"type":"string"},"theme":{"type":"string"},"title":{"type":"string"},"version":{"type":"string"},"ymid":{"type":["number","string"]}},"type":"object"},"Page":{"enum":["index","start","section","redirect"],"type":"string"}}}
|
package/src/bin/getConfig.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseArgs } from "args-json";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Config } from "../types/Config";
|
|
3
3
|
import type { EntryConfig } from "../types/EntryConfig";
|
|
4
4
|
import type { PackageMetadata } from "../types/PackageMetadata";
|
|
5
5
|
import { fetchText } from "./fetchText";
|
|
@@ -41,17 +41,17 @@ async function reviseConfig(config: EntryConfig) {
|
|
|
41
41
|
return deriveMissingProps(await addMetadata(config));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
let config:
|
|
44
|
+
let config: Config | null = null;
|
|
45
45
|
|
|
46
|
-
export async function getConfig(): Promise<
|
|
46
|
+
export async function getConfig(): Promise<Config> {
|
|
47
47
|
if (config) return config;
|
|
48
48
|
|
|
49
|
-
let localConfig:
|
|
49
|
+
let localConfig: Config = {};
|
|
50
50
|
|
|
51
51
|
try {
|
|
52
52
|
localConfig = JSON.parse(
|
|
53
53
|
await fetchText("./docsgen.config.json"),
|
|
54
|
-
) as
|
|
54
|
+
) as Config;
|
|
55
55
|
} catch {}
|
|
56
56
|
|
|
57
57
|
let targetId: string | undefined;
|
|
@@ -65,7 +65,7 @@ export async function getConfig(): Promise<BinConfig> {
|
|
|
65
65
|
root: "/",
|
|
66
66
|
contentDir: "x",
|
|
67
67
|
...localConfig,
|
|
68
|
-
...parseArgs<
|
|
68
|
+
...parseArgs<Config>(args),
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
if (config.entries)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ContentInjectionTarget } from "../types/ContentInjectionTarget";
|
|
2
|
+
import type { Context } from "../types/Context";
|
|
3
|
+
import type { Page } from "../types/Page";
|
|
4
|
+
|
|
5
|
+
export function getInjectedContent(
|
|
6
|
+
ctx: Context,
|
|
7
|
+
page: Page,
|
|
8
|
+
target: ContentInjectionTarget,
|
|
9
|
+
mode: "append" | undefined = "append",
|
|
10
|
+
) {
|
|
11
|
+
let injectedContent = ctx[mode]?.[target];
|
|
12
|
+
|
|
13
|
+
if (!injectedContent) return "";
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
Array.isArray(injectedContent) ? injectedContent : [injectedContent]
|
|
17
|
+
).reduce((s, item) => {
|
|
18
|
+
if (item === undefined) return s;
|
|
19
|
+
|
|
20
|
+
if (typeof item === "string") return `${s}${s ? "\n" : ""}${item}`;
|
|
21
|
+
|
|
22
|
+
let { content, pages } = item;
|
|
23
|
+
|
|
24
|
+
if (!content || (pages && !pages.includes(page))) return s;
|
|
25
|
+
|
|
26
|
+
return `${s}${s ? "\n" : ""}${content}`;
|
|
27
|
+
}, "");
|
|
28
|
+
}
|
package/src/bin/setContent.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { escapeHTML } from "../utils/escapeHTML";
|
|
|
8
8
|
import { escapeRegExp } from "../utils/escapeRegExp";
|
|
9
9
|
import { getCounterContent } from "./getCounterContent";
|
|
10
10
|
import { getIcon } from "./getIcon";
|
|
11
|
+
import { getInjectedContent } from "./getInjectedContent";
|
|
11
12
|
import { getNav } from "./getNav";
|
|
12
13
|
import { getParsedContent } from "./getParsedContent";
|
|
13
14
|
import { getRepoLink } from "./getRepoLink";
|
|
@@ -65,9 +66,11 @@ export async function setContent(ctx: Context) {
|
|
|
65
66
|
<meta name="viewport" content="width=device-width">
|
|
66
67
|
<meta http-equiv="refresh" content="0; URL=${escapedRedirect}">
|
|
67
68
|
${iconTag}
|
|
69
|
+
${getInjectedContent(ctx, "redirect", "head")}
|
|
68
70
|
</head>
|
|
69
71
|
<body>
|
|
70
72
|
${counterContent}
|
|
73
|
+
${getInjectedContent(ctx, "redirect", "body")}
|
|
71
74
|
<script>window.location.replace("${escapedRedirect}");</script>
|
|
72
75
|
</body>
|
|
73
76
|
</html>
|
|
@@ -112,6 +115,7 @@ ${counterContent}
|
|
|
112
115
|
${iconTag}
|
|
113
116
|
${nav[i + 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[i + 1]?.id}">` : ""}
|
|
114
117
|
${nav[i - 1]?.id ? `<link rel="prefetch" href="${root}${contentDir}/${nav[i - 1]?.id}">` : ""}
|
|
118
|
+
${getInjectedContent(ctx, "section", "head")}
|
|
115
119
|
</head>
|
|
116
120
|
<body>
|
|
117
121
|
<div class="layout">
|
|
@@ -150,6 +154,7 @@ ${
|
|
|
150
154
|
: ""
|
|
151
155
|
}
|
|
152
156
|
${counterContent}
|
|
157
|
+
${getInjectedContent(ctx, "section", "body")}
|
|
153
158
|
</body>
|
|
154
159
|
</html>
|
|
155
160
|
`),
|
|
@@ -170,6 +175,7 @@ ${counterContent}
|
|
|
170
175
|
${iconTag}
|
|
171
176
|
<link rel="prefetch" href="${root}start">
|
|
172
177
|
${nav[0] ? `<link rel="prefetch" href="${root}${contentDir}/${nav[0]?.id ?? ""}">` : ""}
|
|
178
|
+
${getInjectedContent(ctx, "index", "head")}
|
|
173
179
|
</head>
|
|
174
180
|
<body>
|
|
175
181
|
<div class="layout">
|
|
@@ -217,6 +223,7 @@ ${
|
|
|
217
223
|
: ""
|
|
218
224
|
}
|
|
219
225
|
${counterContent}
|
|
226
|
+
${getInjectedContent(ctx, "index", "body")}
|
|
220
227
|
</body>
|
|
221
228
|
</html>
|
|
222
229
|
`),
|
|
@@ -234,6 +241,7 @@ ${counterContent}
|
|
|
234
241
|
<link rel="stylesheet" href="${packageUrl}/dist/css/base.css">
|
|
235
242
|
${iconTag}
|
|
236
243
|
<script>window.location.replace("${root}${contentDir}/${nav[0]?.id}");</script>
|
|
244
|
+
${getInjectedContent(ctx, "start", "head")}
|
|
237
245
|
</head>
|
|
238
246
|
<body>
|
|
239
247
|
<div class="layout">
|
|
@@ -241,6 +249,7 @@ ${counterContent}
|
|
|
241
249
|
</div>
|
|
242
250
|
|
|
243
251
|
${counterContent}
|
|
252
|
+
${getInjectedContent(ctx, "start", "body")}
|
|
244
253
|
</body>
|
|
245
254
|
</html>
|
|
246
255
|
`),
|
package/src/bin/toConfig.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Config } from "../types/Config";
|
|
2
2
|
import type { PackageMetadata } from "../types/PackageMetadata";
|
|
3
3
|
import { toRepoURL } from "./toRepoURL";
|
|
4
4
|
|
|
5
|
-
export function toConfig(metadata: PackageMetadata): Partial<
|
|
5
|
+
export function toConfig(metadata: PackageMetadata): Partial<Config> {
|
|
6
6
|
let { name, description, version, repository } = metadata;
|
|
7
7
|
|
|
8
8
|
return {
|
package/src/bin/toFileContent.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ContentInjectionTarget } from "./ContentInjectionTarget";
|
|
2
|
+
import type { Page } from "./Page";
|
|
3
|
+
|
|
4
|
+
type InjectedContent =
|
|
5
|
+
| string
|
|
6
|
+
| undefined
|
|
7
|
+
| {
|
|
8
|
+
content?: string | undefined;
|
|
9
|
+
pages?: Page[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type ContentInjectionMap<T extends ContentInjectionTarget> = Partial<
|
|
13
|
+
Record<T, InjectedContent | InjectedContent[]>
|
|
14
|
+
>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ContentInjectionTarget = "head" | "body";
|
package/src/types/Context.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Config } from "./Config";
|
|
2
2
|
import type { EntryConfig } from "./EntryConfig";
|
|
3
3
|
|
|
4
|
-
export type Context = Omit<
|
|
4
|
+
export type Context = Omit<Config, "entries"> & EntryConfig;
|
package/src/types/EntryConfig.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ContentInjectionMap } from "./ContentInjectionMap";
|
|
1
2
|
import type { Theme } from "./Theme";
|
|
2
3
|
|
|
3
4
|
export type EntryConfig = {
|
|
@@ -58,4 +59,5 @@ export type EntryConfig = {
|
|
|
58
59
|
*/
|
|
59
60
|
jsorg?: boolean | string;
|
|
60
61
|
ymid?: number | string;
|
|
62
|
+
append?: ContentInjectionMap<"head" | "body">;
|
|
61
63
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Page = "index" | "start" | "section" | "redirect";
|