@t8/docsgen 0.1.0

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.
Files changed (43) hide show
  1. package/README.md +0 -0
  2. package/dist/bin.js +756 -0
  3. package/dist/css/base.css +232 -0
  4. package/dist/css/code.css +30 -0
  5. package/dist/css/code.lightbulb.css +278 -0
  6. package/dist/css/index.css +212 -0
  7. package/dist/css/section.css +200 -0
  8. package/package.json +36 -0
  9. package/src/bin/cleanup.ts +11 -0
  10. package/src/bin/createFiles.ts +8 -0
  11. package/src/bin/fetchText.ts +16 -0
  12. package/src/bin/getConfig.ts +44 -0
  13. package/src/bin/getCounterContent.ts +17 -0
  14. package/src/bin/getNav.ts +64 -0
  15. package/src/bin/getParsedContent.ts +180 -0
  16. package/src/bin/getRepoLink.ts +9 -0
  17. package/src/bin/getSlug.ts +21 -0
  18. package/src/bin/getTitle.ts +49 -0
  19. package/src/bin/run.ts +31 -0
  20. package/src/bin/runEntry.ts +55 -0
  21. package/src/bin/setCName.ts +13 -0
  22. package/src/bin/setContent.ts +251 -0
  23. package/src/bin/setImages.ts +8 -0
  24. package/src/bin/toConfig.ts +14 -0
  25. package/src/bin/toFileContent.ts +3 -0
  26. package/src/bin/toRepoURL.ts +22 -0
  27. package/src/const/packageName.ts +1 -0
  28. package/src/css/base.css +232 -0
  29. package/src/css/code.css +30 -0
  30. package/src/css/code.lightbulb.css +278 -0
  31. package/src/css/index.css +212 -0
  32. package/src/css/section.css +200 -0
  33. package/src/types/BinConfig.ts +6 -0
  34. package/src/types/Context.ts +4 -0
  35. package/src/types/EntryConfig.ts +57 -0
  36. package/src/types/NavItem.ts +8 -0
  37. package/src/types/PackageMetadata.ts +11 -0
  38. package/src/types/Theme.ts +1 -0
  39. package/src/utils/escapeHTML.ts +17 -0
  40. package/src/utils/escapeRegExp.ts +4 -0
  41. package/src/utils/getIcon.ts +16 -0
  42. package/src/utils/getSVGDataURL.ts +9 -0
  43. package/tsconfig.json +14 -0
@@ -0,0 +1,212 @@
1
+ html[data-theme="t8"] {
2
+ background:
3
+ linear-gradient(to bottom right, #90eec6, #9a70ce) 50% 50% / cover no-repeat;
4
+ }
5
+ @media (max-width: 840px) {
6
+ html[data-theme="t8"] {
7
+ background:
8
+ linear-gradient(to bottom, #90eec6, #9a70ce) 50% 50% / cover no-repeat;
9
+ }
10
+ }
11
+ @media (prefers-color-scheme: dark) {
12
+ html[data-theme="t8"] {
13
+ background:
14
+ linear-gradient(to bottom right, #14a482, #6649b5) 50% 50% / cover
15
+ no-repeat;
16
+ }
17
+ }
18
+ @media (max-width: 840px) and (prefers-color-scheme: dark) {
19
+ html[data-theme="t8"] {
20
+ background:
21
+ linear-gradient(to bottom, #14a482, #6649b5) 50% 50% / cover no-repeat;
22
+ }
23
+ }
24
+ body {
25
+ min-height: 100vh;
26
+ }
27
+
28
+ .layout {
29
+ display: flex;
30
+ flex-direction: column;
31
+ min-height: 90vh;
32
+ align-items: center;
33
+ justify-content: center;
34
+ }
35
+
36
+ main {
37
+ --max-content-width: 32em;
38
+
39
+ display: flex;
40
+ align-items: flex-start;
41
+ justify-content: center;
42
+ padding: 0;
43
+ margin: 6vh 0;
44
+ }
45
+ @media (max-width: 840px) {
46
+ main {
47
+ --max-content-width: 100%;
48
+
49
+ display: block;
50
+ margin: 0;
51
+ }
52
+ }
53
+
54
+ h1 {
55
+ font-size: 2.5em;
56
+ font-weight: 900;
57
+ margin: 1.5rem 0;
58
+ }
59
+ @media (max-width: 840px) {
60
+ h1 {
61
+ font-size: 2.35em;
62
+ }
63
+ }
64
+ h1 a {
65
+ position: relative;
66
+ }
67
+ h1 a::before {
68
+ content: "";
69
+ background-color: color(from var(--b1) srgb r g b / 0.3);
70
+ transform: skew(-15deg, -10deg);
71
+ border-radius: 0.4em;
72
+ position: absolute;
73
+ inset: 0.3em -0.25em 0.25em;
74
+ transition: inset 0.3s;
75
+ }
76
+ h1 a:hover {
77
+ text-decoration: none;
78
+ }
79
+ h1 a:hover::before {
80
+ inset: 0.25em -0.25em 0.2em;
81
+ }
82
+ header {
83
+ display: block;
84
+ text-align: center;
85
+ padding: 0 var(--content-padding-x);
86
+ }
87
+ @media (max-width: 840px) {
88
+ .badges {
89
+ margin: 0 2em;
90
+ }
91
+ }
92
+ .description {
93
+ font-size: 1.1em;
94
+ margin: 0;
95
+ }
96
+ .description p {
97
+ margin-top: 0;
98
+ }
99
+ .actions {
100
+ --r: 1em;
101
+
102
+ font-size: 1.25em;
103
+ margin: 0.5em 0;
104
+ }
105
+ .actions a.button {
106
+ min-width: 32%;
107
+ }
108
+ @media (max-width: 840px) {
109
+ .actions {
110
+ font-size: 1.15em;
111
+ }
112
+ }
113
+ .actions .sep {
114
+ display: none;
115
+ }
116
+ .ref {
117
+ font-size: 0.9em;
118
+ }
119
+
120
+ section {
121
+ max-width: var(--max-content-width);
122
+ padding: 0 2.5em;
123
+ box-sizing: border-box;
124
+ }
125
+ section + section {
126
+ display: flex;
127
+ flex-direction: column;
128
+ align-self: stretch;
129
+ justify-content: center;
130
+ border-left: 0.1em solid var(--b1-medium);
131
+ }
132
+ section.intro-title {
133
+ text-align: center;
134
+ padding-top: 4em;
135
+ padding-bottom: 4em;
136
+ }
137
+ @media (max-width: 840px) {
138
+ section {
139
+ max-width: 100%;
140
+ padding: var(--content-padding-y) var(--content-padding-x);
141
+ }
142
+ section + section {
143
+ display: block;
144
+ border-left: none;
145
+ }
146
+ section.intro-title {
147
+ padding-top: 2em;
148
+ padding-bottom: 0;
149
+ }
150
+ section.intro {
151
+ padding-bottom: 2.5em;
152
+ }
153
+ }
154
+ .features {
155
+ --link-color: color(from var(--c0) srgb r g b / 0.55);
156
+ --link-decoration: underline;
157
+
158
+ margin: 2em 0;
159
+ }
160
+ @media (max-width: 840px) {
161
+ .features {
162
+ padding: 0;
163
+ margin: 0;
164
+ }
165
+ }
166
+ .features h2 {
167
+ font-size: 1.5em;
168
+ font-style: italic;
169
+ text-align: center;
170
+ border: none;
171
+ padding: 0.1em 0;
172
+ margin: 0.75em 0 0.5em;
173
+ }
174
+ .features > ul {
175
+ list-style: none;
176
+ padding: 0;
177
+ margin: 0.5em 0 0;
178
+ }
179
+ .features > ul > li {
180
+ background: var(--b1-light);
181
+ border-bottom: 0.25em solid var(--b1-medium);
182
+ border-radius: 0.5em;
183
+ padding: 0.9em 1.2em;
184
+ margin: 1em 0;
185
+ box-sizing: border-box;
186
+ }
187
+ @media (max-width: 840px) {
188
+ .features > ul > li {
189
+ width: 100%;
190
+ margin: 0.5em 0;
191
+ }
192
+ }
193
+ .features > ul > li > ul {
194
+ list-style: disc;
195
+ }
196
+ .note {
197
+ padding: 0 3.5em;
198
+ margin: 1.5em 0;
199
+ }
200
+ @media (max-width: 840px) {
201
+ .note {
202
+ padding: 0;
203
+ }
204
+ }
205
+ p.installation {
206
+ font-size: 1.25em;
207
+ text-align: center;
208
+ margin: 1em 0;
209
+ }
210
+ .installation code {
211
+ background: transparent;
212
+ }
@@ -0,0 +1,200 @@
1
+ .body {
2
+ display: flex;
3
+ align-items: stretch;
4
+ padding: var(--content-padding-y) var(--content-padding-x);
5
+ }
6
+ .body > hr {
7
+ display: none;
8
+ }
9
+ @media (max-width: 840px) {
10
+ .body {
11
+ flex-direction: column;
12
+ padding: 0;
13
+ }
14
+ }
15
+ .body > nav {
16
+ width: 30%;
17
+ flex: none;
18
+ align-self: flex-start;
19
+ font-size: 0.9em;
20
+ background: var(--b1-light);
21
+ border-radius: var(--content-border-radius);
22
+ padding: 0.5rem var(--content-padding-x) 0.65rem;
23
+ margin: 0 0 0 var(--space-x);
24
+ box-sizing: border-box;
25
+ }
26
+ @media (max-width: 840px) {
27
+ .body > nav {
28
+ width: 100%;
29
+ font-size: inherit;
30
+ border-top: 0.35em solid var(--b1);
31
+ border-radius: 0;
32
+ padding: 0.25rem var(--content-padding-x) 0.35rem;
33
+ margin: 0;
34
+ }
35
+ }
36
+ .body > nav section {
37
+ padding: 1rem 0;
38
+ }
39
+ .body > nav section + section {
40
+ border-top: 0.05rem solid var(--b1);
41
+ }
42
+ .body > nav section.related {
43
+ border-top: 0.15rem double var(--b1);
44
+ }
45
+ .body > nav h2,
46
+ .body > nav p.title {
47
+ font-size: 0.7rem;
48
+ font-weight: normal;
49
+ line-height: 1.2;
50
+ text-transform: uppercase;
51
+ color: color(from var(--c0) srgb r g b / 0.6);
52
+ margin: 1.1rem 0 0.75rem 0;
53
+ }
54
+ .body > nav h2:first-of-type,
55
+ .body > nav p.title:first-of-type {
56
+ margin-top: 0;
57
+ }
58
+ .body > nav ul {
59
+ line-height: 1.2;
60
+ padding: 0;
61
+ padding-inline-start: 1em;
62
+ margin: 0;
63
+ }
64
+ .body > nav > ul + ul {
65
+ border-top: 0.05rem solid var(--b1);
66
+ padding-top: 1.2em;
67
+ margin-top: 1.5em;
68
+ }
69
+ .body > nav ul ul {
70
+ margin: 0.65em 0 0.5em;
71
+ }
72
+ .body > nav li {
73
+ margin-top: 0;
74
+ margin-bottom: 0;
75
+ }
76
+ .body > nav li + li {
77
+ margin-top: 0.5em;
78
+ }
79
+ @media (max-width: 840px) {
80
+ .body > nav li + li {
81
+ margin-top: 0.65em;
82
+ }
83
+ }
84
+ .body > nav > ul:last-child,
85
+ .body > nav > ul:last-child > li:last-child {
86
+ margin-bottom: 0;
87
+ }
88
+ .body > nav a.active {
89
+ font-weight: bold;
90
+ text-decoration: none;
91
+ color: inherit;
92
+ pointer-events: none;
93
+ }
94
+ .body > nav a.anchorjs-link {
95
+ display: none;
96
+ }
97
+
98
+ main {
99
+ width: calc(70% - var(--space-x));
100
+ box-sizing: border-box;
101
+ }
102
+ @media (max-width: 840px) {
103
+ main {
104
+ width: 100%;
105
+ padding: var(--content-padding-y) var(--content-padding-x) 0;
106
+ }
107
+ }
108
+ .body.no-nav {
109
+ --max-content-width: 45em;
110
+ }
111
+ .body.no-nav > main {
112
+ width: auto;
113
+ }
114
+ main p.sep {
115
+ font-size: 1.5em;
116
+ text-align: center;
117
+ margin: 0.5em 0;
118
+ }
119
+ main hr {
120
+ background: none transparent;
121
+ border: none;
122
+ border-top: 0.075em solid;
123
+ margin: var(--block-margin-y) 0;
124
+ }
125
+ main h1 {
126
+ font-size: 0.8rem;
127
+ font-weight: normal;
128
+ line-height: 1.1;
129
+ color: color(from var(--c0) srgb r g b / 0.5);
130
+ margin: 0;
131
+ }
132
+ h1 .sep {
133
+ margin: 0 0.1em;
134
+ }
135
+ @media (max-width: 840px) {
136
+ main h1 {
137
+ margin-top: 0;
138
+ }
139
+ }
140
+ main h1 + h2 {
141
+ margin-top: 0.75rem;
142
+ }
143
+ main h2 {
144
+ border-bottom: var(--hr-border);
145
+ padding-bottom: 0.1em;
146
+ }
147
+
148
+ .pagenav {
149
+ --icon-width: 1.25em;
150
+
151
+ display: flex;
152
+ justify-content: space-between;
153
+ gap: 1em;
154
+ background: var(--b1-light);
155
+ border-top: var(--hr-border);
156
+ padding: 0.6em 0.75em 0.75em;
157
+ margin: 1.5em 0 0;
158
+ }
159
+ @media (max-width: 840px) {
160
+ .pagenav {
161
+ padding: 1em var(--content-padding-x) 1.1em;
162
+ margin: 2em calc(-1 * var(--content-padding-x)) 0;
163
+ }
164
+ }
165
+ .pagenav .prev,
166
+ .pagenav .next {
167
+ display: inline-block;
168
+ line-height: 1.2;
169
+ position: relative;
170
+ }
171
+ .pagenav .icon {
172
+ display: inline-block;
173
+ width: var(--icon-width);
174
+ box-sizing: border-box;
175
+ position: absolute;
176
+ top: 0;
177
+ }
178
+ .pagenav .prev {
179
+ text-align: left;
180
+ }
181
+ .pagenav .prev .icon {
182
+ left: 0;
183
+ }
184
+ .pagenav .next {
185
+ text-align: right;
186
+ }
187
+ .pagenav .next .icon {
188
+ right: 0;
189
+ }
190
+ .pagenav .prev {
191
+ padding-left: var(--icon-width);
192
+ }
193
+ .pagenav .next {
194
+ padding-right: var(--icon-width);
195
+ }
196
+ .pagenav .sep,
197
+ .pagenav .anchorjs-link,
198
+ .pagenav hr {
199
+ display: none;
200
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@t8/docsgen",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "main": "dist/bin.js",
6
+ "bin": {
7
+ "docsgen": "dist/bin.js"
8
+ },
9
+ "scripts": {
10
+ "build": "npx npm-run-all clean build-bin -s build-css",
11
+ "build-bin": "npx esbuild ./src/bin/run.ts --bundle --outfile=dist/bin.js --platform=node --external:jsdom --external:markdown-it",
12
+ "build-css": "node -e \"require('node:fs').cpSync('src/css', 'dist/css', { force: true, recursive: true });\"",
13
+ "clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
14
+ "prepublishOnly": "npm run build",
15
+ "preversion": "npx npm-run-all typecheck shape build",
16
+ "shape": "npx codeshape",
17
+ "typecheck": "tsc --noEmit"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/t8js/docsgen.git"
22
+ },
23
+ "license": "ISC",
24
+ "author": "axtk",
25
+ "devDependencies": {
26
+ "@types/jsdom": "^27.0.0",
27
+ "@types/markdown-it": "^14.1.2",
28
+ "@types/node": "^24.7.0",
29
+ "typescript": "^5.9.3"
30
+ },
31
+ "dependencies": {
32
+ "args-json": "^1.2.4",
33
+ "jsdom": "^27.0.0",
34
+ "markdown-it": "^14.1.0"
35
+ }
36
+ }
@@ -0,0 +1,11 @@
1
+ import { rm } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import type { Context } from "../types/Context";
4
+
5
+ export async function cleanup({ dir = "" }: Context) {
6
+ await Promise.all(
7
+ ["x", "index.html", "start.html"].map((path) => {
8
+ return rm(join(dir, path), { force: true, recursive: true });
9
+ }),
10
+ );
11
+ }
@@ -0,0 +1,8 @@
1
+ import type { Context } from "../types/Context";
2
+ import { setCName } from "./setCName";
3
+ import { setContent } from "./setContent";
4
+ import { setImages } from "./setImages";
5
+
6
+ export async function createFiles(ctx: Context) {
7
+ await Promise.all([setCName(ctx), setContent(ctx), setImages(ctx)]);
8
+ }
@@ -0,0 +1,16 @@
1
+ import { readFile } from "node:fs/promises";
2
+
3
+ export async function fetchText(location: string | undefined) {
4
+ if (!location) return "";
5
+
6
+ if (/^https?:\/\//.test(location)) {
7
+ try {
8
+ return await (await fetch(location)).text();
9
+ } catch {
10
+ console.warn(`Failed to fetch content from '${location}'`);
11
+ return "";
12
+ }
13
+ }
14
+
15
+ return (await readFile(location)).toString();
16
+ }
@@ -0,0 +1,44 @@
1
+ import { parseArgs } from "args-json";
2
+ import type { BinConfig } from "../types/BinConfig";
3
+ import type { PackageMetadata } from "../types/PackageMetadata";
4
+ import { fetchText } from "./fetchText";
5
+ import { toConfig } from "./toConfig";
6
+
7
+ let config: BinConfig | null = null;
8
+
9
+ export async function getConfig(): Promise<BinConfig> {
10
+ if (config) return config;
11
+
12
+ let metadata: PackageMetadata = {};
13
+
14
+ try {
15
+ metadata = JSON.parse(await fetchText("./package.json")) as PackageMetadata;
16
+ } catch {}
17
+
18
+ let localConfig: BinConfig = {};
19
+
20
+ try {
21
+ localConfig = JSON.parse(
22
+ await fetchText("./docsgen.config.json"),
23
+ ) as BinConfig;
24
+ } catch {}
25
+
26
+ let targetId: string | undefined;
27
+ let args = process.argv.slice(2);
28
+
29
+ if (!args[0].startsWith("--")) targetId = args.shift();
30
+
31
+ config = {
32
+ targetId,
33
+ mainBranch: "main",
34
+ root: "/",
35
+ contentDir: "x",
36
+ ...toConfig(metadata),
37
+ ...localConfig,
38
+ ...parseArgs<BinConfig>(args),
39
+ };
40
+
41
+ if (!config.root?.endsWith("/")) config.root = `${config.root ?? ""}/`;
42
+
43
+ return config;
44
+ }
@@ -0,0 +1,17 @@
1
+ import type { Context } from "../types/Context";
2
+
3
+ export function getCounterContent({ ymid }: Context) {
4
+ if (!ymid) return "";
5
+
6
+ return `
7
+ <script>
8
+ (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
9
+ m[i].l=1*new Date();
10
+ for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
11
+ k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
12
+ (window, document, "script", "https://mc.yandex.com/metrika/tag.js", "ym");
13
+ ym(${ymid}, "init", {clickmap: true, trackLinks: true, accurateTrackBounce: true});
14
+ </script>
15
+ <noscript><div><img src="https://mc.yandex.com/watch/${ymid}" style="position:absolute;left:-9999px;" alt=""></div></noscript>
16
+ `.trim();
17
+ }
@@ -0,0 +1,64 @@
1
+ import { JSDOM } from "jsdom";
2
+ import type { Context } from "../types/Context";
3
+ import type { NavItem } from "../types/NavItem";
4
+ import { fetchText } from "./fetchText";
5
+ import { getRepoLink } from "./getRepoLink";
6
+
7
+ export async function getNav(ctx: Context, navItems: NavItem[]) {
8
+ let { name, root, contentDir, backstory, nav } = ctx;
9
+ let navContent = await fetchText(nav);
10
+ let s = "";
11
+
12
+ if (navContent) {
13
+ let navDom = new JSDOM(navContent).window.document.body;
14
+
15
+ for (let link of navDom.querySelectorAll("a")) {
16
+ if (link.dataset.name === name) {
17
+ let parent = link.parentElement;
18
+
19
+ link.remove();
20
+
21
+ while (parent && parent.innerHTML.trim() === "") {
22
+ let nextParent = parent.parentElement;
23
+
24
+ parent.remove();
25
+ parent = nextParent;
26
+ }
27
+ }
28
+ }
29
+
30
+ navContent = navDom.innerHTML;
31
+ }
32
+
33
+ if (navItems.length > 1) {
34
+ for (let { id, title, items } of navItems) {
35
+ s += `\n<li data-id="${id}"><a href="${root}${contentDir}/${id}">${title}</a></li>`;
36
+
37
+ if (items.length !== 0) {
38
+ s += "\n <ul>";
39
+
40
+ for (let { title } of items) s += `\n <li>${title}</li>`;
41
+
42
+ s += "\n </ul>\n";
43
+ }
44
+
45
+ s += "</li>";
46
+ }
47
+ }
48
+
49
+ if (!s && !navContent) return "";
50
+
51
+ let repoLink = getRepoLink(ctx);
52
+
53
+ s = s.trim() ? `<section><ul>${s}\n</ul></section>` : "";
54
+ s = `${s}
55
+ <section class="ref">
56
+ <ul>
57
+ <li>${repoLink}</li>
58
+ ${backstory ? `<li><a href="${backstory}">Backstory</a></li>` : ""}
59
+ </ul>
60
+ </section>
61
+ ${navContent}`;
62
+
63
+ return `<nav>\n${s}\n</nav>`;
64
+ }