mdzilla 0.0.2 → 0.0.3
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/_chunks/exporter.mjs +35 -22
- package/dist/cli/main.mjs +2 -2
- package/dist/index.d.mts +16 -11
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
2
2
|
import { basename, dirname, extname, join } from "node:path";
|
|
3
|
-
import { parseMeta, renderToText } from "md4x";
|
|
3
|
+
import { parseMeta, renderToMarkdown, renderToText } from "md4x";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
//#region src/docs/manager.ts
|
|
@@ -763,25 +763,38 @@ async function npmProvider(input) {
|
|
|
763
763
|
}
|
|
764
764
|
//#endregion
|
|
765
765
|
//#region src/docs/exporter.ts
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
766
|
+
/** Paths to skip during export (generated by source, not actual docs) */
|
|
767
|
+
const IGNORED_PATHS = new Set(["/llms.txt", "/llms-full.txt"]);
|
|
768
|
+
/**
|
|
769
|
+
* Export documentation entries to a local filesystem directory as flat `.md` files.
|
|
770
|
+
*
|
|
771
|
+
* Each entry is written to `<dir>/<path>.md`. Directory stubs (`page === false`)
|
|
772
|
+
* are skipped by default unless a custom `filter` is provided.
|
|
773
|
+
*
|
|
774
|
+
* A `README.md` table of contents is generated at the root of the output directory.
|
|
775
|
+
*/
|
|
776
|
+
async function exportDocsToFS(manager, dir, options = {}) {
|
|
777
|
+
const rootEntry = manager.flat.find((f) => f.entry.path === "/");
|
|
778
|
+
const tocLines = [`# ${options.title ?? rootEntry?.entry.title ?? "Table of Contents"}`, ""];
|
|
779
|
+
const writtenFiles = /* @__PURE__ */ new Set();
|
|
780
|
+
for (const flat of manager.flat) {
|
|
781
|
+
if (options.filter ? !options.filter(flat) : flat.entry.page === false) continue;
|
|
782
|
+
if (IGNORED_PATHS.has(flat.entry.path)) continue;
|
|
783
|
+
let content = await manager.getContent(flat);
|
|
784
|
+
if (content === void 0) continue;
|
|
785
|
+
const cleanContent = options.plainText ? renderToText(content) : renderToMarkdown(content);
|
|
786
|
+
const filePath = flat.entry.path === "/" ? "/index.md" : flat.entry.path.endsWith(".md") ? flat.entry.path : `${flat.entry.path}.md`;
|
|
787
|
+
const dest = join(dir, filePath);
|
|
788
|
+
await mkdir(dirname(dest), { recursive: true });
|
|
789
|
+
await writeFile(dest, cleanContent, "utf8");
|
|
790
|
+
writtenFiles.add(filePath.slice(1));
|
|
791
|
+
const indent = " ".repeat(flat.depth);
|
|
792
|
+
const desc = flat.entry.description ? `: ${flat.entry.description}` : "";
|
|
793
|
+
tocLines.push(`${indent}- [${flat.entry.title}](.${filePath})${desc}`);
|
|
794
|
+
}
|
|
795
|
+
let tocFile = options.tocFile ?? "README.md";
|
|
796
|
+
if (writtenFiles.has(tocFile)) tocFile = `_${tocFile}`;
|
|
797
|
+
await writeFile(join(dir, tocFile), tocLines.join("\n") + "\n", "utf8");
|
|
798
|
+
}
|
|
786
799
|
//#endregion
|
|
787
|
-
export {
|
|
800
|
+
export { DocsSourceFS as a, DocsSourceGit as i, DocsSourceNpm as n, DocsSource as o, DocsSourceHTTP as r, DocsManager as s, exportDocsToFS as t };
|
package/dist/cli/main.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as DocsSourceFS, i as DocsSourceGit, n as DocsSourceNpm, r as DocsSourceHTTP, s as DocsManager, t as exportDocsToFS } from "../_chunks/exporter.mjs";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { basename } from "node:path";
|
|
5
5
|
import { parseMeta, renderToAnsi, renderToText } from "md4x";
|
|
@@ -765,7 +765,7 @@ async function main() {
|
|
|
765
765
|
const docs = new DocsManager(isURL ? new DocsSourceHTTP(docsDir) : docsDir.startsWith("gh:") ? new DocsSourceGit(docsDir) : docsDir.startsWith("npm:") ? new DocsSourceNpm(docsDir) : new DocsSourceFS(docsDir));
|
|
766
766
|
await docs.load();
|
|
767
767
|
if (exportDir) {
|
|
768
|
-
await
|
|
768
|
+
await exportDocsToFS(docs, exportDir, { plainText: plain });
|
|
769
769
|
console.log(`Exported ${docs.pages.length} pages to ${exportDir}`);
|
|
770
770
|
return;
|
|
771
771
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -144,18 +144,23 @@ declare class DocsManager {
|
|
|
144
144
|
//#endregion
|
|
145
145
|
//#region src/docs/exporter.d.ts
|
|
146
146
|
interface ExportOptions {
|
|
147
|
-
/**
|
|
148
|
-
|
|
147
|
+
/** Custom filter callback. Return false to skip an entry. Default: skip stubs (page === false) */
|
|
148
|
+
filter?: (entry: FlatEntry) => boolean;
|
|
149
149
|
/** Compile markdown to plain text using md4x. Default: false */
|
|
150
150
|
plainText?: boolean;
|
|
151
|
+
/** Filename for the generated table of contents. Default: "README.md" */
|
|
152
|
+
tocFile?: string;
|
|
153
|
+
/** Title for the table of contents. Default: root entry title or "Table of Contents" */
|
|
154
|
+
title?: string;
|
|
151
155
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Export documentation entries to a local filesystem directory as flat `.md` files.
|
|
158
|
+
*
|
|
159
|
+
* Each entry is written to `<dir>/<path>.md`. Directory stubs (`page === false`)
|
|
160
|
+
* are skipped by default unless a custom `filter` is provided.
|
|
161
|
+
*
|
|
162
|
+
* A `README.md` table of contents is generated at the root of the output directory.
|
|
163
|
+
*/
|
|
164
|
+
declare function exportDocsToFS(manager: DocsManager, dir: string, options?: ExportOptions): Promise<void>;
|
|
160
165
|
//#endregion
|
|
161
|
-
export {
|
|
166
|
+
export { DocsManager, DocsSource, DocsSourceFS, DocsSourceGit, type DocsSourceGitOptions, DocsSourceHTTP, type DocsSourceHTTPOptions, DocsSourceNpm, type DocsSourceNpmOptions, type ExportOptions, type FlatEntry, type NavEntry, exportDocsToFS };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export {
|
|
1
|
+
import { a as DocsSourceFS, i as DocsSourceGit, n as DocsSourceNpm, o as DocsSource, r as DocsSourceHTTP, s as DocsManager, t as exportDocsToFS } from "./_chunks/exporter.mjs";
|
|
2
|
+
export { DocsManager, DocsSource, DocsSourceFS, DocsSourceGit, DocsSourceHTTP, DocsSourceNpm, exportDocsToFS };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdzilla",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "pi0/mdzilla",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@speed-highlight/core": "^1.2.14",
|
|
34
34
|
"giget": "^3.1.2",
|
|
35
|
-
"md4x": ">=0.0.
|
|
35
|
+
"md4x": ">=0.0.22",
|
|
36
36
|
"mdream": "^0.16.0",
|
|
37
37
|
"std-env": "4.0.0-rc.1"
|
|
38
38
|
},
|