mdzilla 0.1.0 → 0.2.1
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/README.md +66 -59
- package/dist/_chunks/exporter.mjs +220 -52
- package/dist/_chunks/server.mjs +649 -446
- package/dist/cli/main.mjs +149 -604
- package/dist/index.d.mts +123 -64
- package/dist/index.mjs +2 -2
- package/package.json +8 -8
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/nav.d.ts
|
|
2
2
|
interface NavEntry {
|
|
3
3
|
/** URL-friendly path segment (without numeric prefix) */
|
|
4
4
|
slug: string;
|
|
@@ -20,38 +20,116 @@ interface NavEntry {
|
|
|
20
20
|
[key: string]: unknown;
|
|
21
21
|
}
|
|
22
22
|
//#endregion
|
|
23
|
-
//#region src/
|
|
24
|
-
|
|
23
|
+
//#region src/sources/_base.d.ts
|
|
24
|
+
type WatchCallback = (event: {
|
|
25
|
+
path: string;
|
|
26
|
+
}) => void;
|
|
27
|
+
declare abstract class Source {
|
|
25
28
|
abstract load(): Promise<{
|
|
26
29
|
tree: NavEntry[];
|
|
27
30
|
fileMap: Map<string, string>;
|
|
28
31
|
}>;
|
|
29
32
|
abstract readContent(filePath: string): Promise<string>;
|
|
33
|
+
/** Start watching for file changes. Override in sources that support it. */
|
|
34
|
+
watch(_callback: WatchCallback): void;
|
|
35
|
+
/** Stop watching. Override in sources that support it. */
|
|
36
|
+
unwatch(): void;
|
|
30
37
|
}
|
|
31
38
|
//#endregion
|
|
32
|
-
//#region src/
|
|
33
|
-
|
|
39
|
+
//#region src/collection.d.ts
|
|
40
|
+
interface ContentMatch {
|
|
41
|
+
line: number;
|
|
42
|
+
text: string;
|
|
43
|
+
context: string[];
|
|
44
|
+
}
|
|
45
|
+
interface SearchResult {
|
|
46
|
+
flat: FlatEntry;
|
|
47
|
+
score: number;
|
|
48
|
+
titleMatch: boolean;
|
|
49
|
+
heading?: string;
|
|
50
|
+
contentMatches: ContentMatch[];
|
|
51
|
+
}
|
|
52
|
+
interface FlatEntry {
|
|
53
|
+
entry: NavEntry;
|
|
54
|
+
depth: number;
|
|
55
|
+
filePath?: string;
|
|
56
|
+
}
|
|
57
|
+
declare class Collection {
|
|
58
|
+
source: Source;
|
|
59
|
+
tree: NavEntry[];
|
|
60
|
+
flat: FlatEntry[];
|
|
61
|
+
private _fileMap;
|
|
62
|
+
private _contentCache;
|
|
63
|
+
private _changeListeners;
|
|
64
|
+
private _reloadTimer?;
|
|
65
|
+
constructor(source: Source);
|
|
66
|
+
load(): Promise<void>;
|
|
67
|
+
reload(): Promise<void>;
|
|
68
|
+
/** Start watching source for changes. Debounces, reloads collection, and notifies listeners. */
|
|
69
|
+
watch(): void;
|
|
70
|
+
/** Stop watching source. */
|
|
71
|
+
unwatch(): void;
|
|
72
|
+
/** Register a change listener. Returns unsubscribe function. */
|
|
73
|
+
onChange(listener: (path: string) => void): () => void;
|
|
74
|
+
/** Get raw file content for a flat entry (cached). */
|
|
75
|
+
getContent(entry: FlatEntry): Promise<string | undefined>;
|
|
76
|
+
/** Invalidate cached content for a specific file path. */
|
|
77
|
+
invalidate(filePath: string): void;
|
|
78
|
+
/** Fuzzy filter flat entries by query string (title and path only). */
|
|
79
|
+
filter(query: string): FlatEntry[];
|
|
80
|
+
/** Search flat entries by query string, including page contents. Yields scored results as found. */
|
|
81
|
+
search(query: string): AsyncIterable<SearchResult>;
|
|
82
|
+
/** Flat entries that are navigable pages (excludes directory stubs). */
|
|
83
|
+
get pages(): FlatEntry[];
|
|
84
|
+
/** Find a flat entry by path (exact or with trailing slash). */
|
|
85
|
+
findByPath(path: string): FlatEntry | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Resolve a page path to its content, trying:
|
|
88
|
+
* 1. Exact match in the navigation tree
|
|
89
|
+
* 2. Stripped common prefix (e.g., /docs/guide/... → /guide/...)
|
|
90
|
+
* 3. Direct source fetch (for HTTP sources with uncrawled paths)
|
|
91
|
+
*/
|
|
92
|
+
resolvePage(path: string): Promise<{
|
|
93
|
+
entry?: FlatEntry;
|
|
94
|
+
raw?: string;
|
|
95
|
+
}>;
|
|
96
|
+
/** Suggest related pages for a query (fuzzy + keyword fallback). */
|
|
97
|
+
suggest(query: string, max?: number): FlatEntry[];
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/utils.d.ts
|
|
101
|
+
/** Extract short text snippets around matching terms. */
|
|
102
|
+
declare function extractSnippets(content: string, terms: string[], opts?: {
|
|
103
|
+
maxSnippets?: number;
|
|
104
|
+
radius?: number;
|
|
105
|
+
}): string[];
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/sources/fs.d.ts
|
|
108
|
+
declare class FSSource extends Source {
|
|
34
109
|
dir: string;
|
|
110
|
+
private _watcher?;
|
|
35
111
|
constructor(dir: string);
|
|
36
112
|
load(): Promise<{
|
|
37
113
|
tree: NavEntry[];
|
|
38
114
|
fileMap: Map<string, string>;
|
|
39
115
|
}>;
|
|
40
116
|
readContent(filePath: string): Promise<string>;
|
|
117
|
+
watch(callback: WatchCallback): void;
|
|
118
|
+
unwatch(): void;
|
|
41
119
|
}
|
|
42
120
|
//#endregion
|
|
43
|
-
//#region src/
|
|
44
|
-
interface
|
|
121
|
+
//#region src/sources/git.d.ts
|
|
122
|
+
interface GitSourceOptions {
|
|
45
123
|
/** Authorization token for private repos */
|
|
46
124
|
auth?: string;
|
|
47
125
|
/** Subdirectory within the repo containing docs */
|
|
48
126
|
subdir?: string;
|
|
49
127
|
}
|
|
50
|
-
declare class
|
|
128
|
+
declare class GitSource extends Source {
|
|
51
129
|
src: string;
|
|
52
|
-
options:
|
|
130
|
+
options: GitSourceOptions;
|
|
53
131
|
private _fs?;
|
|
54
|
-
constructor(src: string, options?:
|
|
132
|
+
constructor(src: string, options?: GitSourceOptions);
|
|
55
133
|
load(): Promise<{
|
|
56
134
|
tree: NavEntry[];
|
|
57
135
|
fileMap: Map<string, string>;
|
|
@@ -59,19 +137,19 @@ declare class DocsSourceGit extends DocsSource {
|
|
|
59
137
|
readContent(filePath: string): Promise<string>;
|
|
60
138
|
}
|
|
61
139
|
//#endregion
|
|
62
|
-
//#region src/
|
|
63
|
-
interface
|
|
140
|
+
//#region src/sources/http.d.ts
|
|
141
|
+
interface HTTPSourceOptions {
|
|
64
142
|
/** Additional headers to send with each request */
|
|
65
143
|
headers?: Record<string, string>;
|
|
66
144
|
}
|
|
67
|
-
declare class
|
|
145
|
+
declare class HTTPSource extends Source {
|
|
68
146
|
url: string;
|
|
69
|
-
options:
|
|
147
|
+
options: HTTPSourceOptions;
|
|
70
148
|
private _contentCache;
|
|
71
149
|
private _tree;
|
|
72
150
|
private _fileMap;
|
|
73
151
|
private _npmPackage?;
|
|
74
|
-
constructor(url: string, options?:
|
|
152
|
+
constructor(url: string, options?: HTTPSourceOptions);
|
|
75
153
|
load(): Promise<{
|
|
76
154
|
tree: NavEntry[];
|
|
77
155
|
fileMap: Map<string, string>;
|
|
@@ -86,16 +164,16 @@ declare class DocsSourceHTTP extends DocsSource {
|
|
|
86
164
|
private _fetch;
|
|
87
165
|
}
|
|
88
166
|
//#endregion
|
|
89
|
-
//#region src/
|
|
90
|
-
interface
|
|
167
|
+
//#region src/sources/npm.d.ts
|
|
168
|
+
interface NpmSourceOptions {
|
|
91
169
|
/** Subdirectory within the package containing docs */
|
|
92
170
|
subdir?: string;
|
|
93
171
|
}
|
|
94
|
-
declare class
|
|
172
|
+
declare class NpmSource extends Source {
|
|
95
173
|
src: string;
|
|
96
|
-
options:
|
|
174
|
+
options: NpmSourceOptions;
|
|
97
175
|
private _fs?;
|
|
98
|
-
constructor(src: string, options?:
|
|
176
|
+
constructor(src: string, options?: NpmSourceOptions);
|
|
99
177
|
load(): Promise<{
|
|
100
178
|
tree: NavEntry[];
|
|
101
179
|
fileMap: Map<string, string>;
|
|
@@ -103,46 +181,15 @@ declare class DocsSourceNpm extends DocsSource {
|
|
|
103
181
|
readContent(filePath: string): Promise<string>;
|
|
104
182
|
}
|
|
105
183
|
//#endregion
|
|
106
|
-
//#region src/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
declare
|
|
113
|
-
source: DocsSource;
|
|
114
|
-
tree: NavEntry[];
|
|
115
|
-
flat: FlatEntry[];
|
|
116
|
-
private _fileMap;
|
|
117
|
-
private _contentCache;
|
|
118
|
-
constructor(source: DocsSource);
|
|
119
|
-
load(): Promise<void>;
|
|
120
|
-
reload(): Promise<void>;
|
|
121
|
-
/** Get raw file content for a flat entry (cached). */
|
|
122
|
-
getContent(entry: FlatEntry): Promise<string | undefined>;
|
|
123
|
-
/** Invalidate cached content for a specific file path. */
|
|
124
|
-
invalidate(filePath: string): void;
|
|
125
|
-
/** Fuzzy filter flat entries by query string. */
|
|
126
|
-
filter(query: string): FlatEntry[];
|
|
127
|
-
/** Flat entries that are navigable pages (excludes directory stubs). */
|
|
128
|
-
get pages(): FlatEntry[];
|
|
129
|
-
/** Find a flat entry by path (exact or with trailing slash). */
|
|
130
|
-
findByPath(path: string): FlatEntry | undefined;
|
|
131
|
-
/**
|
|
132
|
-
* Resolve a page path to its content, trying:
|
|
133
|
-
* 1. Exact match in the navigation tree
|
|
134
|
-
* 2. Stripped common prefix (e.g., /docs/guide/... → /guide/...)
|
|
135
|
-
* 3. Direct source fetch (for HTTP sources with uncrawled paths)
|
|
136
|
-
*/
|
|
137
|
-
resolvePage(path: string): Promise<{
|
|
138
|
-
entry?: FlatEntry;
|
|
139
|
-
raw?: string;
|
|
140
|
-
}>;
|
|
141
|
-
/** Return indices of matching flat entries (case-insensitive substring). */
|
|
142
|
-
matchIndices(query: string): number[];
|
|
143
|
-
}
|
|
184
|
+
//#region src/source.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Resolve a source string to the appropriate Source instance.
|
|
187
|
+
*
|
|
188
|
+
* Supports: local paths, `gh:owner/repo`, `npm:package`, `http(s)://...`
|
|
189
|
+
*/
|
|
190
|
+
declare function resolveSource(input: string): Source;
|
|
144
191
|
//#endregion
|
|
145
|
-
//#region src/
|
|
192
|
+
//#region src/exporter.d.ts
|
|
146
193
|
interface ExportOptions {
|
|
147
194
|
/** Custom filter callback. Return false to skip an entry. Default: skip stubs (page === false) */
|
|
148
195
|
filter?: (entry: FlatEntry) => boolean;
|
|
@@ -153,15 +200,27 @@ interface ExportOptions {
|
|
|
153
200
|
/** Title for the table of contents. Default: root entry title or "Table of Contents" */
|
|
154
201
|
title?: string;
|
|
155
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* High-level export: resolve source, load, and export in one call.
|
|
205
|
+
*
|
|
206
|
+
* ```ts
|
|
207
|
+
* await exportSource("./docs", "./dist/docs");
|
|
208
|
+
* await exportSource("gh:unjs/h3", "./dist/h3-docs");
|
|
209
|
+
* await exportSource("npm:h3", "./dist/h3-docs", { plainText: true });
|
|
210
|
+
* await exportSource("https://h3.unjs.io", "./dist/h3-docs");
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
declare function exportSource(input: string | Source, dir: string, options?: ExportOptions): Promise<Collection>;
|
|
156
214
|
/**
|
|
157
215
|
* Export documentation entries to a local filesystem directory as flat `.md` files.
|
|
158
216
|
*
|
|
159
|
-
* Each entry is written to `<dir>/<
|
|
160
|
-
* index pages). Navigation order is preserved via
|
|
161
|
-
*
|
|
217
|
+
* Each entry is written to `<dir>/<prefix>.<slug>.md` (or `<dir>/<prefix>.<slug>/index.md`
|
|
218
|
+
* for directory index pages). Navigation order is preserved via numeric prefixes on
|
|
219
|
+
* directories and files (e.g., `1.guide/`, `2.getting-started.md`) so the nav scanner
|
|
220
|
+
* can infer order without additional metadata files.
|
|
162
221
|
*
|
|
163
222
|
* A `README.md` table of contents is generated at the root of the output directory.
|
|
164
223
|
*/
|
|
165
|
-
declare function
|
|
224
|
+
declare function writeCollection(collection: Collection, dir: string, options?: ExportOptions): Promise<void>;
|
|
166
225
|
//#endregion
|
|
167
|
-
export {
|
|
226
|
+
export { Collection, type ExportOptions, FSSource, type FlatEntry, GitSource, type GitSourceOptions, HTTPSource, type HTTPSourceOptions, type NavEntry, NpmSource, type NpmSourceOptions, type SearchResult, Source, exportSource, extractSnippets, resolveSource, writeCollection };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export {
|
|
1
|
+
import { a as HTTPSource, c as Source, i as NpmSource, l as extractSnippets, n as writeCollection, o as GitSource, r as resolveSource, s as FSSource, t as exportSource, u as Collection } from "./_chunks/exporter.mjs";
|
|
2
|
+
export { Collection, FSSource, GitSource, HTTPSource, NpmSource, Source, exportSource, extractSnippets, resolveSource, writeCollection };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdzilla",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "pi0/mdzilla",
|
|
@@ -31,22 +31,22 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@speed-highlight/core": "^1.2.15",
|
|
34
|
-
"giget": "^3.
|
|
34
|
+
"giget": "^3.2.0",
|
|
35
35
|
"md4x": "^0.0.25",
|
|
36
36
|
"srvx": "^0.11.13",
|
|
37
37
|
"std-env": "^4.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "^25.5.0",
|
|
41
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
42
|
-
"@vitest/coverage-v8": "^4.1.
|
|
41
|
+
"@typescript/native-preview": "^7.0.0-dev.20260327.2",
|
|
42
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
43
43
|
"automd": "^0.4.3",
|
|
44
44
|
"changelogen": "^0.6.2",
|
|
45
45
|
"obuild": "^0.4.32",
|
|
46
|
-
"oxfmt": "^0.
|
|
47
|
-
"oxlint": "^1.
|
|
46
|
+
"oxfmt": "^0.42.0",
|
|
47
|
+
"oxlint": "^1.57.0",
|
|
48
48
|
"typescript": "^6.0.2",
|
|
49
|
-
"vitest": "^4.1.
|
|
49
|
+
"vitest": "^4.1.2"
|
|
50
50
|
},
|
|
51
|
-
"packageManager": "pnpm@10.
|
|
51
|
+
"packageManager": "pnpm@10.33.0"
|
|
52
52
|
}
|