@moxn/kb-migrate 0.2.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/client.js +4 -1
- package/dist/export.js +18 -9
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -117,7 +117,10 @@ export class MoxnClient {
|
|
|
117
117
|
let offset = 0;
|
|
118
118
|
const limit = 100;
|
|
119
119
|
while (true) {
|
|
120
|
-
const params = new URLSearchParams({
|
|
120
|
+
const params = new URLSearchParams({
|
|
121
|
+
limit: String(limit),
|
|
122
|
+
offset: String(offset),
|
|
123
|
+
});
|
|
121
124
|
if (pathPrefix) {
|
|
122
125
|
params.set('path', pathPrefix);
|
|
123
126
|
}
|
package/dist/export.js
CHANGED
|
@@ -10,9 +10,15 @@ import { MoxnClient } from './client.js';
|
|
|
10
10
|
// ──────────────────────────────────────────────
|
|
11
11
|
// Utility functions
|
|
12
12
|
// ──────────────────────────────────────────────
|
|
13
|
-
/** Strip <moxn:comment> tags from text, preserving the inner text. */
|
|
13
|
+
/** Strip <moxn:comment> tags from text, preserving the inner text. Handles nested/double-wrapped tags. */
|
|
14
14
|
function stripCommentTags(text) {
|
|
15
|
-
|
|
15
|
+
const pattern = /<moxn:comment[^>]*>([\s\S]*?)<\/moxn:comment>/g;
|
|
16
|
+
let result = text;
|
|
17
|
+
// Loop until no more comment tags remain (handles nested/double-wrapped tags from TipTap CRDT)
|
|
18
|
+
while (pattern.test(result)) {
|
|
19
|
+
result = result.replace(pattern, '$1');
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
16
22
|
}
|
|
17
23
|
/** Derive a local filename from a storage key or URL. */
|
|
18
24
|
function deriveFilename(storageKey, url, fallbackExt) {
|
|
@@ -117,7 +123,10 @@ function buildMarkdown(doc, mediaMap, mdFilePath) {
|
|
|
117
123
|
// ──────────────────────────────────────────────
|
|
118
124
|
function getMediaTarget(block, options) {
|
|
119
125
|
if (block.blockType === 'image') {
|
|
120
|
-
return {
|
|
126
|
+
return {
|
|
127
|
+
targetDir: options.imageDir,
|
|
128
|
+
fallbackExt: mimeToExt(block.mimeType || 'image/png'),
|
|
129
|
+
};
|
|
121
130
|
}
|
|
122
131
|
else if (block.blockType === 'document') {
|
|
123
132
|
return {
|
|
@@ -137,9 +146,9 @@ export async function runExport(outputDir, options) {
|
|
|
137
146
|
const startTime = Date.now();
|
|
138
147
|
const client = new MoxnClient(options);
|
|
139
148
|
// List documents
|
|
140
|
-
console.
|
|
149
|
+
console.error('Fetching document list...');
|
|
141
150
|
const documents = await client.listDocuments(options.basePath || undefined);
|
|
142
|
-
console.
|
|
151
|
+
console.error(`Found ${documents.length} documents`);
|
|
143
152
|
if (documents.length === 0) {
|
|
144
153
|
return {
|
|
145
154
|
timestamp: new Date().toISOString(),
|
|
@@ -174,7 +183,7 @@ export async function runExport(outputDir, options) {
|
|
|
174
183
|
for (const docItem of documents) {
|
|
175
184
|
const docStart = Date.now();
|
|
176
185
|
const mediaFiles = [];
|
|
177
|
-
console.
|
|
186
|
+
console.error(`Processing: ${docItem.path}`);
|
|
178
187
|
try {
|
|
179
188
|
const doc = await client.getDocument(docItem.id);
|
|
180
189
|
const mdRelativePath = docPathToFilePath(doc.path);
|
|
@@ -205,7 +214,7 @@ export async function runExport(outputDir, options) {
|
|
|
205
214
|
}
|
|
206
215
|
catch (err) {
|
|
207
216
|
const msg = err instanceof Error ? err.message : String(err);
|
|
208
|
-
console.
|
|
217
|
+
console.error(` \u2717 Download failed: ${filename}: ${msg}`);
|
|
209
218
|
}
|
|
210
219
|
}
|
|
211
220
|
}
|
|
@@ -220,7 +229,7 @@ export async function runExport(outputDir, options) {
|
|
|
220
229
|
fs.mkdirSync(path.dirname(mdFullPath), { recursive: true });
|
|
221
230
|
fs.writeFileSync(mdFullPath, markdown, 'utf-8');
|
|
222
231
|
}
|
|
223
|
-
console.
|
|
232
|
+
console.error(` \u2713 ${mdRelativePath} (${doc.sections.length} sections, ${mediaFiles.length} media)`);
|
|
224
233
|
results.push({
|
|
225
234
|
documentId: doc.id,
|
|
226
235
|
documentPath: doc.path,
|
|
@@ -233,7 +242,7 @@ export async function runExport(outputDir, options) {
|
|
|
233
242
|
}
|
|
234
243
|
catch (error) {
|
|
235
244
|
const message = error instanceof Error ? error.message : String(error);
|
|
236
|
-
console.
|
|
245
|
+
console.error(` \u2717 Failed: ${message}`);
|
|
237
246
|
results.push({
|
|
238
247
|
documentId: docItem.id,
|
|
239
248
|
documentPath: docItem.path,
|
package/package.json
CHANGED