@artinstack/migrator 0.1.21 → 0.1.23
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/{chunk-J3WX7IAS.js → chunk-6UEPTHEU.js} +6 -4
- package/dist/chunk-6UEPTHEU.js.map +1 -0
- package/dist/{chunk-H62Y7JAJ.js → chunk-E2EUJY3C.js} +285 -18
- package/dist/chunk-E2EUJY3C.js.map +1 -0
- package/dist/cli/index.js +2 -2
- package/dist/index.d.ts +40 -1
- package/dist/index.js +14 -2
- package/dist/sinks/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-H62Y7JAJ.js.map +0 -1
- package/dist/chunk-J3WX7IAS.js.map +0 -1
|
@@ -53,6 +53,11 @@ var squarespaceClientOptionsSchema = z.object({
|
|
|
53
53
|
retryBaseDelayMs: z.number().int().min(0).default(500),
|
|
54
54
|
maxRetryDelayMs: z.number().int().min(0).default(8e3),
|
|
55
55
|
requestIntervalMs: z.number().int().min(0).default(200),
|
|
56
|
+
/**
|
|
57
|
+
* When json-pretty yields an empty classic layout (common on 7.1 section pages),
|
|
58
|
+
* fetch the rendered HTML once and parse `.sqs-block` content from `#sections`.
|
|
59
|
+
*/
|
|
60
|
+
htmlFallback: z.boolean().default(true),
|
|
56
61
|
fetchImpl: z.custom().optional()
|
|
57
62
|
});
|
|
58
63
|
function isRecord(value) {
|
|
@@ -95,6 +100,37 @@ function inferBlockTypeFromClassName(className) {
|
|
|
95
100
|
if (raw === "horizontalrule") return "line";
|
|
96
101
|
return raw.replace(/-block$/g, "");
|
|
97
102
|
}
|
|
103
|
+
function isEmptyClassicMainContent(html) {
|
|
104
|
+
if (!html?.trim()) return true;
|
|
105
|
+
const $ = cheerio.load(html, { xml: false });
|
|
106
|
+
if ($(".sqs-block").length > 0) return false;
|
|
107
|
+
if ($(".sqs-layout.empty").length > 0) return true;
|
|
108
|
+
return html.replace(/\s+/g, " ").trim().length < 280;
|
|
109
|
+
}
|
|
110
|
+
function pageContentIsEmpty(page) {
|
|
111
|
+
if ((page.blocks?.length ?? 0) > 0) return false;
|
|
112
|
+
return isEmptyClassicMainContent(page.contentHtml);
|
|
113
|
+
}
|
|
114
|
+
function extractPageBodyHtml(html) {
|
|
115
|
+
if (!html.trim()) return "";
|
|
116
|
+
const $ = cheerio.load(html, { xml: false });
|
|
117
|
+
const sections = $("#sections").first();
|
|
118
|
+
if (sections.length) return sections.html() ?? "";
|
|
119
|
+
const article = $("article.sections").first();
|
|
120
|
+
if (article.length) return article.html() ?? "";
|
|
121
|
+
const main = $("main#page, main[role='main'], main").first();
|
|
122
|
+
if (main.length) return main.html() ?? "";
|
|
123
|
+
return "";
|
|
124
|
+
}
|
|
125
|
+
function extractPageContentFromHtml(html) {
|
|
126
|
+
const body = extractPageBodyHtml(html);
|
|
127
|
+
if (!body.trim()) return { contentHtml: "" };
|
|
128
|
+
const parsedBlocks = extractBlocksFromBodyHtml(body);
|
|
129
|
+
if (parsedBlocks.length > 0) {
|
|
130
|
+
return { blocks: parsedBlocks };
|
|
131
|
+
}
|
|
132
|
+
return { contentHtml: body };
|
|
133
|
+
}
|
|
98
134
|
function extractBlocksFromBodyHtml(html) {
|
|
99
135
|
if (!html.trim()) return [];
|
|
100
136
|
const $ = cheerio.load(html, { xml: false });
|
|
@@ -238,19 +274,60 @@ function isBlogCollection(collection) {
|
|
|
238
274
|
const typeName = String(collection.typeName ?? collection.typeLabel ?? "").toLowerCase();
|
|
239
275
|
return typeName.includes("blog");
|
|
240
276
|
}
|
|
277
|
+
function isGalleryCollection(collection) {
|
|
278
|
+
if (!collection) return false;
|
|
279
|
+
if (isBlogCollection(collection)) return false;
|
|
280
|
+
const typeName = String(collection.typeName ?? "").toLowerCase();
|
|
281
|
+
const typeLabel = String(collection.typeLabel ?? "").toLowerCase();
|
|
282
|
+
return typeName.includes("gallery") || typeLabel.includes("gallery") || typeName === "portfolio" || typeLabel === "portfolio";
|
|
283
|
+
}
|
|
241
284
|
function isStaticPageItem(item, collection) {
|
|
242
285
|
const recordTypeLabel = String(item.recordTypeLabel ?? "").toLowerCase();
|
|
243
286
|
if (recordTypeLabel.includes("page")) return true;
|
|
244
287
|
const collectionType = String(collection?.typeName ?? collection?.typeLabel ?? "").toLowerCase();
|
|
245
288
|
return collectionType === "page" || collectionType.includes("page-collection");
|
|
246
289
|
}
|
|
247
|
-
function
|
|
290
|
+
function stripSimpleHtml(value) {
|
|
291
|
+
return value.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
|
292
|
+
}
|
|
293
|
+
function mapWireGalleryItem(item) {
|
|
294
|
+
const resolved = typeof item.assetUrl === "string" && item.assetUrl.trim() ? item.assetUrl.trim() : typeof item.imageUrl === "string" && item.imageUrl.trim() ? item.imageUrl.trim() : "";
|
|
295
|
+
if (!resolved.startsWith("http")) return void 0;
|
|
296
|
+
const rawCaption = typeof item.body === "string" ? stripSimpleHtml(item.body) : typeof item.excerpt === "string" ? item.excerpt.trim() : typeof item.caption === "string" ? item.caption.trim() : void 0;
|
|
297
|
+
return {
|
|
298
|
+
id: String(item.id ?? item.systemDataId ?? item.urlId ?? ""),
|
|
299
|
+
imageUrl: resolved,
|
|
300
|
+
altText: typeof item.altText === "string" ? item.altText : typeof item.title === "string" ? item.title : void 0,
|
|
301
|
+
caption: rawCaption || void 0
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function mapWireGalleryCollection(collection, items, context) {
|
|
305
|
+
const id = String(collection.id ?? collection.urlId ?? collection.fullUrl ?? "gallery");
|
|
306
|
+
const title = String(collection.title ?? collection.navigationTitle ?? "Gallery");
|
|
307
|
+
const slug = sanitizeSlug(String(collection.urlId ?? collection.title ?? id));
|
|
308
|
+
const galleryItems = items.map((item) => mapWireGalleryItem(item)).filter((item) => !!item);
|
|
309
|
+
return {
|
|
310
|
+
id,
|
|
311
|
+
title,
|
|
312
|
+
slug,
|
|
313
|
+
url: resolveAbsoluteUrl(
|
|
314
|
+
typeof collection.fullUrl === "string" ? collection.fullUrl : void 0,
|
|
315
|
+
context?.fetchedUrl
|
|
316
|
+
),
|
|
317
|
+
description: typeof collection.description === "string" ? stripSimpleHtml(collection.description) : void 0,
|
|
318
|
+
items: galleryItems
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function mapWireItemToPost(item, options) {
|
|
248
322
|
const content = mapWireItemContent(item);
|
|
249
323
|
return {
|
|
250
324
|
id: String(item.id ?? item.systemDataId ?? item.urlId ?? ""),
|
|
251
325
|
title: String(item.title ?? "Untitled"),
|
|
252
326
|
slug: sanitizeSlug(String(item.urlId ?? item.title ?? item.id ?? "post")),
|
|
253
|
-
url:
|
|
327
|
+
url: resolveAbsoluteUrl(
|
|
328
|
+
typeof item.fullUrl === "string" ? item.fullUrl : void 0,
|
|
329
|
+
options?.fallbackUrl
|
|
330
|
+
),
|
|
254
331
|
excerpt: typeof item.excerpt === "string" ? item.excerpt : void 0,
|
|
255
332
|
publishedAt: mapPublishOn(item.publishOn ?? item.addedOn),
|
|
256
333
|
status: mapWorkflowState(item.workflowState),
|
|
@@ -262,13 +339,26 @@ function mapWireItemToPost(item) {
|
|
|
262
339
|
...content
|
|
263
340
|
};
|
|
264
341
|
}
|
|
342
|
+
function resolveAbsoluteUrl(raw, fallback) {
|
|
343
|
+
const candidate = raw?.trim() || fallback?.trim();
|
|
344
|
+
if (!candidate) return void 0;
|
|
345
|
+
try {
|
|
346
|
+
if (fallback) return new URL(candidate, fallback).toString();
|
|
347
|
+
return new URL(candidate).toString();
|
|
348
|
+
} catch {
|
|
349
|
+
return candidate.startsWith("http") ? candidate : void 0;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
265
352
|
function mapWireItemToPage(item, options) {
|
|
266
353
|
const content = mapWireItemContent(item);
|
|
267
354
|
return {
|
|
268
355
|
id: String(item.id ?? item.urlId ?? ""),
|
|
269
356
|
title: String(item.title ?? "Untitled"),
|
|
270
357
|
slug: sanitizeSlug(String(item.urlId ?? item.title ?? item.id ?? "page")),
|
|
271
|
-
url:
|
|
358
|
+
url: resolveAbsoluteUrl(
|
|
359
|
+
typeof item.fullUrl === "string" ? item.fullUrl : void 0,
|
|
360
|
+
options?.fallbackUrl
|
|
361
|
+
),
|
|
272
362
|
status: mapWorkflowState(item.workflowState),
|
|
273
363
|
isHomePage: options?.isHomePage,
|
|
274
364
|
seoTitle: readSeo(item.seoData, "title"),
|
|
@@ -313,11 +403,16 @@ function mapJsonPrettyWire(wire, context) {
|
|
|
313
403
|
site: siteFromWire(wire),
|
|
314
404
|
pages: [],
|
|
315
405
|
posts: [],
|
|
406
|
+
galleries: [],
|
|
316
407
|
categories: mapWireCategories(collection),
|
|
317
408
|
tags: []
|
|
318
409
|
};
|
|
319
410
|
if (Array.isArray(wire.items)) {
|
|
320
411
|
const itemRecords = wire.items.map((entry) => asRecord(entry)).filter((entry) => !!entry);
|
|
412
|
+
if (collection && isGalleryCollection(collection)) {
|
|
413
|
+
partial.galleries = [mapWireGalleryCollection(collection, itemRecords, context)];
|
|
414
|
+
return partial;
|
|
415
|
+
}
|
|
321
416
|
partial.tags = mapWireTags(itemRecords);
|
|
322
417
|
for (const item2 of itemRecords) {
|
|
323
418
|
if (isStaticPageItem(item2, collection)) {
|
|
@@ -325,7 +420,7 @@ function mapJsonPrettyWire(wire, context) {
|
|
|
325
420
|
mapWireItemToPage(item2, { fallbackUrl: context?.fetchedUrl, isHomePage: context?.isHomePage })
|
|
326
421
|
);
|
|
327
422
|
} else {
|
|
328
|
-
partial.posts.push(mapWireItemToPost(item2));
|
|
423
|
+
partial.posts.push(mapWireItemToPost(item2, { fallbackUrl: context?.fetchedUrl }));
|
|
329
424
|
}
|
|
330
425
|
}
|
|
331
426
|
return partial;
|
|
@@ -337,20 +432,29 @@ function mapJsonPrettyWire(wire, context) {
|
|
|
337
432
|
mapWireItemToPage(item, { fallbackUrl: context?.fetchedUrl, isHomePage: context?.isHomePage })
|
|
338
433
|
);
|
|
339
434
|
} else {
|
|
340
|
-
partial.posts.push(mapWireItemToPost(item));
|
|
435
|
+
partial.posts.push(mapWireItemToPost(item, { fallbackUrl: context?.fetchedUrl }));
|
|
341
436
|
partial.tags = mapWireTags([item]);
|
|
342
437
|
}
|
|
343
438
|
return partial;
|
|
344
439
|
}
|
|
440
|
+
if (collection && isGalleryCollection(collection)) {
|
|
441
|
+
partial.galleries = [mapWireGalleryCollection(collection, [], context)];
|
|
442
|
+
return partial;
|
|
443
|
+
}
|
|
345
444
|
if (collection && isBlogCollection(collection) === false) {
|
|
445
|
+
const mainContent = typeof wire.mainContent === "string" ? wire.mainContent : void 0;
|
|
446
|
+
const body = mainContent && !isEmptyClassicMainContent(mainContent) ? mainContent : typeof collection.description === "string" ? collection.description : void 0;
|
|
346
447
|
partial.pages.push(
|
|
347
448
|
mapWireItemToPage(
|
|
348
449
|
{
|
|
349
450
|
id: collection.id ?? collection.urlId ?? collection.fullUrl,
|
|
350
451
|
title: collection.title ?? collection.navigationTitle,
|
|
351
452
|
urlId: collection.urlId,
|
|
352
|
-
fullUrl:
|
|
353
|
-
|
|
453
|
+
fullUrl: resolveAbsoluteUrl(
|
|
454
|
+
typeof collection.fullUrl === "string" ? collection.fullUrl : void 0,
|
|
455
|
+
context?.fetchedUrl
|
|
456
|
+
),
|
|
457
|
+
body,
|
|
354
458
|
workflowState: collection.draft ? 2 : 1,
|
|
355
459
|
seoData: collection.seoData
|
|
356
460
|
},
|
|
@@ -380,6 +484,7 @@ function mergeSquarespaceExportPartials(partials) {
|
|
|
380
484
|
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
381
485
|
pages: [],
|
|
382
486
|
posts: [],
|
|
487
|
+
galleries: [],
|
|
383
488
|
categories: [],
|
|
384
489
|
tags: []
|
|
385
490
|
};
|
|
@@ -387,11 +492,13 @@ function mergeSquarespaceExportPartials(partials) {
|
|
|
387
492
|
if (partial.site) merged.site = { ...merged.site, ...partial.site };
|
|
388
493
|
merged.pages.push(...partial.pages ?? []);
|
|
389
494
|
merged.posts.push(...partial.posts ?? []);
|
|
495
|
+
merged.galleries.push(...partial.galleries ?? []);
|
|
390
496
|
merged.categories.push(...partial.categories ?? []);
|
|
391
497
|
merged.tags.push(...partial.tags ?? []);
|
|
392
498
|
}
|
|
393
499
|
merged.pages = dedupeById(merged.pages);
|
|
394
500
|
merged.posts = dedupeById(merged.posts ?? []);
|
|
501
|
+
merged.galleries = dedupeById(merged.galleries ?? []);
|
|
395
502
|
merged.categories = dedupeBySlug(merged.categories ?? []);
|
|
396
503
|
merged.tags = dedupeBySlug(merged.tags ?? []);
|
|
397
504
|
return merged;
|
|
@@ -415,6 +522,7 @@ var SquarespaceCollectionClient = class {
|
|
|
415
522
|
retryBaseDelayMs;
|
|
416
523
|
maxRetryDelayMs;
|
|
417
524
|
requestIntervalMs;
|
|
525
|
+
htmlFallback;
|
|
418
526
|
fetchImpl;
|
|
419
527
|
lastRequestAt = 0;
|
|
420
528
|
constructor(options = {}) {
|
|
@@ -424,15 +532,24 @@ var SquarespaceCollectionClient = class {
|
|
|
424
532
|
this.retryBaseDelayMs = parsed.retryBaseDelayMs;
|
|
425
533
|
this.maxRetryDelayMs = parsed.maxRetryDelayMs;
|
|
426
534
|
this.requestIntervalMs = parsed.requestIntervalMs;
|
|
535
|
+
this.htmlFallback = parsed.htmlFallback;
|
|
427
536
|
this.fetchImpl = parsed.fetchImpl ?? fetch;
|
|
428
537
|
}
|
|
429
538
|
buildJsonPrettyUrl(pageUrl) {
|
|
430
539
|
return buildJsonPrettyUrl(pageUrl, this.format);
|
|
431
540
|
}
|
|
432
541
|
async fetchWire(url) {
|
|
433
|
-
const response = await this.requestWithRetry(this.buildJsonPrettyUrl(url)
|
|
542
|
+
const response = await this.requestWithRetry(this.buildJsonPrettyUrl(url), {
|
|
543
|
+
accept: "application/json, text/html, */*"
|
|
544
|
+
});
|
|
434
545
|
return response.json();
|
|
435
546
|
}
|
|
547
|
+
async fetchHtml(url) {
|
|
548
|
+
const response = await this.requestWithRetry(url, {
|
|
549
|
+
accept: "text/html,application/xhtml+xml"
|
|
550
|
+
});
|
|
551
|
+
return response.text();
|
|
552
|
+
}
|
|
436
553
|
async collectExport(targets) {
|
|
437
554
|
if (targets.length === 0) {
|
|
438
555
|
throw new Error("Squarespace collector requires at least one target URL");
|
|
@@ -449,7 +566,30 @@ var SquarespaceCollectionClient = class {
|
|
|
449
566
|
);
|
|
450
567
|
}
|
|
451
568
|
}
|
|
452
|
-
|
|
569
|
+
const merged = mergeSquarespaceExportPartials(partials);
|
|
570
|
+
if (this.htmlFallback) {
|
|
571
|
+
await this.enrichEmptyPagesFromHtml(merged);
|
|
572
|
+
}
|
|
573
|
+
return merged;
|
|
574
|
+
}
|
|
575
|
+
async enrichEmptyPagesFromHtml(doc) {
|
|
576
|
+
for (const page of doc.pages) {
|
|
577
|
+
if (!pageContentIsEmpty(page)) continue;
|
|
578
|
+
const pageUrl = page.url?.trim();
|
|
579
|
+
if (!pageUrl) continue;
|
|
580
|
+
try {
|
|
581
|
+
const html = await this.fetchHtml(pageUrl);
|
|
582
|
+
const content = extractPageContentFromHtml(html);
|
|
583
|
+
if (content.blocks?.length) {
|
|
584
|
+
page.blocks = content.blocks;
|
|
585
|
+
delete page.contentHtml;
|
|
586
|
+
} else if (content.contentHtml?.trim()) {
|
|
587
|
+
page.contentHtml = content.contentHtml;
|
|
588
|
+
delete page.blocks;
|
|
589
|
+
}
|
|
590
|
+
} catch {
|
|
591
|
+
}
|
|
592
|
+
}
|
|
453
593
|
}
|
|
454
594
|
async collectCollectionPages(target) {
|
|
455
595
|
const partials = [];
|
|
@@ -466,13 +606,14 @@ var SquarespaceCollectionClient = class {
|
|
|
466
606
|
}
|
|
467
607
|
return partials;
|
|
468
608
|
}
|
|
469
|
-
async requestWithRetry(url) {
|
|
609
|
+
async requestWithRetry(url, options) {
|
|
470
610
|
let attempt = 0;
|
|
611
|
+
const accept = options?.accept ?? "application/json, text/html, */*";
|
|
471
612
|
while (true) {
|
|
472
613
|
await this.throttle();
|
|
473
614
|
const response = await this.fetchImpl(url, {
|
|
474
615
|
method: "GET",
|
|
475
|
-
headers: { Accept:
|
|
616
|
+
headers: { Accept: accept }
|
|
476
617
|
});
|
|
477
618
|
if (response.ok) {
|
|
478
619
|
return response;
|
|
@@ -722,6 +863,98 @@ function assetFromUrl(url, exportedAt, index) {
|
|
|
722
863
|
mimeType: guessMime(filename)
|
|
723
864
|
};
|
|
724
865
|
}
|
|
866
|
+
function galleryPortfolioSourceId(parentSourceId, block, galleryIndex) {
|
|
867
|
+
const blockId = block.id?.trim();
|
|
868
|
+
if (blockId) return `gallery:${blockId}`;
|
|
869
|
+
return `gallery:${parentSourceId}:${galleryIndex}`;
|
|
870
|
+
}
|
|
871
|
+
function countGalleryPortfolios(blocks) {
|
|
872
|
+
if (!blocks?.length) return 0;
|
|
873
|
+
return blocks.filter(
|
|
874
|
+
(block) => block.type.toLowerCase() === "gallery" && (block.items?.length ?? 0) > 0
|
|
875
|
+
).length;
|
|
876
|
+
}
|
|
877
|
+
function collectGalleryImageUrls(blocks) {
|
|
878
|
+
const urls = /* @__PURE__ */ new Set();
|
|
879
|
+
if (!blocks?.length) return urls;
|
|
880
|
+
for (const block of blocks) {
|
|
881
|
+
if (block.type.toLowerCase() !== "gallery") continue;
|
|
882
|
+
for (const item of block.items ?? []) {
|
|
883
|
+
if (item.imageUrl) urls.add(item.imageUrl);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return urls;
|
|
887
|
+
}
|
|
888
|
+
function galleryAssetSourceId(portfolioSourceId, item, sort) {
|
|
889
|
+
const itemId = item.id?.trim();
|
|
890
|
+
if (itemId) return itemId;
|
|
891
|
+
return `${portfolioSourceId}:${sort}`;
|
|
892
|
+
}
|
|
893
|
+
function* emitGalleriesFromBlocks(blocks, parent, exportedAt) {
|
|
894
|
+
if (!blocks?.length) return;
|
|
895
|
+
const nonEmptyGalleries = blocks.filter(
|
|
896
|
+
(block) => block.type.toLowerCase() === "gallery" && (block.items?.length ?? 0) > 0
|
|
897
|
+
);
|
|
898
|
+
if (nonEmptyGalleries.length === 0) return;
|
|
899
|
+
let galleryIndex = 0;
|
|
900
|
+
for (const block of blocks) {
|
|
901
|
+
if (block.type.toLowerCase() !== "gallery") continue;
|
|
902
|
+
const items = (block.items ?? []).filter((item) => Boolean(item.imageUrl?.trim()));
|
|
903
|
+
if (items.length === 0) continue;
|
|
904
|
+
const sourceId = galleryPortfolioSourceId(parent.sourceId, block, galleryIndex);
|
|
905
|
+
const slugBase = block.id?.trim() ? sanitizeSlug(block.id) : sanitizeSlug(`gallery-${galleryIndex + 1}`);
|
|
906
|
+
const title = nonEmptyGalleries.length === 1 ? parent.title : `${parent.title} \u2014 Gallery ${galleryIndex + 1}`;
|
|
907
|
+
yield {
|
|
908
|
+
type: "portfolio",
|
|
909
|
+
source: sourceMeta(sourceId, parent.url, exportedAt),
|
|
910
|
+
sourceId,
|
|
911
|
+
title,
|
|
912
|
+
slug: slugBase.startsWith("gallery") ? slugBase : `gallery-${slugBase}`
|
|
913
|
+
};
|
|
914
|
+
yield* emitGalleryAssets(sourceId, items, exportedAt);
|
|
915
|
+
galleryIndex += 1;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
function galleryCollectionPortfolioSourceId(collectionId) {
|
|
919
|
+
return `gallery-collection:${collectionId}`;
|
|
920
|
+
}
|
|
921
|
+
function* emitGalleryAssets(portfolioSourceId, items, exportedAt) {
|
|
922
|
+
for (let sort = 0; sort < items.length; sort++) {
|
|
923
|
+
const item = items[sort];
|
|
924
|
+
const assetSourceId = galleryAssetSourceId(portfolioSourceId, item, sort);
|
|
925
|
+
const filename = filenameFromUrl(item.imageUrl, `${assetSourceId}.jpg`);
|
|
926
|
+
yield {
|
|
927
|
+
type: "asset",
|
|
928
|
+
source: sourceMeta(assetSourceId, item.imageUrl, exportedAt),
|
|
929
|
+
sourceId: assetSourceId,
|
|
930
|
+
sourceUrl: item.imageUrl,
|
|
931
|
+
filename,
|
|
932
|
+
mimeType: guessMime(filename),
|
|
933
|
+
caption: item.caption,
|
|
934
|
+
altText: item.altText,
|
|
935
|
+
portfolioSourceId,
|
|
936
|
+
sort
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
function* emitGalleryCollections(galleries, exportedAt) {
|
|
941
|
+
if (!galleries?.length) return;
|
|
942
|
+
for (const gallery of galleries) {
|
|
943
|
+
const items = gallery.items.filter((item) => Boolean(item.imageUrl?.trim()));
|
|
944
|
+
if (items.length === 0) continue;
|
|
945
|
+
const sourceId = galleryCollectionPortfolioSourceId(gallery.id);
|
|
946
|
+
const slugBase = sanitizeSlug(gallery.slug || gallery.id);
|
|
947
|
+
yield {
|
|
948
|
+
type: "portfolio",
|
|
949
|
+
source: sourceMeta(sourceId, gallery.url, exportedAt),
|
|
950
|
+
sourceId,
|
|
951
|
+
title: gallery.title,
|
|
952
|
+
slug: slugBase.startsWith("gallery") ? slugBase : `gallery-${slugBase}`,
|
|
953
|
+
description: gallery.description
|
|
954
|
+
};
|
|
955
|
+
yield* emitGalleryAssets(sourceId, items, exportedAt);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
725
958
|
function isSquarespaceExport(value) {
|
|
726
959
|
if (!value || typeof value !== "object") return false;
|
|
727
960
|
const record = value;
|
|
@@ -747,8 +980,8 @@ async function loadSquarespaceExport(options) {
|
|
|
747
980
|
if (isSquarespaceExport(raw)) return raw;
|
|
748
981
|
throw new Error("Invalid Squarespace export: expected exportVersion 1 with pages[]");
|
|
749
982
|
}
|
|
750
|
-
function* emitAssetsFromContent(contentHtml, explicitUrls, exportedAt) {
|
|
751
|
-
const seen =
|
|
983
|
+
function* emitAssetsFromContent(contentHtml, explicitUrls, exportedAt, excludeUrls) {
|
|
984
|
+
const seen = new Set(excludeUrls ?? []);
|
|
752
985
|
const urls = [...explicitUrls, ...discoverContentAssetUrls(contentHtml)];
|
|
753
986
|
let index = 0;
|
|
754
987
|
for (const url of urls) {
|
|
@@ -773,7 +1006,13 @@ async function* emitPage(page, exportedAt) {
|
|
|
773
1006
|
seoTitle: page.seoTitle,
|
|
774
1007
|
seoDescription: page.seoDescription
|
|
775
1008
|
};
|
|
776
|
-
yield*
|
|
1009
|
+
yield* emitGalleriesFromBlocks(
|
|
1010
|
+
page.blocks,
|
|
1011
|
+
{ sourceId: page.id, title: page.title, url: page.url },
|
|
1012
|
+
exportedAt
|
|
1013
|
+
);
|
|
1014
|
+
const galleryUrls = collectGalleryImageUrls(page.blocks);
|
|
1015
|
+
yield* emitAssetsFromContent(contentHtml, assetUrls, exportedAt, galleryUrls);
|
|
777
1016
|
}
|
|
778
1017
|
async function* emitPost(post, exportedAt) {
|
|
779
1018
|
const { contentHtml, assetUrls } = resolveContentHtml(post);
|
|
@@ -808,7 +1047,13 @@ async function* emitPost(post, exportedAt) {
|
|
|
808
1047
|
mimeType: guessMime(filename)
|
|
809
1048
|
};
|
|
810
1049
|
}
|
|
811
|
-
yield*
|
|
1050
|
+
yield* emitGalleriesFromBlocks(
|
|
1051
|
+
post.blocks,
|
|
1052
|
+
{ sourceId: post.id, title: post.title, url: post.url },
|
|
1053
|
+
exportedAt
|
|
1054
|
+
);
|
|
1055
|
+
const galleryUrls = collectGalleryImageUrls(post.blocks);
|
|
1056
|
+
yield* emitAssetsFromContent(contentHtml, assetUrls, exportedAt, galleryUrls);
|
|
812
1057
|
}
|
|
813
1058
|
async function* enumerateSquarespaceEntities(options) {
|
|
814
1059
|
const doc = await loadSquarespaceExport(options);
|
|
@@ -837,13 +1082,29 @@ async function* enumerateSquarespaceEntities(options) {
|
|
|
837
1082
|
for (const post of doc.posts ?? []) {
|
|
838
1083
|
yield* emitPost(post, exportedAt);
|
|
839
1084
|
}
|
|
1085
|
+
yield* emitGalleryCollections(doc.galleries, exportedAt);
|
|
1086
|
+
}
|
|
1087
|
+
function countCollectionPortfolios(galleries) {
|
|
1088
|
+
if (!galleries?.length) return 0;
|
|
1089
|
+
return galleries.filter(
|
|
1090
|
+
(gallery) => gallery.items.some((item) => Boolean(item.imageUrl?.trim()))
|
|
1091
|
+
).length;
|
|
840
1092
|
}
|
|
841
1093
|
function summarizeSquarespaceExport(doc) {
|
|
1094
|
+
let portfolios = 0;
|
|
1095
|
+
for (const page of doc.pages) {
|
|
1096
|
+
portfolios += countGalleryPortfolios(page.blocks);
|
|
1097
|
+
}
|
|
1098
|
+
for (const post of doc.posts ?? []) {
|
|
1099
|
+
portfolios += countGalleryPortfolios(post.blocks);
|
|
1100
|
+
}
|
|
1101
|
+
portfolios += countCollectionPortfolios(doc.galleries);
|
|
842
1102
|
return {
|
|
843
1103
|
pages: doc.pages.length,
|
|
844
1104
|
posts: doc.posts?.length ?? 0,
|
|
845
1105
|
categories: doc.categories?.length ?? 0,
|
|
846
|
-
tags: doc.tags?.length ?? 0
|
|
1106
|
+
tags: doc.tags?.length ?? 0,
|
|
1107
|
+
portfolios
|
|
847
1108
|
};
|
|
848
1109
|
}
|
|
849
1110
|
async function validateSquarespaceExportFile(filePath) {
|
|
@@ -875,7 +1136,7 @@ async function validateSquarespaceExportFile(filePath) {
|
|
|
875
1136
|
posts: summary.posts,
|
|
876
1137
|
categories: summary.categories,
|
|
877
1138
|
tags: summary.tags,
|
|
878
|
-
portfolios:
|
|
1139
|
+
portfolios: summary.portfolios,
|
|
879
1140
|
assets: 0
|
|
880
1141
|
}
|
|
881
1142
|
};
|
|
@@ -1539,6 +1800,12 @@ export {
|
|
|
1539
1800
|
MIGRATION_WRITE_STAGES,
|
|
1540
1801
|
SQUARESPACE_JSON_FORMAT,
|
|
1541
1802
|
buildJsonPrettyUrl,
|
|
1803
|
+
isEmptyClassicMainContent,
|
|
1804
|
+
pageContentIsEmpty,
|
|
1805
|
+
extractPageBodyHtml,
|
|
1806
|
+
extractPageContentFromHtml,
|
|
1807
|
+
extractBlocksFromBodyHtml,
|
|
1808
|
+
isGalleryCollection,
|
|
1542
1809
|
mapJsonPrettyWire,
|
|
1543
1810
|
SquarespaceCollectionClient,
|
|
1544
1811
|
enumerateSquarespaceEntities,
|
|
@@ -1565,4 +1832,4 @@ export {
|
|
|
1565
1832
|
resolveAdapterImportSummary,
|
|
1566
1833
|
runDryRun
|
|
1567
1834
|
};
|
|
1568
|
-
//# sourceMappingURL=chunk-
|
|
1835
|
+
//# sourceMappingURL=chunk-E2EUJY3C.js.map
|