@t8/docsgen 0.1.31 → 0.1.33
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 +11 -7
- package/package.json +1 -1
- package/schema.json +1 -1
- package/src/bin/getParsedContent.ts +11 -6
- package/src/bin/setContent.ts +3 -2
- package/src/types/EntryConfig.ts +2 -0
package/dist/bin.js
CHANGED
|
@@ -446,8 +446,9 @@ function getSectionPostprocess(linkMap) {
|
|
|
446
446
|
return (content) => {
|
|
447
447
|
let s = content;
|
|
448
448
|
s = s.replace(/<a href="([^"]+)">/g, (_, url) => {
|
|
449
|
-
|
|
450
|
-
|
|
449
|
+
let nextURL = linkMap[url] ?? url;
|
|
450
|
+
let attrs = /^(https?:)?\/\//.test(nextURL) ? ' target="_blank"' : "";
|
|
451
|
+
return `<a href="${nextURL}"${attrs}>`;
|
|
451
452
|
});
|
|
452
453
|
return s;
|
|
453
454
|
};
|
|
@@ -465,11 +466,11 @@ function postprocessBadges(content) {
|
|
|
465
466
|
return document.body.innerHTML;
|
|
466
467
|
}
|
|
467
468
|
async function getParsedContent(ctx) {
|
|
468
|
-
let { singlePage } = ctx;
|
|
469
|
+
let { singlePage, linkMap } = ctx;
|
|
469
470
|
let rawContent = await fetchText(getLocation(ctx, "README.md", ctx.source));
|
|
470
471
|
let content = md.render(rawContent);
|
|
471
472
|
let dom = new import_jsdom3.JSDOM(content);
|
|
472
|
-
let { nav, linkMap } = buildNav(ctx, dom);
|
|
473
|
+
let { nav, linkMap: navLinkMap } = buildNav(ctx, dom);
|
|
473
474
|
let badges = [];
|
|
474
475
|
let title = "";
|
|
475
476
|
let description = [];
|
|
@@ -514,7 +515,10 @@ async function getParsedContent(ctx) {
|
|
|
514
515
|
element = element.nextElementSibling;
|
|
515
516
|
}
|
|
516
517
|
if (section.length !== 0) sections.push(joinLines(section));
|
|
517
|
-
let postprocess = getSectionPostprocess(
|
|
518
|
+
let postprocess = getSectionPostprocess({
|
|
519
|
+
...navLinkMap,
|
|
520
|
+
...linkMap
|
|
521
|
+
});
|
|
518
522
|
return {
|
|
519
523
|
badges: postprocessBadges(joinLines(badges)),
|
|
520
524
|
title,
|
|
@@ -631,8 +635,8 @@ ${getInjectedContent(ctx, "redirect", "body")}
|
|
|
631
635
|
<head>
|
|
632
636
|
<meta charset="utf-8">
|
|
633
637
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
634
|
-
<meta name="description" content="${escapedTitle}: ${escapeHTML(nav[i]?.title)}">
|
|
635
|
-
<title>${escapeHTML(nav[i]?.title)} | ${escapedTitle}</title>
|
|
638
|
+
<meta name="description" content="${escapedTitle}: ${escapeHTML(stripHTML(nav[i]?.title))}">
|
|
639
|
+
<title>${escapeHTML(stripHTML(nav[i]?.title))} | ${escapedTitle}</title>
|
|
636
640
|
<link rel="stylesheet" href="${packageUrl}/dist/css/base.css">
|
|
637
641
|
<link rel="stylesheet" href="${packageUrl}/dist/css/section.css">
|
|
638
642
|
${iconTag}
|
package/package.json
CHANGED
package/schema.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"$ref":"#/definitions/Config","$schema":"http://json-schema.org/draft-07/schema#","definitions":{"Config":{"additionalProperties":false,"properties":{"$schema":{"type":"string"},"append":{"$ref":"#/definitions/ContentInjectionMap%3C(%22head%22%7C%22body%22%7C%22%3Ahas-code%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\"|\":has-code\")>":{"additionalProperties":false,"properties":{":has-code":{"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"}]},"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%7C%22%3Ahas-code%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"}}}
|
|
1
|
+
{"$ref":"#/definitions/Config","$schema":"http://json-schema.org/draft-07/schema#","definitions":{"Config":{"additionalProperties":false,"properties":{"$schema":{"type":"string"},"append":{"$ref":"#/definitions/ContentInjectionMap%3C(%22head%22%7C%22body%22%7C%22%3Ahas-code%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"]},"linkMap":{"additionalProperties":{"anyOf":[{"type":"string"},{"not":{}}]},"description":"Link substitution map.","type":"object"},"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\"|\":has-code\")>":{"additionalProperties":false,"properties":{":has-code":{"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"}]},"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%7C%22%3Ahas-code%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"]},"linkMap":{"additionalProperties":{"anyOf":[{"type":"string"},{"not":{}}]},"description":"Link substitution map.","type":"object"},"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"}}}
|
|
@@ -90,13 +90,15 @@ function getInstallationCode(element: Element) {
|
|
|
90
90
|
.match(/(\S\s*)?(npm (i|install) .*)/)?.[2];
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
function getSectionPostprocess(linkMap: Record<string, string>) {
|
|
93
|
+
function getSectionPostprocess(linkMap: Record<string, string | undefined>) {
|
|
94
94
|
return (content: string) => {
|
|
95
95
|
let s = content;
|
|
96
96
|
|
|
97
97
|
s = s.replace(/<a href="([^"]+)">/g, (_, url) => {
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
let nextURL = linkMap[url] ?? url;
|
|
99
|
+
let attrs = /^(https?:)?\/\//.test(nextURL) ? " target=\"_blank\"" : "";
|
|
100
|
+
|
|
101
|
+
return `<a href="${nextURL}"${attrs}>`;
|
|
100
102
|
});
|
|
101
103
|
|
|
102
104
|
return s;
|
|
@@ -122,12 +124,12 @@ function postprocessBadges(content: string) {
|
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
export async function getParsedContent(ctx: Context) {
|
|
125
|
-
let { singlePage } = ctx;
|
|
127
|
+
let { singlePage, linkMap } = ctx;
|
|
126
128
|
let rawContent = await fetchText(getLocation(ctx, "README.md", ctx.source));
|
|
127
129
|
let content = md.render(rawContent);
|
|
128
130
|
let dom = new JSDOM(content);
|
|
129
131
|
|
|
130
|
-
let { nav, linkMap } = buildNav(ctx, dom);
|
|
132
|
+
let { nav, linkMap: navLinkMap } = buildNav(ctx, dom);
|
|
131
133
|
|
|
132
134
|
let badges: string[] = [];
|
|
133
135
|
let title = "";
|
|
@@ -185,7 +187,10 @@ export async function getParsedContent(ctx: Context) {
|
|
|
185
187
|
|
|
186
188
|
if (section.length !== 0) sections.push(joinLines(section));
|
|
187
189
|
|
|
188
|
-
let postprocess = getSectionPostprocess(
|
|
190
|
+
let postprocess = getSectionPostprocess({
|
|
191
|
+
...navLinkMap,
|
|
192
|
+
...linkMap,
|
|
193
|
+
});
|
|
189
194
|
|
|
190
195
|
return {
|
|
191
196
|
badges: postprocessBadges(joinLines(badges)),
|
package/src/bin/setContent.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { getParsedContent } from "./getParsedContent";
|
|
|
14
14
|
import { getRepoLink } from "./getRepoLink";
|
|
15
15
|
import { getTitle } from "./getTitle";
|
|
16
16
|
import { toFileContent } from "./toFileContent";
|
|
17
|
+
import { stripHTML } from "./stripHTML";
|
|
17
18
|
|
|
18
19
|
const exec = promisify(defaultExec);
|
|
19
20
|
|
|
@@ -115,8 +116,8 @@ ${getInjectedContent(ctx, "redirect", "body")}
|
|
|
115
116
|
<head>
|
|
116
117
|
<meta charset="utf-8">
|
|
117
118
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
118
|
-
<meta name="description" content="${escapedTitle}: ${escapeHTML(nav[i]?.title)}">
|
|
119
|
-
<title>${escapeHTML(nav[i]?.title)} | ${escapedTitle}</title>
|
|
119
|
+
<meta name="description" content="${escapedTitle}: ${escapeHTML(stripHTML(nav[i]?.title))}">
|
|
120
|
+
<title>${escapeHTML(stripHTML(nav[i]?.title))} | ${escapedTitle}</title>
|
|
120
121
|
<link rel="stylesheet" href="${packageUrl}/dist/css/base.css">
|
|
121
122
|
<link rel="stylesheet" href="${packageUrl}/dist/css/section.css">
|
|
122
123
|
${iconTag}
|
package/src/types/EntryConfig.ts
CHANGED