create-freeholder 0.2.0-beta.4 → 0.2.0-beta.6

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.
Files changed (158) hide show
  1. package/dist/template/.changeset/blog-playground-content.md +4 -0
  2. package/dist/template/.changeset/blog-wordpress-structure.md +6 -0
  3. package/dist/template/.changeset/managed-preview-assistant.md +4 -0
  4. package/dist/template/.changeset/native-linux-install.md +6 -0
  5. package/dist/template/.changeset/public-beta-5.md +4 -0
  6. package/dist/template/.changeset/public-beta-6.md +4 -0
  7. package/dist/template/.github/ISSUE_TEMPLATE/bug_report.yml +1 -1
  8. package/dist/template/.github/workflows/release-tarballs.yml +117 -0
  9. package/dist/template/AGENTS.md +15 -2
  10. package/dist/template/Dockerfile +3 -0
  11. package/dist/template/MASTER.md +114 -11
  12. package/dist/template/README.md +1 -1
  13. package/dist/template/app/(admin)/admin/assistant/page.tsx +9 -1
  14. package/dist/template/app/(admin)/admin/blog/PostSettings.tsx +26 -0
  15. package/dist/template/app/(admin)/admin/blog/[kind]/page.tsx +53 -0
  16. package/dist/template/app/(admin)/admin/blog/actions.ts +186 -6
  17. package/dist/template/app/(admin)/admin/blog/comments/page.tsx +25 -0
  18. package/dist/template/app/(admin)/admin/blog/page.tsx +21 -5
  19. package/dist/template/app/(admin)/admin/imports/[id]/page.tsx +2 -0
  20. package/dist/template/app/(admin)/admin/pages/[id]/page.tsx +3 -0
  21. package/dist/template/app/(admin)/assistant-actions.ts +13 -6
  22. package/dist/template/app/(public)/[[...slug]]/ReaderComments.tsx +25 -0
  23. package/dist/template/app/(public)/[[...slug]]/blog-parts.tsx +153 -0
  24. package/dist/template/app/(public)/[[...slug]]/comment-actions.ts +16 -0
  25. package/dist/template/app/(public)/[[...slug]]/page.tsx +182 -18
  26. package/dist/template/app/api/chat/assistant/call/route.ts +35 -0
  27. package/dist/template/db/migrations/0061_blog_structure.sql +89 -0
  28. package/dist/template/db/migrations/0062_blog_reader_comments.sql +24 -0
  29. package/dist/template/db/migrations/meta/_journal.json +14 -0
  30. package/dist/template/deploy/README.md +26 -9
  31. package/dist/template/deploy/blog-wordpress-2026-11-07.md +146 -0
  32. package/dist/template/deploy/docker-selfhost/.env.example +11 -1
  33. package/dist/template/deploy/docker-selfhost/README.md +79 -50
  34. package/dist/template/deploy/docker-selfhost/infra/backup.sh +81 -0
  35. package/dist/template/deploy/docker-selfhost/infra/compose.https.yml +37 -1
  36. package/dist/template/deploy/docker-selfhost/infra/compose.yml +37 -1
  37. package/dist/template/deploy/docker-selfhost/migrate.md +8 -5
  38. package/dist/template/deploy/docker-selfhost/recipe.yaml +9 -10
  39. package/dist/template/deploy/docker-selfhost/selfhost.sh +206 -0
  40. package/dist/template/deploy/docker-selfhost/verify.md +11 -4
  41. package/dist/template/deploy/f-criteria-matrix.md +89 -0
  42. package/dist/template/deploy/linux/.env.example +28 -0
  43. package/dist/template/deploy/linux/README.md +181 -0
  44. package/dist/template/deploy/linux/freeholder +655 -0
  45. package/dist/template/deploy/linux/install.sh +173 -0
  46. package/dist/template/deploy/linux/migrate.md +17 -0
  47. package/dist/template/deploy/linux/recipe.yaml +50 -0
  48. package/dist/template/deploy/linux/share/Caddyfile.template +19 -0
  49. package/dist/template/deploy/linux/share/systemd/freeholder-backup.service +13 -0
  50. package/dist/template/deploy/linux/share/systemd/freeholder-backup.timer +12 -0
  51. package/dist/template/deploy/linux/share/systemd/freeholder.service +41 -0
  52. package/dist/template/deploy/linux/verify.md +22 -0
  53. package/dist/template/deploy/managed-preview-assistant.md +99 -0
  54. package/dist/template/eslint.config.mjs +3 -1
  55. package/dist/template/gitignore.template +1 -0
  56. package/dist/template/locales/ar.json +85 -6
  57. package/dist/template/locales/en.json +83 -4
  58. package/dist/template/locales/es.json +83 -4
  59. package/dist/template/locales/fr.json +85 -6
  60. package/dist/template/next.config.ts +2 -0
  61. package/dist/template/package.json +3 -2
  62. package/dist/template/packages/cli/package.json +1 -1
  63. package/dist/template/packages/create-freeholder/package.json +1 -1
  64. package/dist/template/packages/freeholder-app/package.json +1 -1
  65. package/dist/template/packages/mobile-app/package.json +1 -1
  66. package/dist/template/packages/plugin-kit/package.json +1 -1
  67. package/dist/template/packages/sdk/package.json +1 -1
  68. package/dist/template/packages/sdk/src/generated.ts +177 -9
  69. package/dist/template/packages/sdk/src/version.ts +1 -1
  70. package/dist/template/packages/templates/package.json +1 -1
  71. package/dist/template/proxy.ts +18 -1
  72. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/NOTICE.txt +117 -0
  73. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/audio-output-processor.js +267 -0
  74. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.js +847 -0
  75. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.wasm +0 -0
  76. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/encoderWorker.min.js +1 -0
  77. package/dist/template/public/managed-assistant/0.1.10/manifest.json +12 -0
  78. package/dist/template/public/managed-assistant/0.1.10/pm-ai-duplex-client.js +1376 -0
  79. package/dist/template/scripts/build-release.d.mts +4 -0
  80. package/dist/template/scripts/build-release.mjs +171 -0
  81. package/dist/template/scripts/launch-prepare.mjs +6 -3
  82. package/dist/template/scripts/license-headers.mjs +3 -0
  83. package/dist/template/scripts/recipe-matrix.sh +22 -7
  84. package/dist/template/scripts/verify-wordpress-migration.d.mts +8 -0
  85. package/dist/template/scripts/verify-wordpress-migration.mjs +105 -0
  86. package/dist/template/security/adversarial-audit-2026-10-08.md +1 -1
  87. package/dist/template/src/adapters/ai/types.ts +5 -0
  88. package/dist/template/src/adapters/paradise/assistant.ts +37 -0
  89. package/dist/template/src/adapters/paradise/http.ts +4 -3
  90. package/dist/template/src/adapters/storage/local-mode.ts +54 -0
  91. package/dist/template/src/adapters/storage/local.ts +53 -26
  92. package/dist/template/src/core/contract/json-schema.ts +8 -0
  93. package/dist/template/src/core/demo/playground-inserts.ts +29 -0
  94. package/dist/template/src/core/demo/playground-policy.ts +9 -0
  95. package/dist/template/src/core/doctor/index.ts +19 -10
  96. package/dist/template/src/core/env.ts +8 -1
  97. package/dist/template/src/core/http/csp.ts +10 -2
  98. package/dist/template/src/core/http/csrf-client.ts +10 -0
  99. package/dist/template/src/core/import/service.ts +217 -12
  100. package/dist/template/src/core/import/wordpress.ts +80 -15
  101. package/dist/template/src/core/notifications/service.ts +1 -0
  102. package/dist/template/src/core/retention/registry.ts +2 -0
  103. package/dist/template/src/core/search/registry.ts +2 -0
  104. package/dist/template/src/core/seo/feeds.ts +2 -0
  105. package/dist/template/src/core/seo/jsonld.ts +46 -2
  106. package/dist/template/src/core/seo/legacy-proxy.ts +53 -0
  107. package/dist/template/src/core/seo/meta.ts +10 -7
  108. package/dist/template/src/core/seo/service.ts +14 -1
  109. package/dist/template/src/core/update/preflight.ts +3 -2
  110. package/dist/template/src/core/update/release-declaration.json +1 -1
  111. package/dist/template/src/core/update/service.ts +7 -17
  112. package/dist/template/src/modules/assistant/contract.ts +1 -1
  113. package/dist/template/src/modules/assistant/limits.ts +3 -0
  114. package/dist/template/src/modules/assistant/preview.ts +124 -0
  115. package/dist/template/src/modules/assistant/provider.ts +7 -0
  116. package/dist/template/src/modules/assistant/service.ts +21 -5
  117. package/dist/template/src/modules/cms/blocks/PreviewAssistantCall.tsx +176 -0
  118. package/dist/template/src/modules/cms/blocks/SiteChatClient.tsx +10 -4
  119. package/dist/template/src/modules/cms/blocks/surfaces.tsx +10 -0
  120. package/dist/template/src/modules/cms/blog-comments-schema.ts +27 -0
  121. package/dist/template/src/modules/cms/blog-comments.ts +111 -0
  122. package/dist/template/src/modules/cms/blog-schema.ts +146 -0
  123. package/dist/template/src/modules/cms/blog-service.ts +999 -0
  124. package/dist/template/src/modules/cms/blog.tsx +245 -25
  125. package/dist/template/src/modules/cms/manifest.ts +7 -1
  126. package/dist/template/src/modules/cms/read.ts +18 -0
  127. package/dist/template/src/modules/cms/service.ts +22 -4
  128. package/dist/template/src/modules/cms/tables.ts +2 -0
  129. package/dist/template/src/modules/seed/launch.ts +31 -3
  130. package/dist/template/tests/browser/blog-structure.spec.ts +69 -0
  131. package/dist/template/tests/core/agent-launch.test.ts +7 -2
  132. package/dist/template/tests/core/analytics-consent.test.ts +1 -1
  133. package/dist/template/tests/core/blog-playground.test.ts +106 -0
  134. package/dist/template/tests/core/blog-structure-comments.test.ts +166 -0
  135. package/dist/template/tests/core/client-readiness-security.test.ts +3 -1
  136. package/dist/template/tests/core/csp.test.ts +1 -1
  137. package/dist/template/tests/core/deploy-recipe.test.ts +54 -4
  138. package/dist/template/tests/core/internal-services.test.ts +4 -0
  139. package/dist/template/tests/core/legacy-redirect-proxy.test.ts +59 -0
  140. package/dist/template/tests/core/linux-install.test.ts +169 -0
  141. package/dist/template/tests/core/local-storage-mode.test.ts +29 -0
  142. package/dist/template/tests/core/locale-routing.test.ts +1 -1
  143. package/dist/template/tests/core/playground-cache.test.ts +1 -1
  144. package/dist/template/tests/core/playground.test.ts +3 -3
  145. package/dist/template/tests/core/preview-assistant-call.test.ts +88 -0
  146. package/dist/template/tests/core/private-preview-webhooks.test.ts +1 -1
  147. package/dist/template/tests/core/private-preview.test.ts +1 -1
  148. package/dist/template/tests/core/proxy-locale.test.ts +1 -1
  149. package/dist/template/tests/core/sdk-schema.test.ts +20 -0
  150. package/dist/template/tests/core/seo.test.ts +1 -1
  151. package/dist/template/tests/core/site-chat-client.test.ts +50 -0
  152. package/dist/template/tests/core/storage.test.ts +38 -2
  153. package/dist/template/tests/core/wordpress-import-flow.test.ts +81 -18
  154. package/dist/template/tests/core/wordpress-import.test.ts +25 -12
  155. package/dist/template/tests/core/wordpress-migration-verification.test.ts +37 -0
  156. package/dist/template/tests/modules/preview-assistant.test.ts +164 -0
  157. package/dist/template-manifest.json +490 -175
  158. package/package.json +1 -1
@@ -48,6 +48,8 @@ import {
48
48
  wordpressPath,
49
49
  type ImageMatch,
50
50
  type WordpressExport,
51
+ type WordpressComment,
52
+ type WordpressSeo,
51
53
  } from "./wordpress";
52
54
 
53
55
  const HTML_MARKUP_MAX = 20_000;
@@ -62,14 +64,18 @@ type PreviewPage = {
62
64
  /** WordPress only: a draft, private or scheduled item stays a draft at publish. */
63
65
  status?: "publish" | "draft";
64
66
  publishedAt?: string;
67
+ modifiedAt?: string;
65
68
  redirectFrom?: string;
66
- seo?: { title?: string; description?: string };
69
+ seo?: WordpressSeo;
67
70
  author?: string;
68
71
  categories?: string[];
69
72
  tags?: string[];
73
+ categorySlugs?: string[];
74
+ tagSlugs?: string[];
70
75
  featuredMedia?: string;
71
76
  wpId?: string;
72
77
  comments?: number;
78
+ readerComments?: WordpressComment[];
73
79
  };
74
80
 
75
81
  type ConflictDecision = {
@@ -104,14 +110,18 @@ function previewPages(preview: unknown): PreviewPage[] {
104
110
  kind: row.kind === "post" ? "post" : "page",
105
111
  status: row.status === "draft" ? "draft" : row.status === "publish" ? "publish" : undefined,
106
112
  publishedAt: optionalString(row.publishedAt),
113
+ modifiedAt: optionalString(row.modifiedAt),
107
114
  redirectFrom: optionalString(row.redirectFrom),
108
- seo: seo ? { title: optionalString(seo.title), description: optionalString(seo.description) } : undefined,
115
+ seo: seo ? { title: optionalString(seo.title), description: optionalString(seo.description), preserveTitle: seo.preserveTitle === true, preserveDescription: seo.preserveDescription === true, noindex: seo.noindex === true, nofollow: seo.nofollow === true, canonical: optionalString(seo.canonical), ogTitle: optionalString(seo.ogTitle), ogDescription: optionalString(seo.ogDescription), ogImage: optionalString(seo.ogImage) } : undefined,
109
116
  author: optionalString(row.author),
110
117
  categories: stringList(row.categories),
111
118
  tags: stringList(row.tags),
119
+ categorySlugs: stringList(row.categorySlugs),
120
+ tagSlugs: stringList(row.tagSlugs),
112
121
  featuredMedia: optionalString(row.featuredMedia),
113
122
  wpId: optionalString(row.wpId),
114
123
  comments: typeof row.comments === "number" ? row.comments : undefined,
124
+ readerComments: Array.isArray(row.readerComments) ? row.readerComments as WordpressComment[] : undefined,
115
125
  });
116
126
  }
117
127
  return out;
@@ -160,9 +170,10 @@ const wordpressPreviewSchema = z.object({
160
170
  }),
161
171
  ),
162
172
  taxonomy: z.object({
163
- categories: z.array(z.object({ slug: z.string(), name: z.string(), posts: z.number() })),
164
- tags: z.array(z.object({ slug: z.string(), name: z.string(), posts: z.number() })),
173
+ categories: z.array(z.object({ slug: z.string(), name: z.string(), posts: z.number(), parentSlug: z.string().optional(), description: z.string().optional() })),
174
+ tags: z.array(z.object({ slug: z.string(), name: z.string(), posts: z.number(), description: z.string().optional() })),
165
175
  }),
176
+ attachments: z.array(z.object({ wpId: z.string().optional(), parentWpId: z.string().optional(), path: z.string().optional() })).default([]),
166
177
  report: z.record(z.string(), z.unknown()),
167
178
  });
168
179
  type WordpressPreview = z.infer<typeof wordpressPreviewSchema>;
@@ -180,6 +191,10 @@ const cmsPageRef = z.object({
180
191
  blocks: z.unknown(),
181
192
  seo: z.unknown(),
182
193
  status: z.enum(["draft", "published"]),
194
+ publishedAt: z.coerce.date().nullable().optional(),
195
+ workingTitle: z.string().nullable().optional(),
196
+ workingBlocks: z.unknown().optional(),
197
+ workingSeo: z.unknown().optional(),
183
198
  });
184
199
  type CmsPageRef = z.infer<typeof cmsPageRef>;
185
200
 
@@ -320,7 +335,10 @@ async function restoreReplacedPage(ctx: ServiceContext, snapshot: CmsPageRef): P
320
335
  seo: snapshot.seo ?? {},
321
336
  });
322
337
  if (snapshot.status === "published") {
323
- await ctx.call(getService("cms.publishPage"), { id: snapshot.id, published: true });
338
+ await ctx.call(getService("cms.publishPage"), { id: snapshot.id, published: true, ...(snapshot.publishedAt ? { publishedAt: snapshot.publishedAt.toISOString() } : {}) });
339
+ if (snapshot.workingTitle != null || snapshot.workingBlocks != null || snapshot.workingSeo != null) {
340
+ await ctx.call(getService("cms.updatePage"), { id: snapshot.id, title: snapshot.workingTitle ?? snapshot.title, blocks: snapshot.workingBlocks ?? snapshot.blocks, seo: snapshot.workingSeo ?? snapshot.seo ?? {} });
341
+ }
324
342
  }
325
343
  }
326
344
 
@@ -600,6 +618,26 @@ function chooseMenu(menus: ResolvedMenu[]): ResolvedMenu | undefined {
600
618
  }
601
619
 
602
620
  /** The write half of a commit: one transaction for pages, redirects and report. */
621
+ const pendingBlogPost = z.object({ pageId: uuid, key: z.string(), meta: z.record(z.string(), z.unknown()), comments: z.array(z.object({ id: z.string(), parentId: z.string().optional(), name: z.string(), email: z.string().nullable(), body: z.string(), status: z.enum(["pending", "approved", "spam", "trash"]), createdAt: z.string().optional() })) });
622
+
623
+ async function importPostComments(ctx: ServiceContext, runId: string, pageId: string, key: string, entries: WordpressComment[]): Promise<number> {
624
+ const remaining = [...entries], ids = new Map<string, string>();
625
+ for (let pass = 0; remaining.length && pass <= entries.length; pass += 1) {
626
+ for (let index = remaining.length - 1; index >= 0; index -= 1) {
627
+ const comment = remaining[index]!;
628
+ if (comment.parentId && remaining.some(parent => parent.id === comment.parentId)) continue;
629
+ const saved = z.object({ id: uuid }).parse(await ctx.call(getService("cms.importReaderComment"), {
630
+ runId, externalId: `${key}:${comment.id}`, pageId, parentId: comment.parentId ? ids.get(comment.parentId) ?? null : null,
631
+ name: comment.name, email: comment.email, body: comment.body, status: comment.status,
632
+ ...(comment.createdAt ? { createdAt: comment.createdAt } : {}),
633
+ }));
634
+ ids.set(comment.id, saved.id); remaining.splice(index, 1);
635
+ }
636
+ }
637
+ if (remaining.length) throw new ServiceError("validation", "The imported comment thread contains a cycle.");
638
+ return entries.length;
639
+ }
640
+
603
641
  const commitApply = defineService({
604
642
  name: "imports.commitApply",
605
643
  summary: "Write a previewed import into the CMS as drafts, with redirects and a report.",
@@ -639,6 +677,7 @@ const commitApply = defineService({
639
677
  slug = cmsSlug(decision.renamedSlug?.trim() || `${page.slug}-imported`);
640
678
  }
641
679
  if (bySlug.has(slug) && decision?.resolution === "replace") {
680
+ if (wordpress && page.status === "draft" && bySlug.get(slug)!.status === "published") throw new ServiceError("conflict", "A WordPress draft cannot replace a live page. Rename the imported draft or keep the live page.");
642
681
  placements.push({ page, slug, action: "replace", current: bySlug.get(slug)! });
643
682
  continue;
644
683
  }
@@ -654,6 +693,55 @@ const commitApply = defineService({
654
693
  placements.push({ page, slug, action: "create" });
655
694
  }
656
695
  const written = placements.filter((placement) => placement.action !== "keep");
696
+ // Real blog records, shared by owner screens, the API and the public archives.
697
+ const blogSource = `import:${before.id}`;
698
+ const authorIds = new Map<string, string>();
699
+ const categoryIds = new Map<string, string>();
700
+ const tagIds = new Map<string, string>();
701
+ const categoryPaths = new Map<string, string>();
702
+ const archiveAliases: Array<{ fromPath: string; toPath: string }> = [];
703
+ const postSnapshots: unknown[] = [];
704
+ const pendingBlogPosts: z.infer<typeof pendingBlogPost>[] = [];
705
+ const directoryRows = z.array(z.object({ id: z.string(), slug: z.string(), email: z.string().nullable().optional() }));
706
+ if (wordpress) {
707
+ const existingAuthors = directoryRows.element.extend({ path: z.string() }).array().parse(await ctx.call(getService("cms.listAuthors"), {}));
708
+ for (const author of wordpress.authors) {
709
+ const slug = toCmsSlug(author.login).replaceAll("/", "-") || "author";
710
+ const existing = existingAuthors.find(row => row.slug === slug || (author.email && row.email?.toLowerCase() === author.email.toLowerCase()));
711
+ const saved = existing ?? z.object({ id: z.string() }).parse(await ctx.call(getService("cms.saveAuthor"), {
712
+ name: author.displayName || author.login, slug, email: author.email ?? null, path: `author/${slug}`, source: blogSource,
713
+ }));
714
+ authorIds.set(author.login, saved.id);
715
+ if (existing && existing.path !== `author/${slug}`) archiveAliases.push({ fromPath: `author/${slug}`, toPath: existing.path });
716
+ }
717
+ const existingTerms = z.array(z.object({ id: z.string(), slug: z.string(), taxonomy: z.string(), path: z.string() })).parse(await ctx.call(getService("cms.listTerms"), {}));
718
+ for (const taxonomy of ["category", "tag"] as const) {
719
+ const items = taxonomy === "category" ? wordpress.taxonomy.categories : wordpress.taxonomy.tags;
720
+ const ids = taxonomy === "category" ? categoryIds : tagIds;
721
+ const remaining = [...items];
722
+ for (let pass = 0; remaining.length && pass <= items.length; pass += 1) {
723
+ for (let index = remaining.length - 1; index >= 0; index -= 1) {
724
+ const term = remaining[index]!;
725
+ const parentSlug = taxonomy === "category" ? (term as { parentSlug?: string }).parentSlug : undefined;
726
+ if (parentSlug && items.some(row => row.slug === parentSlug) && !ids.has(parentSlug)) continue;
727
+ const slug = toCmsSlug(term.slug).replaceAll("/", "-");
728
+ const path = parentSlug && categoryPaths.has(parentSlug) ? `${categoryPaths.get(parentSlug)}/${slug}` : `${taxonomy}/${slug}`;
729
+ const existing = existingTerms.find(row => row.taxonomy === taxonomy && row.slug === slug);
730
+ const saved = existing ?? z.object({ id: z.string() }).parse(await ctx.call(getService("cms.saveTerm"), {
731
+ taxonomy, name: term.name || slug, slug, description: term.description ?? null,
732
+ parentId: parentSlug ? ids.get(parentSlug) ?? null : null,
733
+ // WordPress archive addresses are kept, independent of Freeholder's defaults.
734
+ path, source: blogSource,
735
+ }));
736
+ ids.set(term.slug, saved.id);
737
+ if (taxonomy === "category") categoryPaths.set(term.slug, path);
738
+ if (existing && existing.path !== path) archiveAliases.push({ fromPath: path, toPath: existing.path });
739
+ remaining.splice(index, 1);
740
+ }
741
+ }
742
+ if (remaining.length) throw new ServiceError("validation", "The imported category hierarchy contains a cycle. Correct the export before committing.");
743
+ }
744
+ }
657
745
 
658
746
  // Media and links, for WordPress bodies.
659
747
  const records = mediaRecordsFrom(before.checkpoint);
@@ -722,6 +810,7 @@ const commitApply = defineService({
722
810
  let droppedEmbeds = 0;
723
811
  let flattenedHtml = 0;
724
812
  let posts = 0;
813
+ let commentsImported = 0;
725
814
  const landed: Placement[] = [];
726
815
 
727
816
  for (const placement of placements) {
@@ -731,7 +820,7 @@ const commitApply = defineService({
731
820
  continue;
732
821
  }
733
822
  let blocks: unknown[];
734
- let seo: { title?: string; description?: string } = {};
823
+ let seo: WordpressSeo = {};
735
824
  if (wordpress) {
736
825
  const featuredKey = page.featuredMedia;
737
826
  const featuredAsset = featuredKey ? assetByKey.get(featuredKey) : undefined;
@@ -754,8 +843,10 @@ const commitApply = defineService({
754
843
  droppedEmbeds += converted.droppedEmbeds;
755
844
  flattenedHtml += converted.flattenedHtml;
756
845
  seo = Object.fromEntries(
757
- Object.entries(page.seo ?? {}).filter(([, value]) => typeof value === "string" && value !== ""),
846
+ Object.entries(page.seo ?? {}).filter(([, value]) => (typeof value === "string" && value !== "") || value === true),
758
847
  );
848
+ if (seo.canonical) seo.canonical = rewriteHref(seo.canonical);
849
+ page.seo = seo;
759
850
  } else {
760
851
  blocks = importedBlocks(slug, page.title, page.body);
761
852
  }
@@ -782,6 +873,28 @@ const commitApply = defineService({
782
873
  id = created.id;
783
874
  }
784
875
  if (page.status === "draft") draftPageIds.push(id);
876
+ if (wordpress && placement.action === "replace") {
877
+ postSnapshots.push(await ctx.call(getService("cms.getPostMeta"), { pageId: id }));
878
+ if (page.kind !== "post") {
879
+ const meta = { pageId: id, isPost: false };
880
+ if (placement.current?.status === "published") pendingBlogPosts.push({ pageId: id, key: page.wpId ?? slug, meta, comments: [] });
881
+ else await ctx.call(getService("cms.setPostMeta"), meta);
882
+ }
883
+ }
884
+ if (wordpress && page.kind === "post") {
885
+ const meta = {
886
+ pageId: id, isPost: true, authorId: page.author ? authorIds.get(page.author) ?? null : null,
887
+ categoryIds: (page.categorySlugs ?? []).flatMap(slug => categoryIds.has(slug) ? [categoryIds.get(slug)!] : []),
888
+ tagIds: (page.tagSlugs ?? []).flatMap(slug => tagIds.has(slug) ? [tagIds.get(slug)!] : []),
889
+ source: blogSource, sourceModifiedAt: page.modifiedAt,
890
+ };
891
+ if (placement.action === "replace" && placement.current?.status === "published") {
892
+ pendingBlogPosts.push({ pageId: id, key: page.wpId ?? slug, meta, comments: page.readerComments ?? [] });
893
+ } else {
894
+ await ctx.call(getService("cms.setPostMeta"), meta);
895
+ commentsImported += await importPostComments(ctx, before.id, id, page.wpId ?? slug, page.readerComments ?? []);
896
+ }
897
+ }
785
898
  if (page.publishedAt) publishedAt[id] = page.publishedAt;
786
899
  if (page.kind === "post") posts += 1;
787
900
  if (page.wpId) slugByWpId.set(page.wpId, slug);
@@ -886,6 +999,7 @@ const commitApply = defineService({
886
999
  : undefined,
887
1000
  }));
888
1001
 
1002
+ const commentsStaged = pendingBlogPosts.reduce((total, post) => total + post.comments.length, 0);
889
1003
  const mediaImported = records.filter((record) => record.assetId).length;
890
1004
  const mediaFailures = records.filter((record) => !record.assetId);
891
1005
  const report = wordpress
@@ -902,10 +1016,12 @@ const commitApply = defineService({
902
1016
  menus: menus.map(({ slug, name, links, nested, unresolved }) => ({ slug, name, links: links.length, nested, unresolved })),
903
1017
  // Said out loud so nobody reads a silent zero as "done".
904
1018
  notRecreated: [
905
- "Categories and tags are recorded here; Freeholder's blog has no taxonomy to file them under.",
906
- "Authors are recorded here; Freeholder pages do not carry an author.",
907
- "Reader comments are not imported; CMS pages have no public comment thread.",
1019
+ ...(Number((wordpress.report.comments as { total?: number } | undefined)?.total ?? 0) > commentsImported + commentsStaged ? ["Unsupported comment types, comments on ordinary pages or skipped posts remain in the source export; counts.commentsSkipped reports the difference."] : []),
1020
+ ...(wordpress.attachments.some(attachment => !attachment.parentWpId || !slugByWpId.has(attachment.parentWpId)) ? ["Orphan attachment pages need an owner-selected destination."] : []),
1021
+ "WordPress /feed is already Freeholder’s member feed; root ?feed=rss2/atom/rss aliases use /feeds/blog.xml. Review this reserved-path collision before DNS cutover.",
1022
+ "WXR does not carry rendered hreflang or all plugin-generated metadata. Compare the source crawl with the destination before DNS cutover.",
908
1023
  ],
1024
+ commentsImported, commentsStaged,
909
1025
  }
910
1026
  : undefined;
911
1027
  const counts = wordpress
@@ -919,7 +1035,8 @@ const commitApply = defineService({
919
1035
  categories: wordpress.taxonomy.categories.length,
920
1036
  tags: wordpress.taxonomy.tags.length,
921
1037
  authors: authors.length,
922
- commentsSkipped: Number((wordpress.report.comments as { total?: number } | undefined)?.total ?? 0),
1038
+ commentsImported, commentsStaged,
1039
+ commentsSkipped: Math.max(0, Number((wordpress.report.comments as { total?: number } | undefined)?.total ?? 0) - commentsImported - commentsStaged),
923
1040
  skippedPages: skippedPages.length,
924
1041
  }
925
1042
  : { pages: createdPageIds.length + replacedPages.length, media: 0, redirects: 0 };
@@ -930,6 +1047,21 @@ const commitApply = defineService({
930
1047
  publishedAt,
931
1048
  redirectIds,
932
1049
  displacedRedirects,
1050
+ postSnapshots, pendingBlogPosts,
1051
+ landedPaths: landed.map(({ page, slug }) => ({ sourceUrl: page.url, path: slug, status: page.status ?? "publish", seo: page.seo ?? {} })),
1052
+ legacyAliases: [
1053
+ ...archiveAliases,
1054
+ ...(wordpress?.attachments ?? []).flatMap(attachment => {
1055
+ const target = attachment.parentWpId ? slugByWpId.get(attachment.parentWpId) : undefined;
1056
+ if (target === undefined) return [];
1057
+ return [
1058
+ ...(attachment.path ? [{ fromPath: attachment.path, toPath: target }] : []),
1059
+ ...(attachment.wpId ? ["", "index.php"].map(root => ({ fromPath: `${root}?attachment_id=${attachment.wpId}`, toPath: target })) : []),
1060
+ ];
1061
+ }),
1062
+ ...(wordpress ? ["rss2", "atom", "rss"].map(feed => ({ fromPath: `?feed=${feed}`, toPath: "feeds/blog.xml" })) : []),
1063
+ ...landed.flatMap(({ page, slug }) => page.wpId ? ["p", "page_id"].flatMap(key => ["", "index.php"].map(root => ({ fromPath: `${root}?${key}=${page.wpId}`, toPath: slug }))) : []),
1064
+ ],
933
1065
  menus,
934
1066
  ...(blogIndexPageId ? { blogIndexPageId } : {}),
935
1067
  ...(report ? { report } : {}),
@@ -1032,6 +1164,11 @@ export const rollbackImport = defineService({
1032
1164
  }
1033
1165
  }
1034
1166
  }
1167
+ for (const snapshot of Array.isArray(checkpoint.postSnapshots) ? checkpoint.postSnapshots : []) {
1168
+ await ctx.call(getService("cms.setPostMeta"), snapshot);
1169
+ }
1170
+ await ctx.call(getService("cms.rollbackImportedBlogProfiles"), { runId: before.id });
1171
+ await ctx.call(getService("cms.rollbackImportedReaderComments"), { runId: before.id });
1035
1172
 
1036
1173
  for (const id of stringIds(checkpoint.redirectIds)) {
1037
1174
  try {
@@ -1267,6 +1404,37 @@ export const publishImport = defineService({
1267
1404
  });
1268
1405
  }
1269
1406
 
1407
+ const pending = pendingBlogPost.array().parse(checkpoint.pendingBlogPosts ?? []);
1408
+ let stagedCommentsImported = 0;
1409
+ for (const post of pending) {
1410
+ await ctx.call(getService("cms.setPostMeta"), post.meta);
1411
+ stagedCommentsImported += await importPostComments(ctx, before.id, post.pageId, post.key, post.comments);
1412
+ }
1413
+
1414
+ // Query-ID aliases are activated at cutover, never while imported content
1415
+ // remains a private draft. Existing redirects are preserved and reported.
1416
+ const aliasSchema = z.array(z.object({ fromPath: z.string(), toPath: z.string() }));
1417
+ const aliases = aliasSchema.safeParse(checkpoint.legacyAliases);
1418
+ const redirectIds = stringIds(checkpoint.redirectIds);
1419
+ const skippedAliases: Array<{ fromPath: string; reason: string }> = [];
1420
+ if (aliases.success) {
1421
+ const landings = z.array(z.object({ path: z.string(), status: z.string() })).safeParse(checkpoint.landedPaths);
1422
+ const draftPaths = new Set(landings.success ? landings.data.filter(page => page.status === "draft").map(page => page.path) : []);
1423
+ const existing = z.array(z.object({ fromPath: z.string() })).parse(await ctx.call(getService("seo.listRedirects"), {}));
1424
+ const occupied = new Set(existing.map(row => row.fromPath));
1425
+ for (const alias of aliases.data) {
1426
+ if (draftPaths.has(alias.toPath)) continue;
1427
+ if (alias.toPath !== "feeds/blog.xml") {
1428
+ const page = await ctx.call(getService("cms.resolvePage"), { slug: alias.toPath, locale: "en" });
1429
+ const archive = page ? null : await ctx.call(getService("cms.resolveBlogArchive"), { path: alias.toPath });
1430
+ if (!page && !archive) { skippedAliases.push({ fromPath: alias.fromPath, reason: "destination is not public" }); continue; }
1431
+ }
1432
+ if (occupied.has(alias.fromPath)) { skippedAliases.push({ fromPath: alias.fromPath, reason: "existing redirect preserved" }); continue; }
1433
+ const created = z.object({ id: z.string() }).parse(await ctx.call(getService("seo.recordRedirect"), { ...alias, source: "import" }));
1434
+ redirectIds.push(created.id); occupied.add(alias.fromPath);
1435
+ }
1436
+ }
1437
+
1270
1438
  // One imported menu joins the site's nav section; the rest stay on record.
1271
1439
  let navApplied: z.infer<typeof navAppliedSchema> | undefined;
1272
1440
  const menus = resolvedMenusSchema.safeParse(checkpoint.menus);
@@ -1289,7 +1457,7 @@ export const publishImport = defineService({
1289
1457
  }
1290
1458
  const [row] = await ctx.tx
1291
1459
  .update(importRuns)
1292
- .set({ status: "published", checkpoint: { ...checkpoint, ...(navApplied ? { navApplied } : {}) } })
1460
+ .set({ status: "published", counts: { ...checkpointOf(before.counts), commentsImported: Number(checkpointOf(before.counts).commentsImported ?? 0) + stagedCommentsImported, commentsStaged: 0 }, checkpoint: { ...checkpoint, pendingBlogPosts: [], redirectIds, skippedAliases, ...(navApplied ? { navApplied } : {}) } })
1293
1461
  .where(eq(importRuns.id, input.id))
1294
1462
  .returning();
1295
1463
  ctx.setSubject("import_run", row!.id);
@@ -1325,6 +1493,7 @@ export function stageWordpressExport(exported: WordpressExport, origin: string):
1325
1493
  menus: plan.menus,
1326
1494
  authors: plan.authors,
1327
1495
  taxonomy: plan.taxonomy,
1496
+ attachments: exported.attachments.map(attachment => ({ wpId: attachment.wpId, parentWpId: attachment.parentWpId, path: attachment.url ? wordpressPath(attachment.url, plan.site.hosts, plan.site.basePath) ?? undefined : undefined })),
1328
1497
  report: plan.report,
1329
1498
  },
1330
1499
  },
@@ -1424,7 +1593,43 @@ export const previewFromSource = defineService({
1424
1593
  },
1425
1594
  });
1426
1595
 
1596
+ export const wordpressVerificationPlan = defineService({
1597
+ name: "imports.wordpressVerificationPlan",
1598
+ summary: "A read-only URL and metadata acceptance manifest for a committed WordPress migration; unresolved source features remain explicit.",
1599
+ kind: "query", permission: "scoped", input: z.object({ id: uuid }),
1600
+ output: z.object({ sourceOrigin: z.string(), status: z.string(), checks: z.array(z.object({ sourceUrl: z.string(), requestPath: z.string(), destinationPath: z.string(), redirect: z.boolean(), expected: z.record(z.string(), z.unknown()) })), warnings: z.array(z.string()) }),
1601
+ handler: async (input, ctx) => {
1602
+ const [run] = await ctx.tx.select().from(importRuns).where(eq(importRuns.id, input.id)).limit(1);
1603
+ if (!run) throw new ServiceError("not_found", "No such import run.");
1604
+ if (!run.kind?.startsWith("wordpress-")) throw new ServiceError("validation", "URL acceptance manifests apply to WordPress imports.");
1605
+ const checkpoint = checkpointOf(run.checkpoint);
1606
+ const landed = z.array(z.object({ sourceUrl: z.string(), path: z.string(), status: z.string(), seo: z.record(z.string(), z.unknown()) })).safeParse(checkpoint.landedPaths);
1607
+ if (!landed.success) throw new ServiceError("conflict", "Commit a WordPress import with URL acceptance records before requesting verification.");
1608
+ const published = landed.data.filter(page => page.status !== "draft");
1609
+ const drafts = new Set(landed.data.filter(page => page.status === "draft").map(page => page.path));
1610
+ const sourceOrigin = run.origin ?? "";
1611
+ const checks = published.map(page => ({ sourceUrl: page.sourceUrl, requestPath: `/${page.path}`, destinationPath: `/${page.path}`, redirect: false, expected: page.seo }));
1612
+ for (const page of published) {
1613
+ const original = new URL(page.sourceUrl);
1614
+ if (original.pathname !== `/${page.path}`) checks.push({ sourceUrl: page.sourceUrl, requestPath: `${original.pathname}${original.search}`, destinationPath: `/${page.path}`, redirect: true, expected: {} });
1615
+ }
1616
+ const aliases = z.array(z.object({ fromPath: z.string(), toPath: z.string() })).safeParse(checkpoint.legacyAliases);
1617
+ const skipped = z.array(z.object({ fromPath: z.string(), reason: z.string() })).safeParse(checkpoint.skippedAliases);
1618
+ const excluded = new Set(skipped.success ? skipped.data.map(alias => alias.fromPath) : []);
1619
+ if (aliases.success) for (const alias of aliases.data) {
1620
+ if (drafts.has(alias.toPath) || excluded.has(alias.fromPath)) continue;
1621
+ checks.push({ sourceUrl: new URL(`/${alias.fromPath}`, sourceOrigin).href, requestPath: `/${alias.fromPath}`, destinationPath: `/${alias.toPath}`, redirect: true, expected: {} });
1622
+ }
1623
+ const report = checkpointOf(checkpoint.report);
1624
+ const warnings = stringIds(report.notRecreated);
1625
+ if (skipped.success) warnings.push(...skipped.data.map(alias => `${alias.fromPath}: ${alias.reason}`));
1626
+ if (run.status !== "published") warnings.push("The import has not been published; draft privacy is expected and cutover acceptance cannot pass yet.");
1627
+ return { sourceOrigin, status: run.status, checks, warnings };
1628
+ },
1629
+ });
1630
+
1427
1631
  export default [
1632
+ wordpressVerificationPlan,
1428
1633
  startImport,
1429
1634
  previewImport,
1430
1635
  previewFromSource,
@@ -25,6 +25,7 @@ import {
25
25
  serializeOuter,
26
26
  type DefaultTreeAdapterTypes,
27
27
  } from "parse5";
28
+ import { z } from "zod";
28
29
  import { sanitizeOwnerHtml } from "@/modules/cms/blocks/html";
29
30
  import {
30
31
  richBlockSchema,
@@ -56,8 +57,8 @@ export const WORDPRESS_MEDIA_LIMITS = {
56
57
  } as const;
57
58
 
58
59
  /** CMS field limits the importer has to fit (cms.createPage `seo`). */
59
- const SEO_TITLE_MAX = 60;
60
- const SEO_DESCRIPTION_MAX = 155;
60
+ const SEO_TITLE_MAX = 1000;
61
+ const SEO_DESCRIPTION_MAX = 1000;
61
62
  const HTML_BLOCK_MAX = 20_000;
62
63
  const RICH_BLOCKS_PER_TEXT = 200;
63
64
  const GALLERY_MAX = 24;
@@ -66,7 +67,10 @@ const GALLERY_MAX = 24;
66
67
 
67
68
  export type WordpressStatus = "publish" | "draft";
68
69
 
69
- export type WordpressTerm = { slug: string; name: string };
70
+ export type WordpressTerm = { slug: string; name: string; parentSlug?: string; description?: string };
71
+ export type WordpressComment = { id: string; parentId?: string; name: string; email: string | null; body: string; status: "pending" | "approved" | "spam" | "trash"; createdAt?: string };
72
+
73
+ export type WordpressSeo = { title?: string; description?: string; preserveTitle?: boolean; preserveDescription?: boolean; noindex?: boolean; nofollow?: boolean; canonical?: string; ogTitle?: string; ogDescription?: string; ogImage?: string };
70
74
 
71
75
  export type WordpressItem = {
72
76
  wpId?: string;
@@ -79,18 +83,20 @@ export type WordpressItem = {
79
83
  /** The raw WordPress status, for the report ("private", "future", ...). */
80
84
  wpStatus: string;
81
85
  publishedAt?: string;
86
+ modifiedAt?: string;
82
87
  author?: string;
83
88
  categories: WordpressTerm[];
84
89
  tags: WordpressTerm[];
85
- seo: { title?: string; description?: string };
90
+ seo: WordpressSeo;
86
91
  featuredWpId?: string;
87
92
  /** For REST exports with `_embed`, the featured image's URL directly. */
88
93
  featuredUrl?: string;
89
94
  passwordProtected: boolean;
90
- comments: { total: number; approved: number };
95
+ comments: { total: number; approved: number; entries?: WordpressComment[] };
91
96
  };
92
97
 
93
98
  export type WordpressAttachment = {
99
+ url?: string;
94
100
  wpId?: string;
95
101
  sourceUrl: string;
96
102
  title?: string;
@@ -118,6 +124,7 @@ export type WordpressExport = {
118
124
  items: WordpressItem[];
119
125
  attachments: WordpressAttachment[];
120
126
  authors: WordpressAuthor[];
127
+ taxonomy?: { categories: WordpressTerm[]; tags: WordpressTerm[] };
121
128
  menus: { slug: string; name: string }[];
122
129
  menuItems: WordpressMenuItem[];
123
130
  /** Items left out on purpose, by reason ("post type: product", "status: trash"). */
@@ -134,15 +141,19 @@ export type PlannedPage = {
134
141
  status: WordpressStatus;
135
142
  wpStatus: string;
136
143
  publishedAt?: string;
144
+ modifiedAt?: string;
137
145
  /** The old WordPress path, when it differs from the new slug. */
138
146
  redirectFrom?: string;
139
- seo: { title?: string; description?: string };
147
+ seo: WordpressSeo;
140
148
  author?: string;
141
149
  categories: string[];
142
150
  tags: string[];
151
+ categorySlugs?: string[];
152
+ tagSlugs?: string[];
143
153
  featuredMedia?: string;
144
154
  wpId?: string;
145
155
  comments: number;
156
+ readerComments?: WordpressComment[];
146
157
  };
147
158
 
148
159
  export type PlannedMedia = {
@@ -274,6 +285,23 @@ function htmlText(value: string): string {
274
285
  return textContentOf(parseFragment(value)).replace(/\s+/g, " ").trim();
275
286
  }
276
287
 
288
+ /** Reader comments stay plain text without joining words across HTML paragraphs. */
289
+ function commentText(value: string): string {
290
+ const parts: string[] = [];
291
+ const visit = (node: DefaultTreeAdapterTypes.Node) => {
292
+ if (node.nodeName === "#text") { parts.push((node as DefaultTreeAdapterTypes.TextNode).value); return; }
293
+ const tag = "tagName" in node ? node.tagName : "";
294
+ if (["script", "style"].includes(tag)) return;
295
+ if (tag === "br") { parts.push("\n"); return; }
296
+ const block = ["p", "div", "li", "blockquote", "pre"].includes(tag);
297
+ if (block) parts.push("\n");
298
+ if ("childNodes" in node) for (const child of node.childNodes) visit(child);
299
+ if (block) parts.push("\n");
300
+ };
301
+ visit(parseFragment(value));
302
+ return parts.join("").replace(/[ \t]+\n/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
303
+ }
304
+
277
305
  function wordpressDate(value: string): string | undefined {
278
306
  const match = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2}):(\d{2})/.exec(value.trim());
279
307
  if (!match || match[1] === "0000") return undefined;
@@ -434,6 +462,7 @@ export function wordpressExportBuilder() {
434
462
  let siteTitle = "";
435
463
  let site: WordpressExport["site"] = { title: "", url: "" };
436
464
  let authors: WordpressAuthor[] = [];
465
+ let taxonomy: NonNullable<WordpressExport["taxonomy"]> = { categories: [], tags: [] };
437
466
  let menus: WordpressExport["menus"] = [];
438
467
  const items: WordpressItem[] = [];
439
468
  const attachments: WordpressAttachment[] = [];
@@ -455,6 +484,18 @@ export function wordpressExportBuilder() {
455
484
  displayName: htmlText(child(inner, "wp:author_display_name", masked, "raw")) || undefined,
456
485
  email: child(inner, "wp:author_email", masked) || undefined,
457
486
  })).filter((author) => author.login);
487
+ taxonomy = {
488
+ categories: elements(text, "wp:category").map(({ inner }) => ({
489
+ slug: child(inner, "wp:category_nicename", masked),
490
+ name: htmlText(child(inner, "wp:cat_name", masked, "raw")),
491
+ parentSlug: child(inner, "wp:category_parent", masked) || undefined,
492
+ description: htmlText(child(inner, "wp:category_description", masked, "raw")) || undefined,
493
+ })).filter(term => term.slug),
494
+ tags: elements(text, "wp:tag").map(({ inner }) => ({
495
+ slug: child(inner, "wp:tag_slug", masked), name: htmlText(child(inner, "wp:tag_name", masked, "raw")),
496
+ description: htmlText(child(inner, "wp:tag_description", masked, "raw")) || undefined,
497
+ })).filter(term => term.slug),
498
+ };
458
499
  menus = elements(text, "wp:term")
459
500
  .filter(({ inner }) => child(inner, "wp:term_taxonomy", masked) === "nav_menu")
460
501
  .map(({ inner }) => ({
@@ -487,7 +528,7 @@ export function wordpressExportBuilder() {
487
528
  const sourceUrl = child(fields, "wp:attachment_url", masked) || child(fields, "guid", masked);
488
529
  if (!sourceUrl) return;
489
530
  attachments.push({
490
- wpId,
531
+ wpId, url: child(fields, "link", masked) || undefined,
491
532
  sourceUrl,
492
533
  title: title || undefined,
493
534
  altText: htmlText(meta.get("_wp_attachment_image_alt") ?? "") || undefined,
@@ -539,25 +580,45 @@ export function wordpressExportBuilder() {
539
580
  wordpressDate(child(fields, "wp:post_date_gmt", masked)) ??
540
581
  rfcDate(child(fields, "pubDate", masked)) ??
541
582
  wordpressDate(child(fields, "wp:post_date", masked)),
583
+ modifiedAt: wordpressDate(child(fields, "wp:post_modified_gmt", masked)) ?? wordpressDate(child(fields, "wp:post_modified", masked)),
542
584
  author: child(fields, "dc:creator", masked) || undefined,
543
585
  categories: terms.filter((term) => term.domain === "category").map(({ slug, name }) => ({ slug, name })),
544
586
  tags: terms.filter((term) => term.domain === "post_tag").map(({ slug, name }) => ({ slug, name })),
545
587
  seo: {
546
588
  title: expandSeoTemplate(htmlText(seoTitle), title, siteTitle) || undefined,
547
589
  description: expandSeoTemplate(htmlText(seoDescription), title, siteTitle) || undefined,
590
+ noindex: meta.get("_yoast_wpseo_meta-robots-noindex") === "1" || /noindex/.test(meta.get("rank_math_robots") ?? ""),
591
+ nofollow: meta.get("_yoast_wpseo_meta-robots-nofollow") === "1" || /nofollow/.test(meta.get("rank_math_robots") ?? ""),
592
+ canonical: meta.get("_yoast_wpseo_canonical") || meta.get("rank_math_canonical_url") || undefined,
593
+ ogTitle: htmlText(meta.get("_yoast_wpseo_opengraph-title") || meta.get("rank_math_facebook_title") || "") || undefined,
594
+ ogDescription: htmlText(meta.get("_yoast_wpseo_opengraph-description") || meta.get("rank_math_facebook_description") || "") || undefined,
595
+ ogImage: meta.get("_yoast_wpseo_opengraph-image") || meta.get("rank_math_facebook_image") || undefined,
548
596
  },
549
597
  featuredWpId: meta.get("_thumbnail_id") || undefined,
550
598
  passwordProtected: child(fields, "wp:post_password", masked) !== "",
551
599
  comments: {
552
600
  total: comments.length,
553
601
  approved: comments.filter(({ inner }) => child(inner, "wp:comment_approved", masked) === "1").length,
602
+ entries: comments.filter(({ inner }) => !child(inner, "wp:comment_type", masked) || child(inner, "wp:comment_type", masked) === "comment").map(({ inner }, index) => {
603
+ const status = child(inner, "wp:comment_approved", masked);
604
+ const email = z.string().email().safeParse(child(inner, "wp:comment_author_email", masked));
605
+ return {
606
+ id: child(inner, "wp:comment_id", masked) || `${wpId ?? items.length}-${index}`,
607
+ parentId: child(inner, "wp:comment_parent", masked) !== "0" ? child(inner, "wp:comment_parent", masked) || undefined : undefined,
608
+ name: htmlText(child(inner, "wp:comment_author", masked, "raw")) || "Reader",
609
+ email: email.success ? email.data.toLowerCase() : null,
610
+ body: commentText(child(inner, "wp:comment_content", masked, "raw")),
611
+ status: status === "1" ? "approved" as const : status === "spam" ? "spam" as const : status === "trash" ? "trash" as const : "pending" as const,
612
+ createdAt: wordpressDate(child(inner, "wp:comment_date_gmt", masked)) ?? wordpressDate(child(inner, "wp:comment_date", masked)),
613
+ };
614
+ }).filter(comment => comment.body),
554
615
  },
555
616
  });
556
617
  };
557
618
 
558
619
  return {
559
620
  reader: () => new WxrStreamReader(head, item),
560
- finish: (): WordpressExport => ({ site, items, attachments, authors, menus, menuItems, skipped }),
621
+ finish: (): WordpressExport => ({ site, items, attachments, authors, taxonomy, menus, menuItems, skipped }),
561
622
  };
562
623
  }
563
624
 
@@ -864,7 +925,7 @@ export function planWordpressImport(exported: WordpressExport, origin: string):
864
925
  const used = new Set<string>();
865
926
  const unique = (slug: string): string => {
866
927
  let candidate = slug;
867
- for (let n = 2; used.has(candidate); n += 1) candidate = `${slug}-${n}`;
928
+ for (let n = 2; used.has(candidate); n += 1) candidate = `${slug || "home"}-${n}`;
868
929
  used.add(candidate);
869
930
  return candidate;
870
931
  };
@@ -872,17 +933,17 @@ export function planWordpressImport(exported: WordpressExport, origin: string):
872
933
  const wpIdToSlug = new Map<string, string>();
873
934
  const categories = new Map<string, WordpressTerm & { posts: number }>();
874
935
  const tags = new Map<string, WordpressTerm & { posts: number }>();
936
+ for (const term of exported.taxonomy?.categories ?? []) categories.set(term.slug, { ...term, posts: 0 });
937
+ for (const term of exported.taxonomy?.tags ?? []) tags.set(term.slug, { ...term, posts: 0 });
875
938
  const authorPosts = new Map<string, number>();
876
939
 
877
940
  for (const item of exported.items) {
878
941
  const oldPath = wordpressPath(item.url, hosts, basePath);
879
942
  const wpSlug = toCmsSlug(item.slug || slugFromUrl(item.url));
880
943
  const slug = unique(
881
- item.kind === "post"
882
- ? `blog/${(wpSlug.split("/").at(-1) ?? wpSlug) || "post"}`
883
- : oldPath !== null
944
+ oldPath !== null
884
945
  ? toCmsSlug(oldPath)
885
- : wpSlug,
946
+ : item.kind === "post" ? `blog/${(wpSlug.split("/").at(-1) ?? wpSlug) || "post"}` : wpSlug,
886
947
  );
887
948
  if (item.wpId) wpIdToSlug.set(item.wpId, slug);
888
949
 
@@ -924,7 +985,7 @@ export function planWordpressImport(exported: WordpressExport, origin: string):
924
985
  featuredMedia = featured.key;
925
986
  }
926
987
 
927
- const title = trimTo(item.seo.title, SEO_TITLE_MAX);
988
+ const title = trimTo(item.seo.title || item.title, SEO_TITLE_MAX);
928
989
  const description = trimTo(item.seo.description, SEO_DESCRIPTION_MAX);
929
990
  if (title.trimmed || description.trimmed) report.seoTrimmed += 1;
930
991
  if (item.status === "draft") report.drafts += 1;
@@ -952,14 +1013,18 @@ export function planWordpressImport(exported: WordpressExport, origin: string):
952
1013
  status: item.passwordProtected ? "draft" : item.status,
953
1014
  wpStatus: item.wpStatus,
954
1015
  publishedAt: item.publishedAt,
1016
+ modifiedAt: item.modifiedAt,
955
1017
  redirectFrom: oldPath !== null && oldPath !== "" && oldPath !== slug ? oldPath : undefined,
956
- seo: { title: title.value, description: description.value },
1018
+ seo: { ...item.seo, ...(item.seo.canonical ? { canonical: wordpressPath(item.seo.canonical, hosts, basePath) !== null ? `/${wordpressPath(item.seo.canonical, hosts, basePath)}` : item.seo.canonical } : {}), title: title.value, description: description.value, ...(title.value ? { preserveTitle: true } : {}), ...(description.value ? { preserveDescription: true } : {}) },
957
1019
  author: item.author,
958
1020
  categories: item.categories.map((term) => term.name),
959
1021
  tags: item.tags.map((term) => term.name),
1022
+ categorySlugs: item.categories.map((term) => term.slug),
1023
+ tagSlugs: item.tags.map((term) => term.slug),
960
1024
  featuredMedia,
961
1025
  wpId: item.wpId,
962
1026
  comments: item.comments.total,
1027
+ readerComments: item.comments.entries,
963
1028
  });
964
1029
  }
965
1030
 
@@ -56,6 +56,7 @@ import {
56
56
  export const NOTIFICATION_TOPICS = [
57
57
  "briefing.ready",
58
58
  "forms.submission",
59
+ "cms.comment_pending",
59
60
  "connections.attention",
60
61
  "agents.failed",
61
62
  "agents.budget",