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/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/docs/nav.d.ts
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/docs/sources/_base.d.ts
24
- declare abstract class DocsSource {
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/docs/sources/fs.d.ts
33
- declare class DocsSourceFS extends DocsSource {
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/docs/sources/git.d.ts
44
- interface DocsSourceGitOptions {
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 DocsSourceGit extends DocsSource {
128
+ declare class GitSource extends Source {
51
129
  src: string;
52
- options: DocsSourceGitOptions;
130
+ options: GitSourceOptions;
53
131
  private _fs?;
54
- constructor(src: string, options?: DocsSourceGitOptions);
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/docs/sources/http.d.ts
63
- interface DocsSourceHTTPOptions {
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 DocsSourceHTTP extends DocsSource {
145
+ declare class HTTPSource extends Source {
68
146
  url: string;
69
- options: DocsSourceHTTPOptions;
147
+ options: HTTPSourceOptions;
70
148
  private _contentCache;
71
149
  private _tree;
72
150
  private _fileMap;
73
151
  private _npmPackage?;
74
- constructor(url: string, options?: DocsSourceHTTPOptions);
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/docs/sources/npm.d.ts
90
- interface DocsSourceNpmOptions {
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 DocsSourceNpm extends DocsSource {
172
+ declare class NpmSource extends Source {
95
173
  src: string;
96
- options: DocsSourceNpmOptions;
174
+ options: NpmSourceOptions;
97
175
  private _fs?;
98
- constructor(src: string, options?: DocsSourceNpmOptions);
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/docs/manager.d.ts
107
- interface FlatEntry {
108
- entry: NavEntry;
109
- depth: number;
110
- filePath?: string;
111
- }
112
- declare class DocsManager {
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/docs/exporter.d.ts
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>/<path>.md` (or `<dir>/<path>/index.md` for directory
160
- * index pages). Navigation order is preserved via `order` frontmatter in pages and
161
- * `.navigation.yml` files in directories.
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 exportDocsToFS(manager: DocsManager, dir: string, options?: ExportOptions): Promise<void>;
224
+ declare function writeCollection(collection: Collection, dir: string, options?: ExportOptions): Promise<void>;
166
225
  //#endregion
167
- export { DocsManager, DocsSource, DocsSourceFS, DocsSourceGit, type DocsSourceGitOptions, DocsSourceHTTP, type DocsSourceHTTPOptions, DocsSourceNpm, type DocsSourceNpmOptions, type ExportOptions, type FlatEntry, type NavEntry, exportDocsToFS };
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 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 };
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.0",
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.1.2",
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.20260324.1",
42
- "@vitest/coverage-v8": "^4.1.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.41.0",
47
- "oxlint": "^1.56.0",
46
+ "oxfmt": "^0.42.0",
47
+ "oxlint": "^1.57.0",
48
48
  "typescript": "^6.0.2",
49
- "vitest": "^4.1.1"
49
+ "vitest": "^4.1.2"
50
50
  },
51
- "packageManager": "pnpm@10.32.1"
51
+ "packageManager": "pnpm@10.33.0"
52
52
  }