comarkserv 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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +389 -0
  3. package/dist/THIRD_PARTY_LICENSES.md +932 -0
  4. package/dist/build-CsToYJrU.mjs +2 -0
  5. package/dist/build-Cv5aO0CB.mjs +205 -0
  6. package/dist/cli.d.mts +1 -0
  7. package/dist/cli.mjs +894 -0
  8. package/dist/cloudflared-6f_lzz4F.mjs +181 -0
  9. package/dist/dist-B-IALNns.mjs +2 -0
  10. package/dist/dist-BK-bpLWg.mjs +2 -0
  11. package/dist/dist-BQzCbTko.mjs +1693 -0
  12. package/dist/dist-BWcWG5YB.mjs +671 -0
  13. package/dist/dist-BiVw4ojz.mjs +592 -0
  14. package/dist/dist-BnmL9jeq.mjs +538 -0
  15. package/dist/dist-BtedNLrc.mjs +276 -0
  16. package/dist/dist-BvdNTrap.mjs +2710 -0
  17. package/dist/dist-ByijHttv.mjs +69 -0
  18. package/dist/dist-C2E4zSX1.mjs +347 -0
  19. package/dist/dist-CWYRQLUT.mjs +2 -0
  20. package/dist/dist-CXQ7eTfT.mjs +417 -0
  21. package/dist/dist-CfsjQ0o8.mjs +905 -0
  22. package/dist/dist-CsTXDvwi.mjs +300 -0
  23. package/dist/dist-CtONMLh4.mjs +283 -0
  24. package/dist/dist-DMftjyxU.mjs +370 -0
  25. package/dist/dist-Dr9uTCX7.mjs +2 -0
  26. package/dist/dist-Dxvc11TH.mjs +339 -0
  27. package/dist/dist-GmbcGEAc.mjs +3 -0
  28. package/dist/dist-V1rkISnf.mjs +220 -0
  29. package/dist/dist-ZoN94PJ0.mjs +76 -0
  30. package/dist/dist-fh99cWMN.mjs +524 -0
  31. package/dist/editor-CHDyOp-8.mjs +721 -0
  32. package/dist/index.d.mts +301 -0
  33. package/dist/index.mjs +6 -0
  34. package/dist/languages-C0kEygG_.mjs +119 -0
  35. package/dist/markdown-BqKed1Vq.mjs +710 -0
  36. package/dist/markdown-DWuqfzps.mjs +2 -0
  37. package/dist/rolldown-runtime-CMFfr-1z.mjs +26 -0
  38. package/dist/server-Dkjk_D1Y.mjs +2628 -0
  39. package/dist/terminal-aKr5Xlp3.mjs +169 -0
  40. package/dist/themes-mEufQ_3e.mjs +2194 -0
  41. package/dist/twinkleplop.production-Coccf2Q9.mjs +2 -0
  42. package/dist/twinkleplop.production-DekYmX6O.mjs +4697 -0
  43. package/dist/twinkleplop.tokens-CgBUTCSg.mjs +76 -0
  44. package/package.json +133 -0
@@ -0,0 +1,2 @@
1
+ import { n as build } from "./build-Cv5aO0CB.mjs";
2
+ export { build };
@@ -0,0 +1,205 @@
1
+ import { D as join, E as extname, O as relative, S as getAssets, T as dirname, b as renderReadme, c as SKIPPED_GLOBS, f as isMarkdown, h as readDirectory, k as resolve, l as crumbsFor, m as mapLimit, o as createSearchIndex, r as createThemeStore, v as renderListing, w as basename, y as renderPage } from "./themes-mEufQ_3e.mjs";
2
+ import { n as glob } from "./dist-BvdNTrap.mjs";
3
+ import { t as createMarkdownRenderer } from "./markdown-BqKed1Vq.mjs";
4
+ import { existsSync } from "node:fs";
5
+ import { copyFile, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
6
+ //#region src/build.ts
7
+ /** The directory in the site for the files of comarkserv. */
8
+ const ASSETS_DIR = "_comarkserv";
9
+ const MARKER = `${ASSETS_DIR}/build.json`;
10
+ const CONCURRENCY = 16;
11
+ const EXTERNAL = /^(?:[a-z][a-z\d+.-]*:|\/\/|#|\?)/i;
12
+ /** Changes the path of a markdown file to the path of its HTML page. */
13
+ function toHtmlPath(path) {
14
+ return `${path.slice(0, path.length - extname(path).length)}.html`;
15
+ }
16
+ /**
17
+ * Returns a link transform for a page in `directory` (from the root, `""` for the root).
18
+ * Links to markdown files go to their HTML pages, and links to directories go to their `index.html`.
19
+ */
20
+ function staticLinkTransform(directory) {
21
+ return (href) => {
22
+ if (!href || EXTERNAL.test(href)) return href;
23
+ const cut = href.search(/[?#]/);
24
+ let path = cut < 0 ? href : href.slice(0, cut);
25
+ const suffix = cut < 0 ? "" : href.slice(cut);
26
+ if (path.startsWith("/")) {
27
+ const isDirectory = path.endsWith("/");
28
+ path = relative(`/${directory}`, path) || ".";
29
+ if (isDirectory) path = `${path}/`;
30
+ }
31
+ if (isMarkdown(path)) path = toHtmlPath(path);
32
+ else if (path.endsWith("/")) path = `${path}index.html`;
33
+ else if (path === "." || path === "..") path = `${path}/index.html`;
34
+ return path + suffix;
35
+ };
36
+ }
37
+ const staticLinks = {
38
+ directory: (name) => `${encodeURIComponent(name)}/index.html`,
39
+ markdown: (name) => encodeURIComponent(toHtmlPath(name))
40
+ };
41
+ async function prepareOutDir(outDir) {
42
+ if ((await readdir(outDir).catch(() => [])).length > 0) {
43
+ if (!existsSync(join(outDir, MARKER))) throw new Error(`The output directory ${outDir} is not empty, and it is not an earlier comarkserv build. Delete it, or choose another directory.`);
44
+ await rm(outDir, {
45
+ recursive: true,
46
+ force: true
47
+ });
48
+ }
49
+ await mkdir(join(outDir, ASSETS_DIR), { recursive: true });
50
+ }
51
+ function parentOf(path) {
52
+ const parent = dirname(path);
53
+ return parent === "." ? "" : parent;
54
+ }
55
+ async function write(path, content) {
56
+ await mkdir(dirname(path), { recursive: true });
57
+ await writeFile(path, content);
58
+ }
59
+ /** Builds a static HTML site from a directory. */
60
+ async function build(options = {}) {
61
+ const started = performance.now();
62
+ const root = resolve(options.root ?? process.cwd());
63
+ const outDir = resolve(options.outDir ?? "dist");
64
+ if (outDir === root || root.startsWith(`${outDir}/`)) throw new Error("The output directory must not be the root or a parent of the root.");
65
+ const themeStore = options.themeStore ?? createThemeStore();
66
+ const theme = await themeStore.load(options.theme ?? "github", process.cwd());
67
+ const warnings = [];
68
+ const catalog = options.themeCatalog === false ? void 0 : await themeStore.catalog().catch((error) => {
69
+ const reason = error instanceof Error ? error.message : String(error);
70
+ warnings.push(`The theme catalog is not available (${reason}). The theme picker shows only the built-in themes.`);
71
+ });
72
+ await prepareOutDir(outDir);
73
+ const dotfiles = options.dotfiles ?? false;
74
+ const rootName = basename(root) || root;
75
+ const render = createMarkdownRenderer(options);
76
+ const assets = getAssets();
77
+ const outInRoot = outDir.startsWith(`${root}/`) ? relative(root, outDir) : void 0;
78
+ const ignore = [...SKIPPED_GLOBS, ...outInRoot ? [`${outInRoot}/**`] : []];
79
+ const files = await glob(dotfiles ? ["**/*"] : ["**/*", ".well-known/**"], {
80
+ cwd: root,
81
+ dot: dotfiles,
82
+ ignore,
83
+ onlyFiles: true,
84
+ expandDirectories: false
85
+ });
86
+ const fileSet = new Set(files);
87
+ const directories = /* @__PURE__ */ new Set([""]);
88
+ for (const file of files) for (let directory = parentOf(file); directory; directory = parentOf(directory)) directories.add(directory);
89
+ let usesMath = false;
90
+ const page = (url, kind, input) => {
91
+ const prefix = "../".repeat(url.split("/").length - 1);
92
+ const base = `${prefix}${ASSETS_DIR}/`;
93
+ return renderPage({
94
+ ...input,
95
+ theme,
96
+ home: `${prefix}index.html`,
97
+ assets: {
98
+ css: `${base}app.css?v=${assets["app.css"].version}`,
99
+ js: `${base}app.js?v=${assets["app.js"].version}`,
100
+ katex: `${base}katex/katex.min.css?v=${assets.katexVersion}`
101
+ },
102
+ config: {
103
+ root: prefix,
104
+ search: `${base}search.json`,
105
+ events: "",
106
+ themes: catalog ? `${base}themes/catalog.json` : "",
107
+ edit: "",
108
+ share: "",
109
+ local: "",
110
+ source: `/${url}`,
111
+ kind
112
+ }
113
+ });
114
+ };
115
+ const crumbs = (pathname) => crumbsFor(pathname, rootName).map((crumb) => crumb.href === void 0 ? crumb : {
116
+ ...crumb,
117
+ href: `${crumb.href}index.html`
118
+ });
119
+ const renderMarkdown = async (file) => {
120
+ const source = await readFile(join(root, file), "utf8");
121
+ const rendered = await render(source, { transformLink: staticLinkTransform(parentOf(file)) });
122
+ usesMath ||= rendered.features.math;
123
+ return rendered;
124
+ };
125
+ const markdownPages = files.filter((file) => isMarkdown(file));
126
+ await mapLimit(markdownPages, CONCURRENCY, async (file) => {
127
+ const rendered = await renderMarkdown(file);
128
+ const url = toHtmlPath(file);
129
+ const directory = parentOf(file);
130
+ const isIndex = basename(file) === "index.md";
131
+ const html = page(url, "markdown", {
132
+ title: rendered.title ?? basename(file),
133
+ description: rendered.description,
134
+ content: rendered.html,
135
+ toc: rendered.toc,
136
+ crumbs: crumbs(isIndex ? `/${directory ? `${directory}/` : ""}` : `/${file}`),
137
+ features: rendered.features,
138
+ rawHref: encodeURIComponent(basename(file))
139
+ });
140
+ await write(join(outDir, url), html);
141
+ });
142
+ const listings = [...directories].filter((directory) => !fileSet.has(join(directory, "index.md")) && !fileSet.has(join(directory, "index.html")));
143
+ await mapLimit(listings, CONCURRENCY, async (directory) => {
144
+ const listing = await readDirectory(join(root, directory), {
145
+ dotfiles,
146
+ links: staticLinks
147
+ });
148
+ const entries = listing.entries.filter((entry) => {
149
+ const path = join(directory, entry.name);
150
+ return entry.kind === "dir" ? directories.has(path) : fileSet.has(path);
151
+ });
152
+ let content = renderListing(entries, directory ? "../index.html" : void 0);
153
+ let readme;
154
+ if (listing.readme) {
155
+ readme = await renderMarkdown(join(directory, listing.readme));
156
+ content += renderReadme(listing.readme, readme.html);
157
+ }
158
+ const url = join(directory, "index.html");
159
+ const html = page(url, "directory", {
160
+ title: directory ? `${directory}/` : rootName,
161
+ content,
162
+ contentClass: "cms-directory",
163
+ toc: readme?.toc,
164
+ crumbs: crumbs(`/${directory ? `${directory}/` : ""}`),
165
+ features: readme?.features
166
+ });
167
+ await write(join(outDir, url), html);
168
+ });
169
+ await mapLimit(files, 32, async (file) => {
170
+ await mkdir(join(outDir, parentOf(file)), { recursive: true });
171
+ if (isMarkdown(file) || !existsSync(join(outDir, file))) await copyFile(join(root, file), join(outDir, file));
172
+ });
173
+ const search = createSearchIndex({
174
+ root,
175
+ dotfiles,
176
+ ignore,
177
+ toUrl: toHtmlPath
178
+ });
179
+ await Promise.all([
180
+ write(join(outDir, ASSETS_DIR, "app.css"), assets["app.css"].body),
181
+ write(join(outDir, ASSETS_DIR, "app.js"), assets["app.js"].body),
182
+ write(join(outDir, ASSETS_DIR, "search.json"), JSON.stringify(await search.get())),
183
+ ...catalog ? [write(join(outDir, ASSETS_DIR, "themes", "catalog.json"), JSON.stringify(catalog))] : [],
184
+ write(join(outDir, MARKER), JSON.stringify({
185
+ generator: "comarkserv",
186
+ date: (/* @__PURE__ */ new Date()).toISOString()
187
+ }))
188
+ ]);
189
+ if (usesMath) {
190
+ const katexFiles = await glob(["katex.min.css", "fonts/*.woff2"], { cwd: assets.katexDir });
191
+ await Promise.all(katexFiles.map(async (file) => {
192
+ await mkdir(dirname(join(outDir, ASSETS_DIR, "katex", file)), { recursive: true });
193
+ await copyFile(join(assets.katexDir, file), join(outDir, ASSETS_DIR, "katex", file));
194
+ }));
195
+ }
196
+ return {
197
+ outDir,
198
+ pages: markdownPages.length + listings.length,
199
+ files: files.length - markdownPages.length,
200
+ ms: performance.now() - started,
201
+ warnings
202
+ };
203
+ }
204
+ //#endregion
205
+ export { toHtmlPath as i, build as n, staticLinkTransform as r, ASSETS_DIR as t };
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export {}