@t8/docsgen 0.1.32 → 0.1.34
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 +9 -5
- package/dist/css/base.css +1 -1
- package/dist/css/section.css +3 -3
- package/package.json +1 -1
- package/schema.json +1 -1
- package/src/bin/getParsedContent.ts +11 -6
- package/src/css/base.css +1 -1
- package/src/css/section.css +3 -3
- 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,
|
package/dist/css/base.css
CHANGED
package/dist/css/section.css
CHANGED
|
@@ -117,7 +117,7 @@ main p.sep {
|
|
|
117
117
|
main hr {
|
|
118
118
|
background: none transparent;
|
|
119
119
|
border: none;
|
|
120
|
-
border-top:
|
|
120
|
+
border-top: var(--hr-border);
|
|
121
121
|
margin: var(--block-margin-y) 0;
|
|
122
122
|
}
|
|
123
123
|
main h1 {
|
|
@@ -139,7 +139,7 @@ main h1 + h2 {
|
|
|
139
139
|
margin-top: 0.75rem;
|
|
140
140
|
}
|
|
141
141
|
main h2 {
|
|
142
|
-
border-bottom:
|
|
142
|
+
border-bottom: var(--hr-border);
|
|
143
143
|
padding-bottom: 0.1em;
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -150,7 +150,7 @@ main h2 {
|
|
|
150
150
|
justify-content: space-between;
|
|
151
151
|
gap: 1em;
|
|
152
152
|
background: var(--b1-light);
|
|
153
|
-
border-top: var(--
|
|
153
|
+
border-top: 0.15rem solid var(--b1-medium);
|
|
154
154
|
padding: 0.6em 0.75em 0.75em;
|
|
155
155
|
margin: 1.5em 0 0;
|
|
156
156
|
}
|
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/css/base.css
CHANGED
package/src/css/section.css
CHANGED
|
@@ -117,7 +117,7 @@ main p.sep {
|
|
|
117
117
|
main hr {
|
|
118
118
|
background: none transparent;
|
|
119
119
|
border: none;
|
|
120
|
-
border-top:
|
|
120
|
+
border-top: var(--hr-border);
|
|
121
121
|
margin: var(--block-margin-y) 0;
|
|
122
122
|
}
|
|
123
123
|
main h1 {
|
|
@@ -139,7 +139,7 @@ main h1 + h2 {
|
|
|
139
139
|
margin-top: 0.75rem;
|
|
140
140
|
}
|
|
141
141
|
main h2 {
|
|
142
|
-
border-bottom:
|
|
142
|
+
border-bottom: var(--hr-border);
|
|
143
143
|
padding-bottom: 0.1em;
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -150,7 +150,7 @@ main h2 {
|
|
|
150
150
|
justify-content: space-between;
|
|
151
151
|
gap: 1em;
|
|
152
152
|
background: var(--b1-light);
|
|
153
|
-
border-top: var(--
|
|
153
|
+
border-top: 0.15rem solid var(--b1-medium);
|
|
154
154
|
padding: 0.6em 0.75em 0.75em;
|
|
155
155
|
margin: 1.5em 0 0;
|
|
156
156
|
}
|
package/src/types/EntryConfig.ts
CHANGED