@t8/docsgen 0.1.19 → 0.1.20
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 +22 -1
- package/package.json +1 -1
- package/src/bin/getInjectedContent.ts +28 -0
- package/src/bin/setContent.ts +9 -0
- package/src/bin/toFileContent.ts +1 -1
- package/src/types/ContentInjectionMap.ts +14 -0
- package/src/types/ContentInjectionTarget.ts +1 -0
- package/src/types/EntryConfig.ts +2 -0
- package/src/types/Page.ts +1 -0
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
|
@@ -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/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/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";
|