@jant/core 0.6.14 → 0.6.15

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 (311) hide show
  1. package/bin/commands/import-site.js +81 -13
  2. package/bin/commands/migrate.js +55 -0
  3. package/bin/commands/posts/rebuild-html.js +184 -0
  4. package/bin/commands/site/snapshot/import.js +14 -10
  5. package/bin/lib/d1-query.js +23 -5
  6. package/bin/lib/migration-runner.js +29 -7
  7. package/bin/lib/node-database.js +32 -0
  8. package/bin/lib/site-snapshot.js +347 -46
  9. package/bin/lib/sql-export.js +1 -1
  10. package/bin/lib/thread-collection-migration.js +326 -0
  11. package/dist/app-BxCOR3Uc.js +6 -0
  12. package/dist/{app-2i7-WQHg.js → app-C-oi_t8W.js} +7408 -6343
  13. package/dist/client/.vite/manifest.json +3 -3
  14. package/dist/client/_assets/client-B_eGKN5p.css +2 -0
  15. package/dist/client/_assets/{client-BvID5ucz.js → client-DxY5BFe8.js} +58 -37
  16. package/dist/client/_assets/client-auth-CakPESv9.js +5533 -0
  17. package/dist/{export-DWn149b7.js → export-CsFx6F_M.js} +1259 -125
  18. package/dist/{github-sync-Ckk0sJxK.js → github-sync-Cq1pzzOI.js} +1 -1
  19. package/dist/{github-sync-C0zyF6XS.js → github-sync-ppWXN3jb.js} +2 -2
  20. package/dist/index.js +3 -3
  21. package/dist/node.js +5 -5
  22. package/package.json +11 -10
  23. package/src/__tests__/bin/posts-rebuild-html.test.ts +137 -0
  24. package/src/__tests__/dev-navigation-defaults.test.ts +22 -0
  25. package/src/__tests__/export-hugo-build.test.ts +63 -4
  26. package/src/__tests__/export-import-roundtrip.test.ts +6 -4
  27. package/src/__tests__/export-service.test.ts +142 -9
  28. package/src/__tests__/helpers/app.ts +3 -0
  29. package/src/__tests__/helpers/export-fixtures.ts +2 -0
  30. package/src/__tests__/import-site-command.test.ts +65 -0
  31. package/src/__tests__/vite-config.test.ts +45 -0
  32. package/src/app.tsx +16 -3
  33. package/src/client/__tests__/collection-created-notice.test.ts +36 -0
  34. package/src/client/__tests__/collection-form-bridge.test.ts +10 -1
  35. package/src/client/__tests__/collection-page-actions.test.ts +71 -2
  36. package/src/client/__tests__/compose-bridge.test.ts +64 -0
  37. package/src/client/__tests__/feed-video-player.test.ts +16 -1
  38. package/src/client/__tests__/footnote-rail.test.ts +472 -0
  39. package/src/client/__tests__/hydrate-partial.test.ts +3 -0
  40. package/src/client/__tests__/toast.test.ts +18 -1
  41. package/src/client/collection-created-notice.ts +66 -0
  42. package/src/client/collection-form-bridge.ts +17 -0
  43. package/src/client/collection-navigation.ts +44 -0
  44. package/src/client/collection-page-actions.ts +57 -1
  45. package/src/client/components/__tests__/jant-collection-directory.test.ts +155 -6
  46. package/src/client/components/__tests__/jant-compose-dialog.test.ts +370 -5
  47. package/src/client/components/__tests__/jant-compose-editor.test.ts +97 -0
  48. package/src/client/components/__tests__/jant-compose-fullscreen.test.ts +104 -0
  49. package/src/client/components/__tests__/jant-config-editor.test.ts +405 -0
  50. package/src/client/components/__tests__/jant-media-lightbox.test.ts +121 -0
  51. package/src/client/components/__tests__/jant-nav-manager.test.ts +538 -2
  52. package/src/client/components/__tests__/jant-post-form.test.ts +2 -2
  53. package/src/client/components/__tests__/jant-post-menu.test.ts +47 -5
  54. package/src/client/components/__tests__/jant-settings-avatar.test.ts +2 -2
  55. package/src/client/components/__tests__/jant-settings-general.test.ts +3 -3
  56. package/src/client/components/collection-manager-types.ts +9 -3
  57. package/src/client/components/compose-types.ts +8 -0
  58. package/src/client/components/jant-collection-directory.ts +165 -30
  59. package/src/client/components/jant-command-palette.ts +2 -1
  60. package/src/client/components/jant-compose-dialog.ts +85 -21
  61. package/src/client/components/jant-compose-editor.ts +13 -7
  62. package/src/client/components/jant-compose-fullscreen.ts +24 -4
  63. package/src/client/components/jant-config-editor.ts +722 -0
  64. package/src/client/components/jant-media-lightbox.ts +100 -18
  65. package/src/client/components/jant-nav-manager.ts +1283 -54
  66. package/src/client/components/jant-post-form.ts +3 -3
  67. package/src/client/components/jant-post-menu.ts +86 -74
  68. package/src/client/components/nav-manager-types.ts +51 -2
  69. package/src/client/components/post-form-types.ts +1 -1
  70. package/src/client/compose-bridge.ts +4 -1
  71. package/src/client/feed-video-player.ts +62 -2
  72. package/src/client/footnote-rail.ts +478 -0
  73. package/src/client/hydrate-partial.ts +2 -0
  74. package/src/client/media-lightbox-events.ts +63 -0
  75. package/src/client/site-header-fragment.ts +38 -0
  76. package/src/client/tiptap/__tests__/blockquote-editing.test.ts +201 -0
  77. package/src/client/tiptap/__tests__/clear-formatting.test.ts +168 -0
  78. package/src/client/tiptap/__tests__/list-editing.test.ts +447 -0
  79. package/src/client/tiptap/__tests__/markdown-clipboard.test.ts +727 -4
  80. package/src/client/tiptap/__tests__/table-controls.test.ts +263 -0
  81. package/src/client/tiptap/__tests__/table-size-picker.test.ts +179 -0
  82. package/src/client/tiptap/bubble-menu.ts +88 -10
  83. package/src/client/tiptap/continuous-lists.ts +102 -0
  84. package/src/client/tiptap/create-editor.ts +3 -0
  85. package/src/client/tiptap/extensions.ts +14 -5
  86. package/src/client/tiptap/markdown-clipboard.ts +608 -11
  87. package/src/client/tiptap/slash-commands.ts +8 -1
  88. package/src/client/tiptap/structural-keymap.ts +211 -0
  89. package/src/client/tiptap/tab-indent.ts +8 -22
  90. package/src/client/tiptap/table-control-labels.ts +30 -0
  91. package/src/client/tiptap/table-controls.ts +537 -0
  92. package/src/client/tiptap/table-size-picker.ts +254 -0
  93. package/src/client/toast.ts +8 -6
  94. package/src/client-auth.ts +1 -0
  95. package/src/client.ts +1 -0
  96. package/src/db/__tests__/d1-query.test.ts +43 -1
  97. package/src/db/__tests__/migration-runner.test.ts +63 -0
  98. package/src/db/__tests__/migrations.test.ts +469 -0
  99. package/src/db/__tests__/thread-collection-migration.test.ts +364 -0
  100. package/src/db/migrations/0027_old_blue_blade.sql +39 -0
  101. package/src/db/migrations/0028_superb_post.sql +2 -0
  102. package/src/db/migrations/0029_boring_magma.sql +1 -0
  103. package/src/db/migrations/0030_typical_vivisector.sql +50 -0
  104. package/src/db/migrations/meta/0027_snapshot.json +2511 -0
  105. package/src/db/migrations/meta/0028_snapshot.json +2511 -0
  106. package/src/db/migrations/meta/0029_snapshot.json +2519 -0
  107. package/src/db/migrations/meta/0030_snapshot.json +2541 -0
  108. package/src/db/migrations/meta/_journal.json +28 -0
  109. package/src/db/migrations/pg/0025_moaning_epoch.sql +39 -0
  110. package/src/db/migrations/pg/0026_talented_killer_shrike.sql +2 -0
  111. package/src/db/migrations/pg/0027_short_cannonball.sql +1 -0
  112. package/src/db/migrations/pg/0028_perfect_sharon_carter.sql +27 -0
  113. package/src/db/migrations/pg/meta/0025_snapshot.json +3204 -0
  114. package/src/db/migrations/pg/meta/0026_snapshot.json +3204 -0
  115. package/src/db/migrations/pg/meta/0027_snapshot.json +3211 -0
  116. package/src/db/migrations/pg/meta/0028_snapshot.json +3248 -0
  117. package/src/db/migrations/pg/meta/_journal.json +28 -0
  118. package/src/db/pg/schema.ts +28 -20
  119. package/src/db/rehearsal-fixtures/demo-current.json +39 -4
  120. package/src/db/rehearsal-fixtures/demo-current.sql +121 -6
  121. package/src/db/schema.ts +28 -20
  122. package/src/i18n/__tests__/detect.test.ts +8 -2
  123. package/src/i18n/detect.ts +14 -5
  124. package/src/i18n/locales/public/en.po +133 -30
  125. package/src/i18n/locales/public/en.ts +1 -1
  126. package/src/i18n/locales/public/zh-Hans.po +128 -25
  127. package/src/i18n/locales/public/zh-Hans.ts +1 -1
  128. package/src/i18n/locales/public/zh-Hant.po +128 -25
  129. package/src/i18n/locales/public/zh-Hant.ts +1 -1
  130. package/src/i18n/locales/settings/en.po +513 -10
  131. package/src/i18n/locales/settings/en.ts +1 -1
  132. package/src/i18n/locales/settings/zh-Hans.po +515 -12
  133. package/src/i18n/locales/settings/zh-Hans.ts +1 -1
  134. package/src/i18n/locales/settings/zh-Hant.po +515 -12
  135. package/src/i18n/locales/settings/zh-Hant.ts +1 -1
  136. package/src/lib/__tests__/api-settings.test.ts +299 -0
  137. package/src/lib/__tests__/constants.test.ts +5 -0
  138. package/src/lib/__tests__/feed-policy.test.ts +25 -0
  139. package/src/lib/__tests__/footnotes-upgrade.test.ts +181 -0
  140. package/src/lib/__tests__/markdown-roundtrip-embed.test.ts +61 -0
  141. package/src/lib/__tests__/markdown-to-tiptap.test.ts +32 -4
  142. package/src/lib/__tests__/markdown.test.ts +8 -6
  143. package/src/lib/__tests__/navigation.test.ts +59 -2
  144. package/src/lib/__tests__/post-body-html.test.ts +176 -0
  145. package/src/lib/__tests__/post-display.test.ts +64 -0
  146. package/src/lib/__tests__/resolve-config.test.ts +113 -1
  147. package/src/lib/__tests__/summary.test.ts +82 -0
  148. package/src/lib/__tests__/timeline.test.ts +109 -70
  149. package/src/lib/__tests__/timezones.test.ts +31 -3
  150. package/src/lib/__tests__/tiptap-render.test.ts +268 -9
  151. package/src/lib/__tests__/tiptap-to-markdown.test.ts +6 -0
  152. package/src/lib/__tests__/view.test.ts +53 -0
  153. package/src/lib/__tests__/worker-response-cache.test.ts +18 -1
  154. package/src/lib/api-settings.ts +239 -12
  155. package/src/lib/collection-sort.ts +7 -5
  156. package/src/lib/constants.ts +2 -0
  157. package/src/lib/feed-path.ts +25 -0
  158. package/src/lib/feed-policy.ts +64 -0
  159. package/src/lib/footnotes.ts +264 -0
  160. package/src/lib/github-sync-site-config.ts +2 -0
  161. package/src/lib/hugo-markdown.ts +10 -3
  162. package/src/lib/jant-branding.ts +1 -0
  163. package/src/lib/markdown-manager.ts +188 -5
  164. package/src/lib/markdown.ts +10 -3
  165. package/src/lib/navigation.ts +16 -3
  166. package/src/lib/post-body-html.ts +131 -0
  167. package/src/lib/post-display.ts +7 -1
  168. package/src/lib/render.tsx +9 -2
  169. package/src/lib/resolve-config.ts +100 -16
  170. package/src/lib/schemas.ts +133 -1
  171. package/src/lib/settings-paths.ts +5 -0
  172. package/src/lib/site-skill.ts +78 -0
  173. package/src/lib/summary.ts +16 -5
  174. package/src/lib/timeline.ts +98 -122
  175. package/src/lib/timezones.ts +54 -14
  176. package/src/lib/tiptap-render.ts +355 -81
  177. package/src/lib/view.ts +30 -20
  178. package/src/lib/worker-response-cache.ts +11 -18
  179. package/src/middleware/__tests__/public-content-access.test.ts +91 -0
  180. package/src/middleware/config.ts +2 -2
  181. package/src/middleware/public-content-access.ts +87 -0
  182. package/src/node/__tests__/cli-export.test.ts +14 -0
  183. package/src/node/__tests__/cli-migrate.test.ts +6 -0
  184. package/src/node/__tests__/cli-site-snapshot.test.ts +205 -2
  185. package/src/node/__tests__/cli-snapshot-meta.test.ts +100 -0
  186. package/src/node/index.ts +2 -1
  187. package/src/preset.css +16 -2
  188. package/src/routes/__tests__/compose.test.ts +51 -0
  189. package/src/routes/__tests__/site-skill.test.ts +112 -0
  190. package/src/routes/api/__tests__/collections.test.ts +91 -19
  191. package/src/routes/api/__tests__/mcp.test.ts +65 -1
  192. package/src/routes/api/__tests__/nav-items.test.ts +91 -0
  193. package/src/routes/api/__tests__/public-access.test.ts +81 -0
  194. package/src/routes/api/__tests__/settings.test.ts +217 -0
  195. package/src/routes/api/collections.ts +22 -26
  196. package/src/routes/api/export.ts +2 -0
  197. package/src/routes/api/internal/__tests__/post-body-html.test.ts +163 -0
  198. package/src/routes/api/internal/__tests__/sites.test.ts +35 -2
  199. package/src/routes/api/internal/post-body-html.ts +43 -0
  200. package/src/routes/api/internal/sites.ts +24 -0
  201. package/src/routes/api/nav-items.ts +24 -1
  202. package/src/routes/api/posts.ts +2 -2
  203. package/src/routes/api/public/__tests__/archive.test.ts +35 -0
  204. package/src/routes/api/public/__tests__/posts.test.ts +208 -0
  205. package/src/routes/api/public/archive.ts +4 -0
  206. package/src/routes/api/public/posts.ts +41 -24
  207. package/src/routes/api/search.ts +3 -0
  208. package/src/routes/api/settings.ts +33 -0
  209. package/src/routes/auth/__tests__/setup.test.ts +7 -4
  210. package/src/routes/compose.tsx +2 -1
  211. package/src/routes/dash/settings.tsx +45 -2
  212. package/src/routes/feed/__tests__/feed.test.ts +210 -6
  213. package/src/routes/feed/feed.ts +23 -14
  214. package/src/routes/pages/__tests__/archive-params.test.ts +92 -3
  215. package/src/routes/pages/__tests__/collection-routing.test.ts +63 -5
  216. package/src/routes/pages/__tests__/collections.test.ts +9 -9
  217. package/src/routes/pages/__tests__/preview.test.ts +174 -0
  218. package/src/routes/pages/__tests__/search.test.ts +69 -0
  219. package/src/routes/pages/archive.tsx +27 -7
  220. package/src/routes/pages/collection.tsx +32 -19
  221. package/src/routes/pages/collections.tsx +6 -1
  222. package/src/routes/pages/page.tsx +83 -11
  223. package/src/routes/site-skill.ts +18 -0
  224. package/src/services/__tests__/auth.test.ts +7 -5
  225. package/src/services/__tests__/collection.test.ts +159 -44
  226. package/src/services/__tests__/navigation.test.ts +229 -21
  227. package/src/services/__tests__/post-timeline.test.ts +109 -30
  228. package/src/services/__tests__/post.test.ts +567 -5
  229. package/src/services/__tests__/search.test.ts +48 -1
  230. package/src/services/__tests__/settings.test.ts +8 -0
  231. package/src/services/__tests__/site-admin.test.ts +121 -1
  232. package/src/services/auth.ts +2 -2
  233. package/src/services/bootstrap.ts +3 -2
  234. package/src/services/collection.ts +226 -167
  235. package/src/services/export-theme/assets/client-site.css +1 -1
  236. package/src/services/export-theme/assets/client-site.js +46 -25
  237. package/src/services/export-theme/layouts/_default/list.html +18 -4
  238. package/src/services/export-theme/layouts/_default/rss.xml +8 -12
  239. package/src/services/export-theme/layouts/featured/list.html +5 -4
  240. package/src/services/export-theme/layouts/partials/featured-thread.html +56 -0
  241. package/src/services/export-theme/layouts/partials/footer.html +1 -1
  242. package/src/services/export-theme/layouts/partials/media-gallery.html +1 -0
  243. package/src/services/export-theme/styles/main.css +30 -2
  244. package/src/services/export.ts +91 -80
  245. package/src/services/mcp.ts +37 -27
  246. package/src/services/media.ts +1 -1
  247. package/src/services/navigation.ts +185 -46
  248. package/src/services/post.ts +874 -271
  249. package/src/services/search.ts +8 -2
  250. package/src/services/settings.ts +2 -10
  251. package/src/services/site-admin.ts +63 -43
  252. package/src/style-cjk-jp.css +1 -1
  253. package/src/style-cjk-kr.css +1 -1
  254. package/src/style-cjk-tc.css +1 -1
  255. package/src/style-cjk.css +1 -1
  256. package/src/styles/components.css +540 -0
  257. package/src/styles/site-media.css +111 -19
  258. package/src/styles/tokens.css +14 -9
  259. package/src/styles/ui.css +829 -29
  260. package/src/types/bindings.ts +3 -0
  261. package/src/types/config.ts +243 -12
  262. package/src/types/constants.ts +22 -1
  263. package/src/types/entities.ts +9 -8
  264. package/src/types/operations.ts +18 -10
  265. package/src/types/props.ts +8 -2
  266. package/src/types/raw-assets.d.ts +5 -0
  267. package/src/types/views.ts +16 -4
  268. package/src/ui/__tests__/font-themes.test.ts +42 -30
  269. package/src/ui/compose/ComposeDialog.tsx +92 -2
  270. package/src/ui/dash/appearance/NavigationContent.tsx +332 -4
  271. package/src/ui/dash/appearance/__tests__/NavigationContent.test.tsx +23 -0
  272. package/src/ui/dash/settings/ConfigEditorContent.tsx +578 -0
  273. package/src/ui/dash/settings/GeneralContent.tsx +15 -5
  274. package/src/ui/dash/settings/SettingsRootContent.tsx +21 -1
  275. package/src/ui/dash/settings/__tests__/ConfigEditorContent.test.tsx +98 -0
  276. package/src/ui/dash/settings/__tests__/SettingsRootContent.test.tsx +15 -0
  277. package/src/ui/feed/CuratedThreadPreview.tsx +16 -4
  278. package/src/ui/feed/LinkCard.tsx +2 -12
  279. package/src/ui/feed/NoteCard.tsx +10 -20
  280. package/src/ui/feed/QuoteCard.tsx +2 -12
  281. package/src/ui/feed/ThreadPreview.tsx +26 -34
  282. package/src/ui/feed/TimelineFeed.tsx +2 -2
  283. package/src/ui/feed/__tests__/thread-preview.test.ts +197 -56
  284. package/src/ui/feed/__tests__/timeline-cards.test.ts +178 -3
  285. package/src/ui/feed/thread-preview-state.ts +5 -7
  286. package/src/ui/font-themes.ts +74 -26
  287. package/src/ui/layouts/BaseLayout.tsx +22 -8
  288. package/src/ui/layouts/__tests__/BaseLayout.test.tsx +64 -1
  289. package/src/ui/pages/CollectionPage.tsx +101 -22
  290. package/src/ui/pages/CollectionsPage.tsx +3 -1
  291. package/src/ui/pages/PostPage.tsx +39 -12
  292. package/src/ui/pages/SearchPage.tsx +6 -14
  293. package/src/ui/pages/__tests__/ArchivePage.test.tsx +7 -0
  294. package/src/ui/pages/__tests__/PostPage.test.tsx +88 -0
  295. package/src/ui/shared/CollectionDirectory.tsx +13 -9
  296. package/src/ui/shared/CollectionsManager.tsx +17 -7
  297. package/src/ui/shared/DraftPreviewBar.tsx +33 -0
  298. package/src/ui/shared/HomePageBranding.tsx +2 -2
  299. package/src/ui/shared/MediaGallery.tsx +1 -0
  300. package/src/ui/shared/PostFooter.tsx +3 -1
  301. package/src/ui/shared/__tests__/home-page-branding.test.tsx +1 -1
  302. package/src/ui/shared/__tests__/media-gallery.test.ts +1 -0
  303. package/src/ui/shared/__tests__/navigation-labels.test.ts +2 -2
  304. package/src/ui/shared/__tests__/post-footer.test.ts +15 -0
  305. package/src/ui/shared/collection-management-labels.ts +33 -2
  306. package/src/ui/shared/navigation-labels.ts +2 -4
  307. package/src/ui/shared/post-article-attributes.ts +46 -0
  308. package/dist/app-DZDlmh7C.js +0 -6
  309. package/dist/client/_assets/client-Cevfpm8H.css +0 -2
  310. package/dist/client/_assets/client-auth-v3yvhbgZ.js +0 -4736
  311. package/src/client/tiptap/wrapping-input-rules.ts +0 -102
@@ -0,0 +1,181 @@
1
+ import type { JSONContent } from "@tiptap/core";
2
+ import { describe, expect, it } from "vitest";
3
+ import { upgradeLegacyFootnotes } from "../footnotes.js";
4
+ import { markdownToTiptapJson } from "../markdown-to-tiptap.js";
5
+ import { renderTiptapDocument } from "../tiptap-render.js";
6
+
7
+ function linkedText(text: string, href: string): JSONContent {
8
+ return {
9
+ type: "text",
10
+ text,
11
+ marks: [
12
+ {
13
+ type: "link",
14
+ attrs: { href, target: "_blank", rel: "noopener noreferrer" },
15
+ },
16
+ ],
17
+ };
18
+ }
19
+
20
+ function legacyDocument(): JSONContent {
21
+ return {
22
+ type: "doc",
23
+ content: [
24
+ {
25
+ type: "paragraph",
26
+ content: [
27
+ { type: "text", text: "First" },
28
+ linkedText("[1]", "#fn-1"),
29
+ { type: "text", text: " and repeated" },
30
+ linkedText("[1]", "#fn-1"),
31
+ { type: "text", text: ". Second" },
32
+ linkedText("[2]", "#fn-2"),
33
+ ],
34
+ },
35
+ { type: "horizontalRule" },
36
+ {
37
+ type: "orderedList",
38
+ attrs: { start: 1, type: null },
39
+ content: [
40
+ {
41
+ type: "listItem",
42
+ content: [
43
+ {
44
+ type: "paragraph",
45
+ content: [
46
+ { type: "text", text: "Rich definition with " },
47
+ linkedText("source", "https://example.com"),
48
+ linkedText("↩︎", "#fnref-1"),
49
+ ],
50
+ },
51
+ {
52
+ type: "bulletList",
53
+ content: [
54
+ {
55
+ type: "listItem",
56
+ content: [
57
+ {
58
+ type: "paragraph",
59
+ content: [{ type: "text", text: "Nested detail" }],
60
+ },
61
+ ],
62
+ },
63
+ ],
64
+ },
65
+ ],
66
+ },
67
+ {
68
+ type: "listItem",
69
+ content: [
70
+ {
71
+ type: "paragraph",
72
+ content: [
73
+ { type: "text", text: "Second definition" },
74
+ linkedText("↩︎", "#fnref-2"),
75
+ ],
76
+ },
77
+ ],
78
+ },
79
+ ],
80
+ },
81
+ ],
82
+ };
83
+ }
84
+
85
+ describe("upgradeLegacyFootnotes", () => {
86
+ it("upgrades the historical link, rule, list, and backlink shape", () => {
87
+ const result = upgradeLegacyFootnotes(legacyDocument());
88
+
89
+ expect(result.upgraded).toBe(true);
90
+ expect(result.doc.content?.map((node) => node.type)).toEqual([
91
+ "paragraph",
92
+ "footnoteDefinition",
93
+ "footnoteDefinition",
94
+ ]);
95
+ expect(
96
+ result.doc.content?.[0]?.content?.filter(
97
+ (node) => node.type === "footnoteReference",
98
+ ),
99
+ ).toEqual([
100
+ { type: "footnoteReference", attrs: { label: "1" } },
101
+ { type: "footnoteReference", attrs: { label: "1" } },
102
+ { type: "footnoteReference", attrs: { label: "2" } },
103
+ ]);
104
+
105
+ const serialized = JSON.stringify(result.doc);
106
+ expect(serialized).not.toContain("#fn-");
107
+ expect(serialized).not.toContain("#fnref-");
108
+ expect(serialized).not.toContain("↩");
109
+ expect(serialized).toContain("https://example.com");
110
+ expect(serialized).toContain("Nested detail");
111
+
112
+ const html = renderTiptapDocument(result.doc, {
113
+ namespace: "pst_legacy",
114
+ });
115
+ expect(html).toContain('role="doc-noteref"');
116
+ expect(html).toContain('role="doc-endnotes"');
117
+ expect(html).toContain('role="doc-backlink"');
118
+ expect(html).not.toContain("<hr>");
119
+ });
120
+
121
+ it("is idempotent after the canonical nodes have been created", () => {
122
+ const first = upgradeLegacyFootnotes(legacyDocument());
123
+ const second = upgradeLegacyFootnotes(first.doc);
124
+
125
+ expect(second).toEqual({ doc: first.doc, upgraded: false });
126
+ });
127
+
128
+ it("upgrades the Markdown round-trip shape observed on historical posts", () => {
129
+ const body = markdownToTiptapJson(
130
+ [
131
+ "Codex[\\[1\\]](#fn-1) and Claude[\\[2\\]](#fn-2).",
132
+ "",
133
+ "---",
134
+ "",
135
+ "1. First definition.[↩︎](#fnref-1)",
136
+ "2. Second definition.[↩︎](#fnref-2)",
137
+ ].join("\n"),
138
+ );
139
+ const result = upgradeLegacyFootnotes(JSON.parse(body) as JSONContent);
140
+
141
+ expect(result.upgraded).toBe(true);
142
+ expect(JSON.stringify(result.doc)).toContain('"type":"footnoteReference"');
143
+ expect(JSON.stringify(result.doc)).toContain('"type":"footnoteDefinition"');
144
+ });
145
+
146
+ it.each([
147
+ {
148
+ name: "has no separator",
149
+ mutate(doc: JSONContent) {
150
+ doc.content?.splice(-2, 1);
151
+ },
152
+ },
153
+ {
154
+ name: "has an unmatched backlink",
155
+ mutate(doc: JSONContent) {
156
+ const list = doc.content?.at(-1);
157
+ const backlink = list?.content?.[0]?.content?.[0]?.content?.at(-1);
158
+ if (backlink?.marks?.[0]?.attrs) {
159
+ backlink.marks[0].attrs.href = "#fnref-99";
160
+ }
161
+ },
162
+ },
163
+ {
164
+ name: "has an ordinary numbered list",
165
+ mutate(doc: JSONContent) {
166
+ const list = doc.content?.at(-1);
167
+ const paragraph = list?.content?.[0]?.content?.[0];
168
+ paragraph?.content?.pop();
169
+ },
170
+ },
171
+ ])("leaves a document unchanged when it $name", ({ mutate }) => {
172
+ const doc = legacyDocument();
173
+ mutate(doc);
174
+ const original = globalThis.structuredClone(doc);
175
+
176
+ expect(upgradeLegacyFootnotes(doc)).toEqual({
177
+ doc: original,
178
+ upgraded: false,
179
+ });
180
+ });
181
+ });
@@ -8,6 +8,8 @@ interface TiptapNode {
8
8
  type: string;
9
9
  attrs?: Record<string, unknown>;
10
10
  content?: TiptapNode[];
11
+ marks?: Array<{ type: string; attrs?: Record<string, unknown> }>;
12
+ text?: string;
11
13
  }
12
14
 
13
15
  function findNode(node: TiptapNode, type: string): TiptapNode | null {
@@ -86,3 +88,62 @@ describe("markdown round-trip: htmlBlock", () => {
86
88
  expect(out).toContain(inner);
87
89
  });
88
90
  });
91
+
92
+ describe("markdown manager integration", () => {
93
+ it("round-trips ordered-list numbering and nested inline formatting", () => {
94
+ const markdown = [
95
+ "5. **Five**",
96
+ "6. Six",
97
+ " 1. *Nested one*",
98
+ " 2. Nested two",
99
+ ].join("\n");
100
+
101
+ const parsed = parseMarkdownDocument(markdown) as TiptapNode;
102
+ const outerList = findNode(parsed, "orderedList");
103
+ expect(outerList?.attrs?.start).toBe(5);
104
+ expect(outerList?.content).toHaveLength(2);
105
+ const nestedList = findNode(
106
+ outerList?.content?.[1] ?? parsed,
107
+ "orderedList",
108
+ );
109
+ expect(nestedList?.attrs?.start ?? 1).toBe(1);
110
+ expect(nestedList?.content).toHaveLength(2);
111
+
112
+ const serialized = serializeMarkdownDocument(parsed);
113
+ expect(serialized).toContain("5. **Five**");
114
+ expect(serialized).toContain("6. Six");
115
+ expect(parseMarkdownDocument(serialized)).toEqual(parsed);
116
+ });
117
+
118
+ it("round-trips table, image, link, and footnote integrations", () => {
119
+ const markdown = [
120
+ "[Source](https://example.com)",
121
+ "",
122
+ "| Name | Value |",
123
+ "| --- | --- |",
124
+ "| Jant | 1 |",
125
+ "",
126
+ '![Alt text](https://example.com/image.png "Title")',
127
+ "",
128
+ "Body[^note]",
129
+ "",
130
+ "[^note]: Footnote body",
131
+ ].join("\n");
132
+
133
+ const parsed = parseMarkdownDocument(markdown) as TiptapNode;
134
+ expect(findNode(parsed, "table")).not.toBeNull();
135
+ expect(findNode(parsed, "image")?.attrs).toMatchObject({
136
+ src: "https://example.com/image.png",
137
+ alt: "Alt text",
138
+ title: "Title",
139
+ });
140
+ expect(findNode(parsed, "footnoteReference")?.attrs?.label).toBe("note");
141
+ expect(findNode(parsed, "footnoteDefinition")?.attrs?.label).toBe("note");
142
+ const linkedText = findNode(parsed, "text");
143
+ expect(linkedText?.marks?.[0]?.type).toBe("link");
144
+ expect(linkedText?.marks?.[0]?.attrs?.href).toBe("https://example.com");
145
+
146
+ const serialized = serializeMarkdownDocument(parsed);
147
+ expect(parseMarkdownDocument(serialized)).toEqual(parsed);
148
+ });
149
+ });
@@ -128,6 +128,29 @@ describe("markdownToTiptapJson", () => {
128
128
  expect(doc.content[1].content[0].type).toBe("paragraph");
129
129
  expect(doc.content[1].content[0].content[0].text).toBe("Footnote body");
130
130
  });
131
+
132
+ it("normalizes inline footnotes into paired structural nodes", () => {
133
+ const doc = parse("Body^[Inline **bold** note.]");
134
+
135
+ expect(doc.content[0].content).toEqual([
136
+ { type: "text", text: "Body" },
137
+ { type: "footnoteReference", attrs: { label: "1" } },
138
+ ]);
139
+ expect(doc.content[1]).toMatchObject({
140
+ type: "footnoteDefinition",
141
+ attrs: { label: "1" },
142
+ content: [
143
+ {
144
+ type: "paragraph",
145
+ content: [
146
+ { type: "text", text: "Inline " },
147
+ { type: "text", text: "bold", marks: [{ type: "bold" }] },
148
+ { type: "text", text: " note." },
149
+ ],
150
+ },
151
+ ],
152
+ });
153
+ });
131
154
  });
132
155
 
133
156
  describe("inline elements", () => {
@@ -398,15 +421,20 @@ describe("end-to-end: Markdown → markdownToTiptapJson → renderTiptapJson", (
398
421
  expect(html).toContain("<figcaption>Caption</figcaption>");
399
422
  });
400
423
 
401
- it("renders footnotes as inline sidenotes through the shared document renderer", () => {
424
+ it("renders semantic footnotes through the shared document renderer", () => {
402
425
  const json = markdownToTiptapJson("Body[^1]\n\n[^1]: Footnote body");
403
426
  const html = renderTiptapJson(json);
404
427
 
428
+ expect(html).toContain('role="doc-noteref"');
405
429
  expect(html).toContain(
406
- '<label for="sn-1" class="margin-toggle sidenote-number footref">',
430
+ '<section class="footnote-endnotes" role="doc-endnotes">',
407
431
  );
408
- expect(html).toContain('<span class="sidenote">Footnote body</span>');
409
- expect(html).not.toContain('<section class="footnotes"');
432
+ expect(html).toContain('<ol class="footnote-list">');
433
+ expect(html).toContain('<li id="fn-1" class="footnote">');
434
+ expect(html).toMatch(/<p>Footnote body <span class="footnote-backlinks">/);
435
+ expect(html).toContain('role="doc-backlink"');
436
+ expect(html).not.toMatch(/footnote-document|footnote-main|footnote-body/);
437
+ expect(html).not.toMatch(/data-footnote-|--footnote-|tabindex=/);
410
438
  });
411
439
 
412
440
  it("renders a complex document", () => {
@@ -62,14 +62,16 @@ describe("render", () => {
62
62
  expect(html).toBe("<p>Intro</p><!--more--><p>Rest</p>");
63
63
  });
64
64
 
65
- it("renders footnote references as inline sidenotes", () => {
65
+ it("renders semantic footnote references and definitions", () => {
66
66
  const html = render("Body copy[^1]\n\n[^1]: Footnote body");
67
67
 
68
- expect(html).toContain(
69
- '<label for="sn-1" class="margin-toggle sidenote-number footref">',
70
- );
71
- expect(html).toContain('<span class="sidenote">Footnote body</span>');
72
- expect(html).not.toContain('<section class="footnotes"');
68
+ expect(html).toContain('role="doc-noteref"');
69
+ expect(html).toContain('role="doc-endnotes"');
70
+ expect(html).toContain('class="footnote-list"');
71
+ expect(html).toContain("Footnote body");
72
+ expect(html).toContain('role="doc-backlink"');
73
+ expect(html.match(/<ol class="footnote-list">/g)).toHaveLength(1);
74
+ expect(html).not.toMatch(/footnote-document|data-footnote-|--footnote-/);
73
75
  });
74
76
 
75
77
  it("escapes raw HTML outside the supported markdown schema", () => {
@@ -7,6 +7,7 @@ describe("getNavigationData", () => {
7
7
  const context = {
8
8
  var: {
9
9
  publicPath: "/",
10
+ currentSite: { id: "sit_navigation" },
10
11
  appConfig: {
11
12
  siteName: "Jant",
12
13
  sitePathPrefix: "",
@@ -34,8 +35,9 @@ describe("getNavigationData", () => {
34
35
 
35
36
  expect(result.isAuthenticated).toBe(false);
36
37
  expect(result.collections).toEqual([]);
37
- expect(result.siteFooterHtml).toContain('<label for="sn-');
38
- expect(result.siteFooterHtml).toContain('<span class="sidenote">');
38
+ expect(result.siteFooterHtml).toContain('role="doc-noteref"');
39
+ expect(result.siteFooterHtml).toContain('role="doc-endnotes"');
40
+ expect(result.siteFooterHtml).toContain("fn-2wpij13sz70fe-1");
39
41
  expect(result.siteFooterHtml).toContain("<strong>note</strong>");
40
42
  expect(result.siteFooterHtml).toContain(
41
43
  "&lt;script&gt;alert(1)&lt;/script&gt;",
@@ -96,4 +98,59 @@ describe("getNavigationData", () => {
96
98
  expect(result.links[0]?.url).toBe("/featured");
97
99
  expect(result.links[1]?.url).toBe("/");
98
100
  });
101
+
102
+ it("hides only the built-in RSS item when feeds are disabled", async () => {
103
+ const context = {
104
+ var: {
105
+ publicPath: "/",
106
+ appConfig: {
107
+ siteName: "Jant",
108
+ sitePathPrefix: "",
109
+ siteOrigin: "https://example.com",
110
+ siteDescription: "",
111
+ siteDescriptionExplicit: false,
112
+ siteAvatarUrl: "",
113
+ showHeaderAvatar: false,
114
+ siteFooter: "",
115
+ rssFeedsEnabled: false,
116
+ },
117
+ services: {
118
+ navItems: {
119
+ list: async () => [
120
+ {
121
+ id: "nav_rss",
122
+ type: "system",
123
+ systemKey: "rss",
124
+ label: "Feed",
125
+ url: "/feed",
126
+ placement: "header",
127
+ position: "a0",
128
+ createdAt: 1,
129
+ updatedAt: 1,
130
+ },
131
+ {
132
+ id: "nav_custom",
133
+ type: "link",
134
+ label: "Custom feed link",
135
+ url: "/feed",
136
+ placement: "header",
137
+ position: "a1",
138
+ createdAt: 1,
139
+ updatedAt: 1,
140
+ },
141
+ ],
142
+ },
143
+ collections: {
144
+ listByRecentActivity: async () => [],
145
+ },
146
+ },
147
+ isAuthenticated: false,
148
+ session: null,
149
+ },
150
+ } as unknown as Context;
151
+
152
+ const result = await getNavigationData(context);
153
+
154
+ expect(result.links.map((link) => link.id)).toEqual(["nav_custom"]);
155
+ });
99
156
  });
@@ -0,0 +1,176 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ POST_BODY_HTML_VERSION,
4
+ renderPostBodyHtml,
5
+ resolvePostBodyHtml,
6
+ tryPreparePostBodyHtml,
7
+ tryRenderPostBodyHtml,
8
+ } from "../post-body-html.js";
9
+
10
+ const body = JSON.stringify({
11
+ type: "doc",
12
+ content: [
13
+ {
14
+ type: "paragraph",
15
+ content: [
16
+ { type: "text", text: "Body" },
17
+ { type: "footnoteReference", attrs: { label: "note" } },
18
+ ],
19
+ },
20
+ {
21
+ type: "footnoteDefinition",
22
+ attrs: { label: "note" },
23
+ content: [
24
+ {
25
+ type: "paragraph",
26
+ content: [{ type: "text", text: "Definition" }],
27
+ },
28
+ ],
29
+ },
30
+ ],
31
+ });
32
+
33
+ const legacyBody = JSON.stringify({
34
+ type: "doc",
35
+ content: [
36
+ {
37
+ type: "paragraph",
38
+ content: [
39
+ { type: "text", text: "Body " },
40
+ {
41
+ type: "text",
42
+ text: "[1]",
43
+ marks: [{ type: "link", attrs: { href: "#fn-1" } }],
44
+ },
45
+ ],
46
+ },
47
+ { type: "horizontalRule" },
48
+ {
49
+ type: "orderedList",
50
+ content: [
51
+ {
52
+ type: "listItem",
53
+ content: [
54
+ {
55
+ type: "paragraph",
56
+ content: [
57
+ { type: "text", text: "Definition " },
58
+ {
59
+ type: "text",
60
+ text: "↩︎",
61
+ marks: [{ type: "link", attrs: { href: "#fnref-1" } }],
62
+ },
63
+ ],
64
+ },
65
+ ],
66
+ },
67
+ ],
68
+ },
69
+ ],
70
+ });
71
+
72
+ describe("post body HTML projection", () => {
73
+ it("uses the immutable post ID as the footnote namespace", () => {
74
+ const html = renderPostBodyHtml("pst_example", body);
75
+
76
+ expect(html).toContain('id="fn-19lnbd7xufphl-1"');
77
+ expect(html).toContain('id="fnref-19lnbd7xufphl-1-1"');
78
+ expect(html).not.toContain("pst_example");
79
+ });
80
+
81
+ it("returns current stored bytes without rendering", () => {
82
+ expect(
83
+ resolvePostBodyHtml({
84
+ id: "pst_example",
85
+ body,
86
+ bodyHtml: "<p>already current</p>",
87
+ bodyHtmlVersion: POST_BODY_HTML_VERSION,
88
+ }),
89
+ ).toBe("<p>already current</p>");
90
+ });
91
+
92
+ it("renders stale stored HTML to the current contract", () => {
93
+ const html = resolvePostBodyHtml({
94
+ id: "pst_example",
95
+ body,
96
+ bodyHtml: '<span class="sidenote">legacy</span>',
97
+ bodyHtmlVersion: 1,
98
+ });
99
+
100
+ expect(html).toContain('role="doc-noteref"');
101
+ expect(html).toContain('role="doc-endnotes"');
102
+ expect(html).not.toContain("legacy");
103
+ });
104
+
105
+ it("re-renders the short-lived v2 layout protocol as canonical v3 HTML", () => {
106
+ const html = resolvePostBodyHtml({
107
+ id: "pst_example",
108
+ body,
109
+ bodyHtml:
110
+ '<div class="footnote-document"><div class="footnote-main"><p>v2</p></div></div>',
111
+ bodyHtmlVersion: 2,
112
+ });
113
+
114
+ expect(html).toContain(
115
+ '<section class="footnote-endnotes" role="doc-endnotes"><ol class="footnote-list">',
116
+ );
117
+ expect(html).not.toMatch(/footnote-document|footnote-main|data-footnote-/);
118
+ });
119
+
120
+ it("upgrades legacy generic footnotes before rendering the projection", () => {
121
+ const prepared = tryPreparePostBodyHtml("pst_example", legacyBody);
122
+
123
+ expect(prepared).toMatchObject({
124
+ ok: true,
125
+ upgradedLegacyFootnotes: true,
126
+ });
127
+ if (!prepared.ok) throw new Error(prepared.error);
128
+
129
+ expect(prepared.body).toContain('"type":"footnoteReference"');
130
+ expect(prepared.body).toContain('"type":"footnoteDefinition"');
131
+ expect(prepared.body).not.toContain("#fnref-1");
132
+ expect(prepared.html).toContain('role="doc-noteref"');
133
+ expect(prepared.html).toContain('role="doc-endnotes"');
134
+ });
135
+
136
+ it("treats v3 generic footnotes as stale until canonical migration", () => {
137
+ const html = resolvePostBodyHtml({
138
+ id: "pst_example",
139
+ body: legacyBody,
140
+ bodyHtml: '<p>Body <a href="#fn-1">[1]</a></p>',
141
+ bodyHtmlVersion: 3,
142
+ });
143
+
144
+ expect(html).toContain('role="doc-noteref"');
145
+ expect(html).toContain('role="doc-endnotes"');
146
+ expect(html).not.toContain('href="#fn-1"');
147
+ });
148
+
149
+ it("falls back to stored HTML when historical canonical JSON is invalid", () => {
150
+ expect(
151
+ resolvePostBodyHtml({
152
+ id: "pst_example",
153
+ body: "not json",
154
+ bodyHtml: "<p>legacy fallback</p>",
155
+ bodyHtmlVersion: 1,
156
+ }),
157
+ ).toBe("<p>legacy fallback</p>");
158
+ });
159
+
160
+ it("returns null when the canonical body is null", () => {
161
+ expect(
162
+ resolvePostBodyHtml({
163
+ id: "pst_example",
164
+ body: null,
165
+ bodyHtml: "<p>stale</p>",
166
+ bodyHtmlVersion: 1,
167
+ }),
168
+ ).toBeNull();
169
+ });
170
+
171
+ it("strict rendering reports malformed canonical JSON", () => {
172
+ expect(tryRenderPostBodyHtml("pst_example", "not json")).toMatchObject({
173
+ ok: false,
174
+ });
175
+ });
176
+ });
@@ -97,4 +97,68 @@ describe("post display assembly", () => {
97
97
  expect(display?.threadPostViews).toHaveLength(2);
98
98
  expect(display?.threadPostViews?.[1]?.id).toBe(reply.id);
99
99
  });
100
+
101
+ it("includes draft thread members only for an authenticated preview", async () => {
102
+ const root = await postService.create({
103
+ format: "note",
104
+ bodyMarkdown: "Draft root",
105
+ status: "draft",
106
+ });
107
+ const reply = await postService.create({
108
+ format: "note",
109
+ bodyMarkdown: "Draft reply",
110
+ status: "draft",
111
+ replyToId: root.id,
112
+ });
113
+
114
+ const preview = await assemblePostPageDisplay(createContext(), root.id, {
115
+ isAuthenticated: true,
116
+ allowDraft: true,
117
+ includeDraftThread: true,
118
+ });
119
+ const normal = await assemblePostPageDisplay(createContext(), root.id, {
120
+ isAuthenticated: true,
121
+ });
122
+
123
+ expect(preview?.threadPostViews?.map((post) => post.id)).toEqual([
124
+ root.id,
125
+ reply.id,
126
+ ]);
127
+ expect(normal).toBeNull();
128
+ });
129
+
130
+ it("keeps draft replies out of a published permalink outside preview", async () => {
131
+ const root = await postService.create({
132
+ format: "note",
133
+ bodyMarkdown: "Published root",
134
+ status: "published",
135
+ });
136
+ const draftReply = await postService.create({
137
+ format: "note",
138
+ bodyMarkdown: "Draft reply",
139
+ status: "draft",
140
+ replyToId: root.id,
141
+ });
142
+
143
+ const publicDisplay = await assemblePostPageDisplay(
144
+ createContext(),
145
+ root.id,
146
+ { isAuthenticated: true },
147
+ );
148
+ const previewDisplay = await assemblePostPageDisplay(
149
+ createContext(),
150
+ draftReply.id,
151
+ {
152
+ isAuthenticated: true,
153
+ allowDraft: true,
154
+ includeDraftThread: true,
155
+ },
156
+ );
157
+
158
+ expect(publicDisplay?.threadPostViews).toBeUndefined();
159
+ expect(previewDisplay?.threadPostViews?.map((post) => post.id)).toEqual([
160
+ root.id,
161
+ draftReply.id,
162
+ ]);
163
+ });
100
164
  });