mdzilla 0.0.6 → 0.2.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.
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,8 +20,8 @@ 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
+ declare abstract class Source {
25
25
  abstract load(): Promise<{
26
26
  tree: NavEntry[];
27
27
  fileMap: Map<string, string>;
@@ -29,8 +29,68 @@ declare abstract class DocsSource {
29
29
  abstract readContent(filePath: string): Promise<string>;
30
30
  }
31
31
  //#endregion
32
- //#region src/docs/sources/fs.d.ts
33
- declare class DocsSourceFS extends DocsSource {
32
+ //#region src/collection.d.ts
33
+ interface ContentMatch {
34
+ line: number;
35
+ text: string;
36
+ context: string[];
37
+ }
38
+ interface SearchResult {
39
+ flat: FlatEntry;
40
+ score: number;
41
+ titleMatch: boolean;
42
+ heading?: string;
43
+ contentMatches: ContentMatch[];
44
+ }
45
+ interface FlatEntry {
46
+ entry: NavEntry;
47
+ depth: number;
48
+ filePath?: string;
49
+ }
50
+ declare class Collection {
51
+ source: Source;
52
+ tree: NavEntry[];
53
+ flat: FlatEntry[];
54
+ private _fileMap;
55
+ private _contentCache;
56
+ constructor(source: Source);
57
+ load(): Promise<void>;
58
+ reload(): Promise<void>;
59
+ /** Get raw file content for a flat entry (cached). */
60
+ getContent(entry: FlatEntry): Promise<string | undefined>;
61
+ /** Invalidate cached content for a specific file path. */
62
+ invalidate(filePath: string): void;
63
+ /** Fuzzy filter flat entries by query string (title and path only). */
64
+ filter(query: string): FlatEntry[];
65
+ /** Search flat entries by query string, including page contents. Yields scored results as found. */
66
+ search(query: string): AsyncIterable<SearchResult>;
67
+ /** Flat entries that are navigable pages (excludes directory stubs). */
68
+ get pages(): FlatEntry[];
69
+ /** Find a flat entry by path (exact or with trailing slash). */
70
+ findByPath(path: string): FlatEntry | undefined;
71
+ /**
72
+ * Resolve a page path to its content, trying:
73
+ * 1. Exact match in the navigation tree
74
+ * 2. Stripped common prefix (e.g., /docs/guide/... → /guide/...)
75
+ * 3. Direct source fetch (for HTTP sources with uncrawled paths)
76
+ */
77
+ resolvePage(path: string): Promise<{
78
+ entry?: FlatEntry;
79
+ raw?: string;
80
+ }>;
81
+ /** Suggest related pages for a query (fuzzy + keyword fallback). */
82
+ suggest(query: string, max?: number): FlatEntry[];
83
+ }
84
+ //#endregion
85
+ //#region src/utils.d.ts
86
+ /** Extract short text snippets around matching terms. */
87
+ declare function extractSnippets(content: string, terms: string[], opts?: {
88
+ maxSnippets?: number;
89
+ radius?: number;
90
+ }): string[];
91
+ //#endregion
92
+ //#region src/sources/fs.d.ts
93
+ declare class FSSource extends Source {
34
94
  dir: string;
35
95
  constructor(dir: string);
36
96
  load(): Promise<{
@@ -40,18 +100,18 @@ declare class DocsSourceFS extends DocsSource {
40
100
  readContent(filePath: string): Promise<string>;
41
101
  }
42
102
  //#endregion
43
- //#region src/docs/sources/git.d.ts
44
- interface DocsSourceGitOptions {
103
+ //#region src/sources/git.d.ts
104
+ interface GitSourceOptions {
45
105
  /** Authorization token for private repos */
46
106
  auth?: string;
47
107
  /** Subdirectory within the repo containing docs */
48
108
  subdir?: string;
49
109
  }
50
- declare class DocsSourceGit extends DocsSource {
110
+ declare class GitSource extends Source {
51
111
  src: string;
52
- options: DocsSourceGitOptions;
112
+ options: GitSourceOptions;
53
113
  private _fs?;
54
- constructor(src: string, options?: DocsSourceGitOptions);
114
+ constructor(src: string, options?: GitSourceOptions);
55
115
  load(): Promise<{
56
116
  tree: NavEntry[];
57
117
  fileMap: Map<string, string>;
@@ -59,19 +119,19 @@ declare class DocsSourceGit extends DocsSource {
59
119
  readContent(filePath: string): Promise<string>;
60
120
  }
61
121
  //#endregion
62
- //#region src/docs/sources/http.d.ts
63
- interface DocsSourceHTTPOptions {
122
+ //#region src/sources/http.d.ts
123
+ interface HTTPSourceOptions {
64
124
  /** Additional headers to send with each request */
65
125
  headers?: Record<string, string>;
66
126
  }
67
- declare class DocsSourceHTTP extends DocsSource {
127
+ declare class HTTPSource extends Source {
68
128
  url: string;
69
- options: DocsSourceHTTPOptions;
129
+ options: HTTPSourceOptions;
70
130
  private _contentCache;
71
131
  private _tree;
72
132
  private _fileMap;
73
133
  private _npmPackage?;
74
- constructor(url: string, options?: DocsSourceHTTPOptions);
134
+ constructor(url: string, options?: HTTPSourceOptions);
75
135
  load(): Promise<{
76
136
  tree: NavEntry[];
77
137
  fileMap: Map<string, string>;
@@ -86,16 +146,16 @@ declare class DocsSourceHTTP extends DocsSource {
86
146
  private _fetch;
87
147
  }
88
148
  //#endregion
89
- //#region src/docs/sources/npm.d.ts
90
- interface DocsSourceNpmOptions {
149
+ //#region src/sources/npm.d.ts
150
+ interface NpmSourceOptions {
91
151
  /** Subdirectory within the package containing docs */
92
152
  subdir?: string;
93
153
  }
94
- declare class DocsSourceNpm extends DocsSource {
154
+ declare class NpmSource extends Source {
95
155
  src: string;
96
- options: DocsSourceNpmOptions;
156
+ options: NpmSourceOptions;
97
157
  private _fs?;
98
- constructor(src: string, options?: DocsSourceNpmOptions);
158
+ constructor(src: string, options?: NpmSourceOptions);
99
159
  load(): Promise<{
100
160
  tree: NavEntry[];
101
161
  fileMap: Map<string, string>;
@@ -103,46 +163,15 @@ declare class DocsSourceNpm extends DocsSource {
103
163
  readContent(filePath: string): Promise<string>;
104
164
  }
105
165
  //#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
- }
166
+ //#region src/source.d.ts
167
+ /**
168
+ * Resolve a source string to the appropriate Source instance.
169
+ *
170
+ * Supports: local paths, `gh:owner/repo`, `npm:package`, `http(s)://...`
171
+ */
172
+ declare function resolveSource(input: string): Source;
144
173
  //#endregion
145
- //#region src/docs/exporter.d.ts
174
+ //#region src/exporter.d.ts
146
175
  interface ExportOptions {
147
176
  /** Custom filter callback. Return false to skip an entry. Default: skip stubs (page === false) */
148
177
  filter?: (entry: FlatEntry) => boolean;
@@ -153,15 +182,27 @@ interface ExportOptions {
153
182
  /** Title for the table of contents. Default: root entry title or "Table of Contents" */
154
183
  title?: string;
155
184
  }
185
+ /**
186
+ * High-level export: resolve source, load, and export in one call.
187
+ *
188
+ * ```ts
189
+ * await exportSource("./docs", "./dist/docs");
190
+ * await exportSource("gh:unjs/h3", "./dist/h3-docs");
191
+ * await exportSource("npm:h3", "./dist/h3-docs", { plainText: true });
192
+ * await exportSource("https://h3.unjs.io", "./dist/h3-docs");
193
+ * ```
194
+ */
195
+ declare function exportSource(input: string | Source, dir: string, options?: ExportOptions): Promise<Collection>;
156
196
  /**
157
197
  * Export documentation entries to a local filesystem directory as flat `.md` files.
158
198
  *
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.
199
+ * Each entry is written to `<dir>/<prefix>.<slug>.md` (or `<dir>/<prefix>.<slug>/index.md`
200
+ * for directory index pages). Navigation order is preserved via numeric prefixes on
201
+ * directories and files (e.g., `1.guide/`, `2.getting-started.md`) so the nav scanner
202
+ * can infer order without additional metadata files.
162
203
  *
163
204
  * A `README.md` table of contents is generated at the root of the output directory.
164
205
  */
165
- declare function exportDocsToFS(manager: DocsManager, dir: string, options?: ExportOptions): Promise<void>;
206
+ declare function writeCollection(collection: Collection, dir: string, options?: ExportOptions): Promise<void>;
166
207
  //#endregion
167
- export { DocsManager, DocsSource, DocsSourceFS, DocsSourceGit, type DocsSourceGitOptions, DocsSourceHTTP, type DocsSourceHTTPOptions, DocsSourceNpm, type DocsSourceNpmOptions, type ExportOptions, type FlatEntry, type NavEntry, exportDocsToFS };
208
+ 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.0.6",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "repository": "pi0/mdzilla",
@@ -30,24 +30,23 @@
30
30
  "typecheck": "tsgo --noEmit --skipLibCheck"
31
31
  },
32
32
  "dependencies": {
33
- "@speed-highlight/core": "^1.2.14",
33
+ "@speed-highlight/core": "^1.2.15",
34
34
  "giget": "^3.1.2",
35
35
  "md4x": "^0.0.25",
36
- "mdream": "^0.17.0",
37
- "srvx": "^0.11.9",
36
+ "srvx": "^0.11.13",
38
37
  "std-env": "^4.0.0"
39
38
  },
40
39
  "devDependencies": {
41
40
  "@types/node": "^25.5.0",
42
- "@typescript/native-preview": "^7.0.0-dev.20260314.1",
43
- "@vitest/coverage-v8": "^4.1.0",
41
+ "@typescript/native-preview": "^7.0.0-dev.20260325.1",
42
+ "@vitest/coverage-v8": "^4.1.1",
44
43
  "automd": "^0.4.3",
45
44
  "changelogen": "^0.6.2",
46
45
  "obuild": "^0.4.32",
47
- "oxfmt": "^0.40.0",
48
- "oxlint": "^1.55.0",
49
- "typescript": "^5.9.3",
50
- "vitest": "^4.1.0"
46
+ "oxfmt": "^0.42.0",
47
+ "oxlint": "^1.57.0",
48
+ "typescript": "^6.0.2",
49
+ "vitest": "^4.1.1"
51
50
  },
52
- "packageManager": "pnpm@10.32.1"
51
+ "packageManager": "pnpm@10.33.0"
53
52
  }