@jant/core 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (625) hide show
  1. package/bin/commands/db/execute-file.js +1 -1
  2. package/bin/commands/db/export.js +1 -1
  3. package/bin/commands/deploy.js +179 -0
  4. package/bin/commands/migrate.js +4 -4
  5. package/bin/commands/posts/rebuild-html.js +1 -1
  6. package/bin/commands/reset-password.js +1 -1
  7. package/bin/commands/search/reindex.js +1 -1
  8. package/bin/commands/setup.js +4 -2
  9. package/bin/commands/site/export.js +3 -0
  10. package/bin/commands/site/import.js +178 -91
  11. package/bin/commands/site/pull-media.js +3 -2
  12. package/bin/commands/site/snapshot/export.js +3 -1
  13. package/bin/commands/site/snapshot/import.js +3 -2
  14. package/bin/commands/start.js +44 -0
  15. package/bin/commands/telegram/register-webhooks.js +1 -1
  16. package/bin/commands/uploads/cleanup.js +48 -9
  17. package/bin/jant.js +39 -4
  18. package/bin/lib/cloudflare-setup.js +499 -0
  19. package/bin/lib/d1-query.js +26 -1
  20. package/bin/lib/import-sources.js +151 -0
  21. package/bin/lib/node-env.js +14 -9
  22. package/bin/lib/r2-query.js +2 -2
  23. package/bin/lib/runtime-target.js +1 -1
  24. package/bin/lib/site-pull-media.js +56 -4
  25. package/bin/lib/site-snapshot.js +39 -2
  26. package/bin/lib/sql-export.js +66 -10
  27. package/dist/{app-DIVtyB4m.js → app-DSwsDBD0.js} +38257 -9662
  28. package/dist/client/.vite/manifest.json +38 -38
  29. package/dist/client/_assets/chunks/{create-editor-B-m7X7S5.js → create-editor-5Y49x7h5.js} +2 -2
  30. package/dist/client/_assets/chunks/{footnote-rail-CmeoVtnU.js → footnote-rail-BJwswtVQ.js} +1 -1
  31. package/dist/client/_assets/chunks/{settings-paths-C-ZZBTau.js → settings-paths-h6RjIe3C.js} +2 -2
  32. package/dist/client/_assets/chunks/{slug-format-BcIsNKz-.js → slug-format-Dsi0e9Xn.js} +1 -1
  33. package/dist/client/_assets/chunks/{slugify-373citbs.js → slugify-DlHLyUHS.js} +1 -1
  34. package/dist/client/_assets/chunks/sortable-list-DYMcJrlS.js +2 -0
  35. package/dist/client/_assets/chunks/unsafe-svg-DxrzM_Gb.js +2 -0
  36. package/dist/client/_assets/client-BaqmpPQ-.css +2 -0
  37. package/dist/client/_assets/client-DPByjWoU.js +296 -0
  38. package/dist/client/_assets/{client-auth-BpkkKTsV.js → client-auth-CPqPTX1B.js} +2 -2
  39. package/dist/client/_assets/client-author-CGVvrNZ8.css +2 -0
  40. package/dist/client/_assets/{client-compose-C-DXzcFR.js → client-compose-CzEwT5qX.js} +4 -4
  41. package/dist/client/_assets/{client-manage-BfT7ht4M.js → client-manage-CF7x21L4.js} +37 -37
  42. package/dist/client/_assets/{client-settings-CGR_nZ78.js → client-settings-DIM44Zqh.js} +2 -2
  43. package/dist/{url-CKlGzvdN.js → constants-DEgyqWDl.js} +340 -1
  44. package/dist/index.d.ts +44 -0
  45. package/dist/index.js +33 -1
  46. package/dist/node.js +57 -13
  47. package/package.json +43 -48
  48. package/src/__tests__/api-docs.test.ts +168 -1
  49. package/src/__tests__/bin/deploy.test.ts +163 -0
  50. package/src/__tests__/bin/import-sources.test.ts +85 -0
  51. package/src/__tests__/bin/uploads-cleanup.test.ts +66 -26
  52. package/src/__tests__/cli-commands.test.ts +40 -0
  53. package/src/__tests__/config-docs.test.ts +119 -16
  54. package/src/__tests__/custom-url-redirects.test.ts +108 -0
  55. package/src/__tests__/export-collection-custom-urls.test.ts +69 -0
  56. package/src/__tests__/export-docs.test.ts +113 -41
  57. package/src/__tests__/export-feed-ids.test.ts +1 -0
  58. package/src/__tests__/export-format-version.test.ts +88 -0
  59. package/src/__tests__/export-hugo-build.test.ts +143 -8
  60. package/src/__tests__/export-import-roundtrip.test.ts +3 -2
  61. package/src/__tests__/export-service.test.ts +44 -15
  62. package/src/__tests__/export-smart-collection.test.ts +1 -1
  63. package/src/__tests__/feed-docs.test.ts +287 -21
  64. package/src/__tests__/feed-reply-addresses.test.ts +100 -0
  65. package/src/__tests__/feeds-disabled.test.ts +98 -0
  66. package/src/__tests__/fixtures/export-format/1.json +76 -0
  67. package/src/__tests__/fixtures/export-format/2.json +80 -0
  68. package/src/__tests__/fixtures/releases/0.10.0/site-export/README.md +130 -0
  69. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/2thjq/_index.md +25 -0
  70. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/2u5e5/_index.md +35 -0
  71. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/0x4nv/index.md +18 -0
  72. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/_index.md +44 -0
  73. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/faqyt/index.md +30 -0
  74. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +20 -0
  75. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5kayp/_index.md +23 -0
  76. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5ynfs/_index.md +31 -0
  77. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5ynfs/hu597/index.md +21 -0
  78. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/_index.md +5 -0
  79. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +31 -0
  80. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +36 -0
  81. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/archive/_index.md +8 -0
  82. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/are-na-is-the-only-bookmark-pile-i-still-revisit/_index.md +30 -0
  83. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/bought-too-many-lemons-again/_index.md +37 -0
  84. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/city-walks/_index.md +12 -0
  85. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/cleanshot-for-screenshots-ocr-and-screen-recording-on-the-mac/_index.md +33 -0
  86. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/cleanshotmac-shang-de-jie-tu-ocr-lu-ping-gong-ju/_index.md +32 -0
  87. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/co344/_index.md +25 -0
  88. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/collections/_index.md +5 -0
  89. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/current-tea-rotation/_index.md +34 -0
  90. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/derek-sivers-still-writes-the-kind-of-internet-i-want-more-of/_index.md +30 -0
  91. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/desk-but-better/_index.md +25 -0
  92. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/e0kcg/_index.md +22 -0
  93. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/egi3c/_index.md +24 -0
  94. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/evf9j/_index.md +152 -0
  95. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/featured/_index.md +8 -0
  96. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-basho/_index.md +25 -0
  97. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-epictetus/_index.md +25 -0
  98. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-marcus-aurelius/_index.md +25 -0
  99. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-seneca/_index.md +26 -0
  100. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-thoreau/_index.md +25 -0
  101. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/2cl6d/index.md +18 -0
  102. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/3zqv7/index.md +30 -0
  103. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/5oxsv/index.md +18 -0
  104. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/_index.md +39 -0
  105. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gwob9/_index.md +25 -0
  106. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/home-cooking/_index.md +12 -0
  107. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/hz729/_index.md +24 -0
  108. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/inaturalist-ai-zi-ran-she-qu/_index.md +44 -0
  109. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/j4v0q/_index.md +35 -0
  110. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k278t/_index.md +25 -0
  111. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k4eee/_index.md +22 -0
  112. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/_index.md +32 -0
  113. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +20 -0
  114. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/a83qu/index.md +18 -0
  115. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/from-seneca-5hibo/index.md +21 -0
  116. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/kan-qi-lai-bi-jiao-ku-de-gong-si-men/_index.md +41 -0
  117. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/l2m7y/_index.md +29 -0
  118. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/lan-ya-yao-kong-qi-chuang-shang-yue-du-de-fan-ye-shen-qi/_index.md +57 -0
  119. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/mynoise-for-rainy-afternoons/_index.md +30 -0
  120. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/n09le/_index.md +23 -0
  121. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/ni-fu-jin-de-wei-ji-bai-ke-tiao-mu/_index.md +42 -0
  122. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/nts-archives-are-good-cleaning-music/_index.md +30 -0
  123. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/_index.md +32 -0
  124. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/c91j0/index.md +18 -0
  125. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/qyucy/index.md +18 -0
  126. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/wsgck/index.md +18 -0
  127. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +46 -0
  128. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/reading-notes/_index.md +12 -0
  129. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/s4r3e/_index.md +25 -0
  130. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +30 -0
  131. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/_index.md +44 -0
  132. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/cxiu6/index.md +18 -0
  133. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/t77ms/index.md +18 -0
  134. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/the-soup-trick-i-always-forget/index.md +20 -0
  135. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/telk3/_index.md +30 -0
  136. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/telk3/from-thoreau-pawt2/index.md +21 -0
  137. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/the-five-minute-reset-is-still-the-best-habit-i-have/_index.md +36 -0
  138. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +32 -0
  139. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +30 -0
  140. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/tiny-projects/_index.md +12 -0
  141. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/tong-wang-xing-fu-zhi-lu/_index.md +68 -0
  142. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/tou-ma-yan-jiang-ju-le-bu-chu-ti-yan/_index.md +62 -0
  143. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/useful-links/_index.md +12 -0
  144. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/weekend-notes/_index.md +12 -0
  145. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/what-i-actually-use-my-notebook-for/_index.md +52 -0
  146. package/src/__tests__/fixtures/releases/0.10.0/site-export/data/jant.toml +124 -0
  147. package/src/__tests__/fixtures/releases/0.10.0/site-export/hugo.toml +45 -0
  148. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/_redirects +25 -0
  149. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/40bc6cd1f12e-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
  150. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
  151. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
  152. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
  153. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
  154. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
  155. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
  156. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
  157. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
  158. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q1hme4e8cmby77dn66yy.webp +0 -0
  159. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q2w7e4e8cmc20036yh66.webp +0 -0
  160. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q7d2e4e8cmdeqjmyafby.webp +0 -0
  161. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q887e4e8cmdjssych7yh.webp +0 -0
  162. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp-poster.webp +0 -0
  163. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp.mp4 +0 -0
  164. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf-poster.webp +0 -0
  165. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf.mp4 +0 -0
  166. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb-poster.webp +0 -0
  167. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb.mp4 +0 -0
  168. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83-poster.webp +0 -0
  169. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83.mp4 +0 -0
  170. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167sm0f6ct88qw5brtsgcw.webp +0 -0
  171. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167tf8f6ct88r169s51j49.webp +0 -0
  172. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167vaaf6ct88rbx5ztenwb.webp +0 -0
  173. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167w51f6ct88rp19pybkw1.webp +0 -0
  174. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167x0nf6ct88rzajb84tw3.webp +0 -0
  175. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167xxbf6ct88s5t2300bjk.webp +0 -0
  176. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167yq5f6ct88s9pjwt5fxg.webp +0 -0
  177. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167zg4f6ct88sge8jp28ja.webp +0 -0
  178. package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/apple-touch-icon.png +0 -0
  179. package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/custom.css +0 -0
  180. package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/favicon.ico +0 -0
  181. package/src/__tests__/fixtures/releases/0.10.0/site-export/wrangler.jsonc +24 -0
  182. package/src/__tests__/fixtures/releases/0.10.0/snapshot/db.sql +322 -0
  183. package/src/__tests__/fixtures/releases/0.10.0/snapshot/meta.json +11 -0
  184. package/src/__tests__/fixtures/releases/0.11.0/site-export/README.md +130 -0
  185. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/297kg/_index.md +14 -0
  186. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/2thjq/_index.md +25 -0
  187. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/2u5e5/_index.md +33 -0
  188. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/41q27/0x4nv/index.md +18 -0
  189. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/41q27/_index.md +42 -0
  190. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/41q27/faqyt/index.md +28 -0
  191. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +20 -0
  192. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/5kayp/_index.md +23 -0
  193. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/5ynfs/_index.md +31 -0
  194. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/5ynfs/hu597/index.md +21 -0
  195. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/_index.md +5 -0
  196. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +31 -0
  197. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +36 -0
  198. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/archive/_index.md +8 -0
  199. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/are-na-is-the-only-bookmark-pile-i-still-revisit/_index.md +30 -0
  200. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/bought-too-many-lemons-again/_index.md +35 -0
  201. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/city-walks/_index.md +14 -0
  202. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/cleanshot-for-screenshots-ocr-and-screen-recording-on-the-mac/_index.md +33 -0
  203. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/cleanshotmac-shang-de-jie-tu-ocr-lu-ping-gong-ju/_index.md +32 -0
  204. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/co344/_index.md +25 -0
  205. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/collections/_index.md +5 -0
  206. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/current-tea-rotation/_index.md +34 -0
  207. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/derek-sivers-still-writes-the-kind-of-internet-i-want-more-of/_index.md +30 -0
  208. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/desk-but-better/_index.md +25 -0
  209. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/e0kcg/_index.md +22 -0
  210. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/egi3c/_index.md +24 -0
  211. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/evf9j/_index.md +129 -0
  212. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/featured/_index.md +8 -0
  213. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/fixture-draft/_index.md +17 -0
  214. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/fixture-quotes/_index.md +13 -0
  215. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/fixture-text-attachment/_index.md +29 -0
  216. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/from-basho/_index.md +25 -0
  217. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/from-epictetus/_index.md +25 -0
  218. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/from-marcus-aurelius/_index.md +25 -0
  219. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/from-seneca/_index.md +26 -0
  220. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/from-thoreau/_index.md +25 -0
  221. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/gkbvv/2cl6d/index.md +18 -0
  222. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/gkbvv/3zqv7/index.md +28 -0
  223. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/gkbvv/5oxsv/index.md +18 -0
  224. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/gkbvv/_index.md +37 -0
  225. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/gwob9/_index.md +25 -0
  226. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/home-cooking/_index.md +12 -0
  227. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/hz729/_index.md +24 -0
  228. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/inaturalist-ai-zi-ran-she-qu/_index.md +42 -0
  229. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/j4v0q/_index.md +33 -0
  230. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/k278t/_index.md +25 -0
  231. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/k4eee/_index.md +22 -0
  232. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/k5vh8/_index.md +32 -0
  233. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +20 -0
  234. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/k5vh8/a83qu/index.md +18 -0
  235. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/k5vh8/from-seneca-5hibo/index.md +21 -0
  236. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/kan-qi-lai-bi-jiao-ku-de-gong-si-men/_index.md +41 -0
  237. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/l2m7y/_index.md +29 -0
  238. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/lan-ya-yao-kong-qi-chuang-shang-yue-du-de-fan-ye-shen-qi/_index.md +52 -0
  239. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/mynoise-for-rainy-afternoons/_index.md +30 -0
  240. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/n09le/_index.md +23 -0
  241. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/ni-fu-jin-de-wei-ji-bai-ke-tiao-mu/_index.md +40 -0
  242. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/nts-archives-are-good-cleaning-music/_index.md +30 -0
  243. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/qgfcu/_index.md +32 -0
  244. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/qgfcu/c91j0/index.md +18 -0
  245. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/qgfcu/qyucy/index.md +18 -0
  246. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/qgfcu/wsgck/index.md +18 -0
  247. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +44 -0
  248. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/reading-notes/_index.md +12 -0
  249. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/s4r3e/_index.md +25 -0
  250. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +30 -0
  251. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/te812/_index.md +42 -0
  252. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/te812/cxiu6/index.md +18 -0
  253. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/te812/t77ms/index.md +18 -0
  254. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/te812/the-soup-trick-i-always-forget/index.md +20 -0
  255. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/telk3/_index.md +30 -0
  256. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/telk3/from-thoreau-pawt2/index.md +21 -0
  257. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/the-five-minute-reset-is-still-the-best-habit-i-have/_index.md +36 -0
  258. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +32 -0
  259. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +30 -0
  260. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/tiny-projects/_index.md +12 -0
  261. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/tong-wang-xing-fu-zhi-lu/_index.md +68 -0
  262. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/tou-ma-yan-jiang-ju-le-bu-chu-ti-yan/_index.md +62 -0
  263. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/useful-links/_index.md +12 -0
  264. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/weekend-notes/_index.md +12 -0
  265. package/src/__tests__/fixtures/releases/0.11.0/site-export/content/what-i-actually-use-my-notebook-for/_index.md +50 -0
  266. package/src/__tests__/fixtures/releases/0.11.0/site-export/data/jant.toml +155 -0
  267. package/src/__tests__/fixtures/releases/0.11.0/site-export/hugo.toml +45 -0
  268. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/_redirects +30 -0
  269. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/3c46a9ea6fe0-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
  270. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
  271. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
  272. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
  273. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
  274. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
  275. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
  276. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
  277. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
  278. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m313q1hme4e8cmby77dn66yy.webp +0 -0
  279. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m313q2w7e4e8cmc20036yh66.webp +0 -0
  280. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m313q7d2e4e8cmdeqjmyafby.webp +0 -0
  281. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m313q887e4e8cmdjssych7yh.webp +0 -0
  282. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp-poster.webp +0 -0
  283. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp.mp4 +0 -0
  284. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf-poster.webp +0 -0
  285. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf.mp4 +0 -0
  286. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb-poster.webp +0 -0
  287. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb.mp4 +0 -0
  288. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83-poster.webp +0 -0
  289. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83.mp4 +0 -0
  290. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167sm0f6ct88qw5brtsgcw.webp +0 -0
  291. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167tf8f6ct88r169s51j49.webp +0 -0
  292. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167vaaf6ct88rbx5ztenwb.webp +0 -0
  293. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167w51f6ct88rp19pybkw1.webp +0 -0
  294. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167x0nf6ct88rzajb84tw3.webp +0 -0
  295. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167xxbf6ct88s5t2300bjk.webp +0 -0
  296. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167yq5f6ct88s9pjwt5fxg.webp +0 -0
  297. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m3167zg4f6ct88sge8jp28ja.webp +0 -0
  298. package/src/__tests__/fixtures/releases/0.11.0/site-export/static/media/med_01m50607a6e8h8gfpa8byqtt7h.md +3 -0
  299. package/src/__tests__/fixtures/releases/0.11.0/site-export/themes/jant/static/apple-touch-icon.png +0 -0
  300. package/src/__tests__/fixtures/releases/0.11.0/site-export/themes/jant/static/custom.css +0 -0
  301. package/src/__tests__/fixtures/releases/0.11.0/site-export/themes/jant/static/favicon.ico +0 -0
  302. package/src/__tests__/fixtures/releases/0.11.0/site-export/wrangler.jsonc +24 -0
  303. package/src/__tests__/fixtures/releases/0.11.0/snapshot/db.sql +339 -0
  304. package/src/__tests__/fixtures/releases/0.11.0/snapshot/meta.json +11 -0
  305. package/src/__tests__/helpers/app.ts +6 -1
  306. package/src/__tests__/helpers/d1-round-trips.ts +213 -0
  307. package/src/__tests__/helpers/export-fixtures.ts +1 -0
  308. package/src/__tests__/import-refused-aliases.test.ts +98 -0
  309. package/src/__tests__/import-site-command.test.ts +73 -8
  310. package/src/__tests__/package-dependencies.test.ts +123 -0
  311. package/src/__tests__/public-page-round-trips.test.ts +203 -0
  312. package/src/__tests__/public-types.test.ts +64 -0
  313. package/src/__tests__/release-fixtures.test.ts +79 -24
  314. package/src/__tests__/release-version.test.ts +84 -0
  315. package/src/__tests__/site-pull-media.test.ts +48 -0
  316. package/src/__tests__/snapshot-tables.test.ts +37 -0
  317. package/src/__tests__/sql-export.test.ts +21 -1
  318. package/src/__tests__/stored-file-headers.test.ts +94 -0
  319. package/src/__tests__/template-deploy-workflow.test.ts +57 -0
  320. package/src/__tests__/theme-docs.test.ts +113 -24
  321. package/src/__tests__/toolchain-versions.test.ts +54 -0
  322. package/src/__tests__/trailing-slash-redirect.test.ts +61 -0
  323. package/src/__tests__/vite-config-graph.test.ts +98 -0
  324. package/src/__tests__/vite-config.test.ts +32 -0
  325. package/src/app.tsx +96 -67
  326. package/src/client/__tests__/compose-bridge-image-upload.test.ts +1 -0
  327. package/src/client/__tests__/compose-bridge.test.ts +87 -0
  328. package/src/client/__tests__/compose-shortcuts.test.ts +4 -4
  329. package/src/client/__tests__/footnote-rail.test.ts +1 -1
  330. package/src/client/__tests__/lazy-entries.test.ts +1 -1
  331. package/src/client/__tests__/media-scroll-hint.test.ts +2 -2
  332. package/src/client/avatar-upload.ts +10 -10
  333. package/src/client/components/__tests__/jant-compose-dialog.test.ts +295 -4
  334. package/src/client/components/__tests__/jant-compose-editor.test.ts +34 -0
  335. package/src/client/components/__tests__/jant-settings-general.test.ts +0 -32
  336. package/src/client/components/compose-types.ts +14 -0
  337. package/src/client/components/jant-compose-dialog.ts +96 -41
  338. package/src/client/components/jant-compose-editor.ts +21 -4
  339. package/src/client/components/jant-config-editor.ts +4 -6
  340. package/src/client/components/jant-media-lightbox.ts +4 -4
  341. package/src/client/components/jant-settings-general.ts +0 -4
  342. package/src/client/components/nav-manager-types.ts +6 -5
  343. package/src/client/compose-bridge.ts +15 -4
  344. package/src/client/compose-launch.ts +4 -6
  345. package/src/client/compose-shortcuts.ts +1 -1
  346. package/src/client/footnote-rail.ts +1 -1
  347. package/src/client/icons.ts +5 -6
  348. package/src/client/lazy-entries.ts +1 -1
  349. package/src/client/media-scroll-hint.ts +2 -2
  350. package/src/client/tiptap/__tests__/markdown-clipboard.test.ts +55 -0
  351. package/src/client/tiptap/markdown-clipboard.ts +50 -2
  352. package/src/client/upload-session.ts +7 -6
  353. package/src/db/__tests__/backfill-external-redirects.test.ts +59 -0
  354. package/src/db/__tests__/backfill-featured-discover.test.ts +56 -0
  355. package/src/db/__tests__/d1-query.test.ts +29 -0
  356. package/src/db/__tests__/migration-rehearsal.test.ts +2 -2
  357. package/src/db/backfills/0007_restore_external_redirect_scheme.sql +20 -0
  358. package/src/db/backfills/0008_turn_off_featured_only_discover.sql +11 -0
  359. package/src/i18n/locales/public/en.po +46 -48
  360. package/src/i18n/locales/public/en.ts +1 -1
  361. package/src/i18n/locales/public/zh-Hans.po +45 -46
  362. package/src/i18n/locales/public/zh-Hans.ts +1 -1
  363. package/src/i18n/locales/public/zh-Hant.po +45 -46
  364. package/src/i18n/locales/public/zh-Hant.ts +1 -1
  365. package/src/i18n/locales/settings/en.po +15 -29
  366. package/src/i18n/locales/settings/en.ts +1 -1
  367. package/src/i18n/locales/settings/zh-Hans.po +15 -29
  368. package/src/i18n/locales/settings/zh-Hans.ts +1 -1
  369. package/src/i18n/locales/settings/zh-Hant.po +15 -29
  370. package/src/i18n/locales/settings/zh-Hant.ts +1 -1
  371. package/src/index.ts +43 -2
  372. package/src/lib/__tests__/api-settings.test.ts +3 -3
  373. package/src/lib/__tests__/constants.test.ts +10 -0
  374. package/src/lib/__tests__/discover.test.ts +8 -9
  375. package/src/lib/__tests__/env-values.test.ts +125 -0
  376. package/src/lib/__tests__/feed-path.test.ts +29 -0
  377. package/src/lib/__tests__/feed.test.ts +50 -22
  378. package/src/lib/__tests__/filter-dimensions.test.ts +22 -8
  379. package/src/lib/__tests__/icons.test.ts +21 -10
  380. package/src/lib/__tests__/post-list-cursor.test.ts +0 -10
  381. package/src/lib/__tests__/rate-limit.test.ts +22 -7
  382. package/src/lib/__tests__/resolve-config.test.ts +5 -3
  383. package/src/lib/__tests__/schemas.test.ts +72 -23
  384. package/src/lib/__tests__/slugify.test.ts +9 -0
  385. package/src/lib/__tests__/startup-config.test.ts +12 -0
  386. package/src/lib/__tests__/storage-s3.test.ts +214 -0
  387. package/src/lib/__tests__/theme.test.ts +20 -1
  388. package/src/lib/__tests__/time.test.ts +56 -0
  389. package/src/lib/__tests__/timeline.test.ts +46 -0
  390. package/src/lib/__tests__/url-fetch.test.ts +65 -1
  391. package/src/lib/__tests__/url.test.ts +60 -1
  392. package/src/lib/api-nav-items.ts +16 -20
  393. package/src/lib/api-post-input.ts +34 -1
  394. package/src/lib/api-posts.ts +128 -24
  395. package/src/lib/api-public-posts.ts +31 -38
  396. package/src/lib/api-search.ts +49 -2
  397. package/src/lib/api-settings.ts +159 -54
  398. package/src/lib/api-threads.ts +34 -11
  399. package/src/lib/constants.ts +26 -0
  400. package/src/lib/discover.ts +7 -23
  401. package/src/lib/env-values.ts +140 -0
  402. package/src/lib/env.ts +203 -12
  403. package/src/lib/feed-path.ts +8 -2
  404. package/src/lib/feed-policy.ts +110 -7
  405. package/src/lib/feed.ts +69 -25
  406. package/src/lib/filter-dimensions.ts +17 -10
  407. package/src/lib/github-sync-site-config.ts +1 -0
  408. package/src/lib/hugo-markdown.ts +5 -6
  409. package/src/lib/icons.ts +96 -34
  410. package/src/lib/navigation.ts +4 -1
  411. package/src/lib/post-display.ts +13 -9
  412. package/src/lib/post-list-cursor.ts +33 -29
  413. package/src/lib/public-storage.ts +43 -0
  414. package/src/lib/rate-limit.ts +31 -16
  415. package/src/lib/render.tsx +5 -0
  416. package/src/lib/resolve-config.ts +16 -19
  417. package/src/lib/schemas.ts +248 -180
  418. package/src/lib/slugify.ts +6 -1
  419. package/src/lib/sse.ts +1 -1
  420. package/src/lib/startup-config.ts +20 -1
  421. package/src/lib/theme.ts +8 -5
  422. package/src/lib/thread-fold.ts +6 -0
  423. package/src/lib/thread-query.ts +19 -24
  424. package/src/lib/time.ts +137 -17
  425. package/src/lib/timeline.ts +76 -31
  426. package/src/lib/url-fetch.ts +141 -40
  427. package/src/lib/url.ts +86 -1
  428. package/src/lib/view.ts +3 -2
  429. package/src/middleware/__tests__/auth.test.ts +27 -0
  430. package/src/middleware/__tests__/cors.test.ts +54 -0
  431. package/src/middleware/__tests__/cross-origin.test.ts +149 -0
  432. package/src/middleware/__tests__/onboarding.test.ts +5 -3
  433. package/src/middleware/__tests__/public-content-access.test.ts +2 -42
  434. package/src/middleware/__tests__/secure-headers.test.ts +40 -42
  435. package/src/middleware/auth.ts +34 -3
  436. package/src/middleware/config.ts +44 -2
  437. package/src/middleware/cors.ts +4 -4
  438. package/src/middleware/cross-origin.ts +124 -0
  439. package/src/middleware/error-handler.ts +7 -0
  440. package/src/middleware/onboarding.ts +12 -3
  441. package/src/middleware/public-content-access.ts +3 -26
  442. package/src/middleware/secure-headers.ts +32 -37
  443. package/src/node/__tests__/cli-deploy-setup.test.ts +373 -0
  444. package/src/node/__tests__/cli-deploy.test.ts +55 -0
  445. package/src/node/__tests__/cli-migrate.test.ts +2 -2
  446. package/src/node/__tests__/cli-runtime-target.test.ts +13 -2
  447. package/src/node/__tests__/cli-site-snapshot.test.ts +57 -0
  448. package/src/node/__tests__/cli-snapshot-meta.test.ts +11 -1
  449. package/src/node/__tests__/cli-sql-export.test.ts +25 -1
  450. package/src/node/__tests__/cli-start.test.ts +66 -0
  451. package/src/node/__tests__/request-handler.test.ts +37 -0
  452. package/src/node/__tests__/runtime.test.ts +56 -1
  453. package/src/node/request-handler.ts +58 -5
  454. package/src/node/runtime.ts +37 -11
  455. package/src/preset.css +3 -3
  456. package/src/routes/__tests__/compose.test.ts +84 -0
  457. package/src/routes/api/__tests__/collections.test.ts +68 -0
  458. package/src/routes/api/__tests__/mcp.test.ts +164 -9
  459. package/src/routes/api/__tests__/media.test.ts +9 -1
  460. package/src/routes/api/__tests__/nav-items.test.ts +27 -1
  461. package/src/routes/api/__tests__/posts.test.ts +269 -78
  462. package/src/routes/api/__tests__/search.test.ts +17 -4
  463. package/src/routes/api/__tests__/settings.test.ts +119 -85
  464. package/src/routes/api/__tests__/telegram.test.ts +11 -6
  465. package/src/routes/api/__tests__/threads.test.ts +11 -0
  466. package/src/routes/api/__tests__/upload-response.test.ts +48 -0
  467. package/src/routes/api/__tests__/uploads.test.ts +35 -2
  468. package/src/routes/api/collections.ts +3 -3
  469. package/src/routes/api/custom-urls.ts +2 -1
  470. package/src/routes/api/export.ts +1 -0
  471. package/src/routes/api/internal/__tests__/post-body-html.test.ts +19 -0
  472. package/src/routes/api/internal/__tests__/uploads.test.ts +2 -0
  473. package/src/routes/api/internal/sites.ts +16 -4
  474. package/src/routes/api/mcp.ts +1 -0
  475. package/src/routes/api/media.ts +7 -8
  476. package/src/routes/api/nav-items.ts +2 -1
  477. package/src/routes/api/posts.ts +18 -24
  478. package/src/routes/api/public/__tests__/posts.test.ts +15 -0
  479. package/src/routes/api/public/__tests__/threads-collections.test.ts +12 -45
  480. package/src/routes/api/public/__tests__/threads.test.ts +41 -9
  481. package/src/routes/api/public/posts.ts +2 -2
  482. package/src/routes/api/public/threads.ts +16 -26
  483. package/src/routes/api/search.ts +7 -41
  484. package/src/routes/api/settings.ts +32 -28
  485. package/src/routes/api/smart-collections.ts +6 -1
  486. package/src/routes/api/threads.ts +25 -26
  487. package/src/routes/api/upload.ts +6 -21
  488. package/src/routes/api/uploads.ts +14 -20
  489. package/src/routes/auth/__tests__/dev.test.ts +16 -13
  490. package/src/routes/auth/__tests__/hosted-sso.test.ts +51 -0
  491. package/src/routes/auth/__tests__/setup-auth.test.ts +2 -0
  492. package/src/routes/auth/__tests__/setup-discover.test.ts +2 -0
  493. package/src/routes/auth/__tests__/setup-flow.test.ts +32 -0
  494. package/src/routes/auth/__tests__/setup-rate-limit.test.ts +72 -0
  495. package/src/routes/auth/__tests__/setup-steps.test.ts +2 -0
  496. package/src/routes/auth/__tests__/signin.test.ts +167 -2
  497. package/src/routes/auth/dev.ts +4 -6
  498. package/src/routes/auth/hosted-sso.ts +9 -6
  499. package/src/routes/auth/setup.tsx +35 -5
  500. package/src/routes/auth/signin.tsx +96 -1
  501. package/src/routes/compose.tsx +47 -47
  502. package/src/routes/dash/__tests__/settings-avatar.test.ts +59 -4
  503. package/src/routes/dash/__tests__/settings-demo-locks.test.ts +147 -0
  504. package/src/routes/dash/custom-urls.tsx +2 -0
  505. package/src/routes/dash/settings.tsx +79 -32
  506. package/src/routes/feed/__tests__/feed.test.ts +93 -3
  507. package/src/routes/feed/__tests__/sitemap.test.ts +42 -0
  508. package/src/routes/feed/feed.ts +130 -175
  509. package/src/routes/feed/sitemap.ts +9 -7
  510. package/src/routes/pages/__tests__/archive-years.test.ts +45 -0
  511. package/src/routes/pages/__tests__/collection-routing.test.ts +40 -0
  512. package/src/routes/pages/__tests__/collections.test.ts +3 -0
  513. package/src/routes/pages/__tests__/language-routing.test.ts +31 -0
  514. package/src/routes/pages/__tests__/post-page-round-trips.test.ts +44 -12
  515. package/src/routes/pages/__tests__/search.test.ts +5 -2
  516. package/src/routes/pages/__tests__/thread-gap.test.ts +207 -0
  517. package/src/routes/pages/archive.tsx +69 -111
  518. package/src/routes/pages/brand.tsx +1 -0
  519. package/src/routes/pages/collection.tsx +86 -120
  520. package/src/routes/pages/collections.tsx +2 -0
  521. package/src/routes/pages/featured.tsx +7 -2
  522. package/src/routes/pages/home.tsx +1 -0
  523. package/src/routes/pages/latest.tsx +6 -2
  524. package/src/routes/pages/new.tsx +1 -0
  525. package/src/routes/pages/page.tsx +113 -66
  526. package/src/routes/pages/search.tsx +8 -4
  527. package/src/routes/pages/smart-collection.tsx +11 -70
  528. package/src/routes/pages/subscribe.tsx +1 -0
  529. package/src/routes/pages/theme-sample.tsx +1 -0
  530. package/src/runtime/__tests__/readiness.test.ts +16 -0
  531. package/src/runtime/cloudflare.ts +2 -3
  532. package/src/runtime/index.ts +3 -1
  533. package/src/runtime/node.ts +3 -5
  534. package/src/runtime/readiness.ts +5 -0
  535. package/src/services/__tests__/auth.test.ts +115 -0
  536. package/src/services/__tests__/collection.test.ts +11 -4
  537. package/src/services/__tests__/github-sync-webhook.test.ts +78 -0
  538. package/src/services/__tests__/hosted-handoff.test.ts +208 -1
  539. package/src/services/__tests__/media.test.ts +47 -27
  540. package/src/services/__tests__/navigation.test.ts +67 -15
  541. package/src/services/__tests__/post.test.ts +103 -56
  542. package/src/services/__tests__/search.test.ts +38 -0
  543. package/src/services/__tests__/settings.test.ts +2 -14
  544. package/src/services/__tests__/smart-collection.test.ts +2 -2
  545. package/src/services/__tests__/telegram-ingest.test.ts +113 -0
  546. package/src/services/__tests__/thread.test.ts +26 -11
  547. package/src/services/auth.ts +36 -4
  548. package/src/services/collection.ts +141 -76
  549. package/src/services/custom-url.ts +11 -4
  550. package/src/services/export-theme/assets/client-site.css +1 -1
  551. package/src/services/export-theme/assets/client-site.js +2 -2
  552. package/src/services/export-theme/layouts/_default/baseof.html +1 -1
  553. package/src/services/export-theme/layouts/collection/single.html +1 -1
  554. package/src/services/export-theme/layouts/partials/featured-thread.html +8 -1
  555. package/src/services/export-theme/layouts/partials/head.html +1 -1
  556. package/src/services/export-theme/layouts/partials/media-gallery.html +6 -3
  557. package/src/services/export-theme/layouts/smart_collection/list.html +1 -1
  558. package/src/services/export-theme/styles/main.css +3 -3
  559. package/src/services/export.ts +70 -20
  560. package/src/services/github-sync.ts +10 -10
  561. package/src/services/hosted-handoff.ts +106 -6
  562. package/src/services/index.ts +3 -1
  563. package/src/services/language.ts +33 -0
  564. package/src/services/mcp.ts +176 -438
  565. package/src/services/media.ts +69 -21
  566. package/src/services/navigation.ts +19 -4
  567. package/src/services/path.ts +45 -3
  568. package/src/services/post.ts +460 -400
  569. package/src/services/search.ts +22 -3
  570. package/src/services/settings.ts +40 -11
  571. package/src/services/site-admin.ts +1 -0
  572. package/src/services/smart-collection.ts +10 -3
  573. package/src/services/telegram.ts +23 -6
  574. package/src/services/thread.ts +11 -3
  575. package/src/services/upload-session.ts +14 -15
  576. package/src/styles/components.css +2 -2
  577. package/src/styles/site-media.css +2 -2
  578. package/src/styles/tokens.css +19 -22
  579. package/src/styles/ui-author.css +73 -94
  580. package/src/styles/ui.css +62 -62
  581. package/src/types/app-context.ts +10 -1
  582. package/src/types/bindings.ts +11 -0
  583. package/src/types/config.ts +4 -4
  584. package/src/types/constants.ts +20 -0
  585. package/src/types/props.ts +34 -8
  586. package/src/types/views.ts +28 -13
  587. package/src/ui/color-themes.ts +6 -5
  588. package/src/ui/dash/settings/GeneralContent.tsx +0 -22
  589. package/src/ui/dash/settings/__tests__/GeneralContent.test.tsx +0 -21
  590. package/src/ui/feed/CuratedThreadPreview.tsx +7 -2
  591. package/src/ui/feed/LinkCard.tsx +1 -2
  592. package/src/ui/feed/NoteCard.tsx +1 -2
  593. package/src/ui/feed/QuoteCard.tsx +2 -2
  594. package/src/ui/feed/ThreadPreview.tsx +6 -6
  595. package/src/ui/feed/TimelineFeed.tsx +1 -7
  596. package/src/ui/feed/__tests__/thread-preview.test.ts +123 -10
  597. package/src/ui/feed/__tests__/timeline-cards.test.ts +18 -1
  598. package/src/ui/layouts/BaseLayout.tsx +5 -0
  599. package/src/ui/pages/ArchivePage.tsx +35 -35
  600. package/src/ui/pages/BrandPage.tsx +1 -1
  601. package/src/ui/pages/CollectionPage.tsx +1 -2
  602. package/src/ui/pages/CollectionsPage.tsx +2 -2
  603. package/src/ui/pages/ComposePage.tsx +1 -1
  604. package/src/ui/pages/FeaturedPage.tsx +1 -1
  605. package/src/ui/pages/HomePage.tsx +1 -1
  606. package/src/ui/pages/PostPage.tsx +1 -1
  607. package/src/ui/pages/SearchPage.tsx +1 -1
  608. package/src/ui/pages/SmartCollectionPage.tsx +4 -5
  609. package/src/ui/pages/SubscribePage.tsx +3 -5
  610. package/src/ui/pages/ThemeSamplePage.tsx +1 -1
  611. package/src/ui/shared/CollectionDirectory.tsx +2 -2
  612. package/src/ui/shared/CollectionsManager.tsx +1 -1
  613. package/src/ui/shared/CopyField.tsx +1 -1
  614. package/src/ui/shared/Icon.tsx +5 -5
  615. package/src/ui/shared/IconSprite.tsx +10 -11
  616. package/src/ui/shared/MediaGallery.tsx +1 -1
  617. package/src/ui/shared/custom-icons.ts +38 -7
  618. package/src/ui/shared/icon-collector.ts +7 -5
  619. package/src/vendor/datastar.js +9 -1956
  620. package/src/vendor/datastar.js.map +4 -4
  621. package/dist/client/_assets/chunks/sortable-list-BJyd-LXE.js +0 -2
  622. package/dist/client/_assets/chunks/unsafe-svg-DU_DNMy5.js +0 -2
  623. package/dist/client/_assets/client-D4AT9Iqr.js +0 -295
  624. package/dist/client/_assets/client-DRuw7XCt.css +0 -2
  625. package/dist/client/_assets/client-author-DQ8R-8KR.css +0 -2
@@ -13,6 +13,7 @@ import {
13
13
  type SQL,
14
14
  type SQLWrapper,
15
15
  isNull,
16
+ ne,
16
17
  desc,
17
18
  inArray,
18
19
  notInArray,
@@ -37,17 +38,19 @@ import {
37
38
  buildRootActivityExpr,
38
39
  rootActivityColumns,
39
40
  } from "../db/thread-activity.js";
40
- import { buildReaderVisibilityConditions } from "../db/post-visibility.js";
41
+ import {
42
+ buildReaderVisibilityConditions,
43
+ type ReaderVisibilityOptions,
44
+ } from "../db/post-visibility.js";
41
45
  import { createEntityId } from "../lib/ids.js";
42
46
  import {
43
47
  decodePostListCursor,
44
48
  encodePostListCursor,
45
- isLegacyPostListCursor,
46
- MISSING_LEGACY_CURSOR_MESSAGE,
49
+ THREAD_POSTS_SORT_MODE,
47
50
  type PostListCursorKeyKind,
48
51
  type PostListCursorValue,
49
52
  } from "../lib/post-list-cursor.js";
50
- import { now } from "../lib/time.js";
53
+ import { calendarPeriodsIn, now, type CalendarPeriod } from "../lib/time.js";
51
54
  import { trimTiptapBody } from "../lib/tiptap-render.js";
52
55
  import {
53
56
  POST_BODY_HTML_VERSION,
@@ -61,7 +64,6 @@ import {
61
64
  THREAD_TRAILING_REPLIES,
62
65
  } from "../lib/thread-fold.js";
63
66
  import { markdownToTiptapJson } from "../lib/markdown-to-tiptap.js";
64
- import { tiptapJsonToMarkdown } from "../lib/tiptap-to-markdown.js";
65
67
  import { generatePostSlug } from "../lib/slug.js";
66
68
  import { getSlugValidationIssue } from "../lib/slug-format.js";
67
69
  import { isReservedPath } from "../lib/constants.js";
@@ -229,10 +231,7 @@ export interface PostFilters {
229
231
 
230
232
  /** Where `PostService.listPage` starts, and how much it returns. */
231
233
  export interface PostListPageOptions {
232
- /**
233
- * `nextCursor` from the previous page; omit for the first. A bare post ID,
234
- * the format earlier releases returned, is still accepted.
235
- */
234
+ /** `nextCursor` from the previous page; omit for the first. */
236
235
  cursor?: string;
237
236
  /** Posts per page. */
238
237
  limit: number;
@@ -311,12 +310,6 @@ interface ListSort {
311
310
  pinned: boolean;
312
311
  }
313
312
 
314
- /**
315
- * The sort mode a cursor into one Thread's Posts records. Distinct from every
316
- * `list()` and collection mode, so a position in one never resumes another.
317
- */
318
- const THREAD_POSTS_SORT_MODE = "thread";
319
-
320
313
  /** One term of a paged ORDER BY: `list()`'s, a collection's, or a Thread's. */
321
314
  interface ListSortKey {
322
315
  /** Selectable as a column, so a page's cursor is read from SQL. */
@@ -336,6 +329,19 @@ export interface FeaturedThreadTimelinePost {
336
329
  position: number;
337
330
  }
338
331
 
332
+ /**
333
+ * Where one gap in a curated Featured Thread points: the first Post of the run
334
+ * it hides, as `lib/thread-fold.ts` has every gap do. Only its address is
335
+ * loaded, since nothing renders it.
336
+ */
337
+ export interface FeaturedThreadGapTarget {
338
+ id: string;
339
+ /** Canonical slug from `path_registry`. */
340
+ slug: string;
341
+ /** The shown Post the hidden run starts right after. */
342
+ afterPostId: string;
343
+ }
344
+
339
345
  /**
340
346
  * Bounded projection for one curated Featured Thread.
341
347
  *
@@ -346,15 +352,8 @@ export interface FeaturedThreadTimelinePost {
346
352
  export interface FeaturedThreadTimelineData {
347
353
  posts: FeaturedThreadTimelinePost[];
348
354
  featuredPostIds: string[];
349
- }
350
-
351
- export interface PostBodyContent {
352
- id: string;
353
- type: "post";
354
- format: Format;
355
- contentFormat: "markdown";
356
- content: string;
357
- chars: number;
355
+ /** The first hidden Post of each run between two shown ones. */
356
+ gapTargets: FeaturedThreadGapTarget[];
358
357
  }
359
358
 
360
359
  /** Minimal projection used by the sitemap renderer. */
@@ -432,7 +431,6 @@ export interface PostService {
432
431
  * ```
433
432
  */
434
433
  getWithCanonicalAlias(postId: string): Promise<PostWithCanonicalAlias | null>;
435
- getBodyContent(id: string): Promise<PostBodyContent | null>;
436
434
  getBySlug(slug: string): Promise<Post | null>;
437
435
  suggestSlug(input: {
438
436
  title?: string;
@@ -459,8 +457,8 @@ export interface PostService {
459
457
  * @param filters - What to list and in which order, as for {@link list}
460
458
  * @param page - The previous page's `nextCursor`, and the page size
461
459
  * @returns The page's Posts and the cursor after them, `null` on the last page
462
- * @throws {ValidationError} When the cursor can't be read, was taken in
463
- * another sort mode, or is a Post ID the caller can't see
460
+ * @throws {ValidationError} When the cursor can't be read or was taken in
461
+ * another sort mode
464
462
  * @example
465
463
  * ```ts
466
464
  * const first = await posts.listPage({ status: "published" }, { limit: 20 });
@@ -539,9 +537,13 @@ export interface PostService {
539
537
  filters: readonly PostFilters[],
540
538
  base: PostFilters,
541
539
  ): Promise<PostFilterAggregate[]>;
542
- /** Count posts grouped by year-month (YYYY-MM) on the `sortBy` time axis */
540
+ /**
541
+ * Count posts grouped by year-month (YYYY-MM) on the `sortBy` time axis, as
542
+ * the site's wall clock in `timeZone` reads it.
543
+ */
543
544
  countByYearMonth(
544
- filters?: PostFilters,
545
+ filters: PostFilters,
546
+ timeZone: string,
545
547
  ): Promise<{ yearMonth: string; count: number }[]>;
546
548
  create(data: CreatePost, summaryConfig?: SummaryConfig): Promise<Post>;
547
549
  createWithAttachments(
@@ -591,10 +593,28 @@ export interface PostService {
591
593
  */
592
594
  delete(id: string, deps?: PostDeleteDeps): Promise<boolean>;
593
595
  /**
594
- * Delete a thread draft and release its slug paths so they can be reused.
595
- * Used when replacing a saved thread draft with a new version.
596
+ * Replace a saved Thread draft with a new version of it.
597
+ *
598
+ * The old Thread is deleted first, which releases its paths for the new
599
+ * one. Its attachments are detached before that, since the new version
600
+ * sends back the ones it keeps by ID; once the new Thread is created, the
601
+ * ones it left out are deleted.
602
+ *
603
+ * @param id - The old Thread's root, or the one post to replace
604
+ * @param items - The new version, as `createThreadWithAttachments` takes it
605
+ * @param deps - Media/storage dependencies
606
+ * @param summaryConfig - Optional summary extraction config
607
+ * @returns Ordered list of created posts; posts[0] is the root
596
608
  */
597
- deleteThreadDraft(id: string, deps?: PostDeleteDeps): Promise<boolean>;
609
+ replaceThreadDraft(
610
+ id: string,
611
+ items: Array<{
612
+ data: CreatePost;
613
+ attachments: PostAttachmentInput[] | undefined;
614
+ }>,
615
+ deps: PostAttachmentDeps,
616
+ summaryConfig?: SummaryConfig,
617
+ ): Promise<Post[]>;
598
618
  /**
599
619
  * Every Post in a Thread, drafts included, in Thread order: the root first,
600
620
  * then replies by creation time, then ID.
@@ -606,17 +626,15 @@ export interface PostService {
606
626
  *
607
627
  * Pages like {@link listPage}. A new reply joins the end of the Thread, so a
608
628
  * walk that is still going when one is published reaches it rather than
609
- * skipping it. As well as a `nextCursor`, the cursor may be the ID of a Post
610
- * in this Thread with the requested status: the page then starts right after
611
- * it, which is how a reader opens the run a fold hides.
629
+ * skipping it. A fold's gap carries a cursor from
630
+ * `encodeThreadPostsCursorAfter`, which opens the run the fold hides.
612
631
  *
613
632
  * @param threadId - The Thread root's ID
614
633
  * @param options - Which Posts to include; `status` defaults to `published`
615
- * @param page - The previous page's `nextCursor` or a Post ID, and the page
616
- * size
634
+ * @param page - The previous page's `nextCursor`, and the page size
617
635
  * @returns The page's Posts and the cursor after them, `null` on the last page
618
- * @throws {ValidationError} When the cursor can't be read, was taken in
619
- * another order, or names a Post this request doesn't list
636
+ * @throws {ValidationError} When the cursor can't be read or was taken in
637
+ * another order
620
638
  * @example
621
639
  * ```ts
622
640
  * const first = await posts.listThreadPostsPage(root.id, {}, { limit: 100 });
@@ -698,13 +716,27 @@ export interface PostService {
698
716
  /**
699
717
  * List the Thread roots that are translations of the given Post, excluding
700
718
  * the Post itself. Empty when it belongs to no translation group.
719
+ *
720
+ * @param postId - The Post whose translations to list
721
+ * @param reader - What the audience may see. Omit it for the author's view,
722
+ * which includes drafts and private translations.
701
723
  */
702
- listTranslations(postId: string): Promise<Post[]>;
724
+ listTranslations(
725
+ postId: string,
726
+ reader?: ReaderVisibilityOptions,
727
+ ): Promise<Post[]>;
703
728
  /**
704
729
  * List translations for many Thread roots in one round trip, keyed by the
705
- * root ID that was asked about. Roots with no group are omitted.
730
+ * root ID that was asked about. Roots with no group, or none the audience
731
+ * may see, are omitted.
732
+ *
733
+ * @param postIds - Thread roots to look up
734
+ * @param reader - What the audience may see. Omit it for the author's view.
706
735
  */
707
- getTranslationsMap(postIds: string[]): Promise<Map<string, Post[]>>;
736
+ getTranslationsMap(
737
+ postIds: string[],
738
+ reader?: ReaderVisibilityOptions,
739
+ ): Promise<Map<string, Post[]>>;
708
740
  /**
709
741
  * Find published Thread roots this Post could be linked to as a translation.
710
742
  *
@@ -826,8 +858,8 @@ export interface PostService {
826
858
  * @param page - The previous page's `nextCursor`, and the page size
827
859
  * @returns The page's Thread roots and the cursor after them, `null` on the
828
860
  * last page
829
- * @throws {ValidationError} When the cursor can't be read, was taken in
830
- * another order, or is a root ID this request doesn't list
861
+ * @throws {ValidationError} When the cursor can't be read or was taken in
862
+ * another order
831
863
  * @example
832
864
  * ```ts
833
865
  * const first = await posts.listCollectionThreadRootPage(
@@ -860,8 +892,11 @@ export interface PostService {
860
892
  rootIds: string[],
861
893
  options?: Pick<PostFilters, "publishedBefore">,
862
894
  ): Promise<Map<string, Post[]>>;
863
- /** Get distinct years with posts, bucketed on the `sortBy` time axis */
864
- getDistinctYears(filters?: PostFilters): Promise<number[]>;
895
+ /**
896
+ * Get distinct years with posts, bucketed on the `sortBy` time axis as the
897
+ * site's wall clock in `timeZone` reads it.
898
+ */
899
+ getDistinctYears(filters: PostFilters, timeZone: string): Promise<number[]>;
865
900
  /**
866
901
  * For each Thread ID, resolve the Post that currently ends the chain: the
867
902
  * last in Thread order, so the root only while it has no replies.
@@ -1176,6 +1211,7 @@ export function createPostService(
1176
1211
  * cursor. The one definition both read, so a page of a Thread and the
1177
1212
  * Thread page itself cannot order its posts differently.
1178
1213
  */
1214
+ /** Thread order; `encodeThreadPostsCursorAfter` writes the same tuple. */
1179
1215
  function threadSortKeys(): ListSortKey[] {
1180
1216
  return [
1181
1217
  {
@@ -1194,16 +1230,58 @@ export function createPostService(
1194
1230
  ];
1195
1231
  }
1196
1232
 
1197
- function buildYearMonthExpr(column: SQLWrapper): SQL<string> {
1198
- return databaseDialect === "pg"
1199
- ? sql<string>`to_char(timezone('UTC', to_timestamp(${column})), 'YYYY-MM')`
1200
- : sql<string>`strftime('%Y-%m', ${column}, 'unixepoch')`;
1233
+ /**
1234
+ * The calendar periods, on the site's wall clock, that the posts matching
1235
+ * `filters` fall in, with the time axis and condition that select them.
1236
+ * `null` when no post matches.
1237
+ *
1238
+ * Neither SQLite nor D1 knows IANA time zones, so the period boundaries are
1239
+ * worked out here from the earliest and latest matching post, and the query
1240
+ * sorts each row into one by comparing against them.
1241
+ */
1242
+ async function calendarPeriodsOf(
1243
+ filters: PostFilters,
1244
+ unit: "year" | "month",
1245
+ timeZone: string,
1246
+ ) {
1247
+ const axis = timeAxisColumn(filters);
1248
+ const where = and(...buildFilterConditions(filters), isNotNull(axis));
1249
+ const [span] = await db
1250
+ .select({
1251
+ from: sql<number | null>`min(${axis})`,
1252
+ to: sql<number | null>`max(${axis})`,
1253
+ })
1254
+ .from(posts)
1255
+ .where(where);
1256
+ if (span?.from == null || span.to == null) return null;
1257
+ const periods = calendarPeriodsIn(
1258
+ Number(span.from),
1259
+ Number(span.to),
1260
+ unit,
1261
+ timeZone,
1262
+ );
1263
+ return { expr: buildPeriodExpr(axis, periods), where };
1201
1264
  }
1202
1265
 
1203
- function buildYearExpr(column: SQLWrapper): SQL<string> {
1204
- return databaseDialect === "pg"
1205
- ? sql<string>`to_char(timezone('UTC', to_timestamp(${column})), 'YYYY')`
1206
- : sql<string>`strftime('%Y', ${column}, 'unixepoch')`;
1266
+ /**
1267
+ * A column's period key: the latest of `periods` (oldest first, the first
1268
+ * beginning at or before every value) that begins at or before it. Every
1269
+ * branch reads the column, even with one period: Postgres refuses to group
1270
+ * or order by a bare constant. Boundaries and keys are generated digits,
1271
+ * written as literals because D1 takes at most 100 bound parameters and a
1272
+ * long archive has more month boundaries than that.
1273
+ */
1274
+ function buildPeriodExpr(
1275
+ column: SQLWrapper,
1276
+ periods: readonly CalendarPeriod[],
1277
+ ): SQL<string> {
1278
+ const branches = [...periods]
1279
+ .reverse()
1280
+ .map(
1281
+ (period) =>
1282
+ sql`WHEN ${column} >= ${sql.raw(String(period.start))} THEN ${sql.raw(`'${period.key}'`)}`,
1283
+ );
1284
+ return sql<string>`CASE ${sql.join(branches, sql` `)} END`;
1207
1285
  }
1208
1286
 
1209
1287
  /** Check if a slug is available (not used by posts or path_registry) */
@@ -1762,47 +1840,17 @@ export function createPostService(
1762
1840
 
1763
1841
  /**
1764
1842
  * The position a cursor names, as the tuple of sort-key values after which
1765
- * the page starts.
1766
- *
1767
- * A bare post ID, the cursor earlier releases returned, is looked up — but
1768
- * only among Posts the caller could have been shown: the request's status,
1769
- * and nothing private when the request excludes it. A deleted Post, a draft,
1770
- * and a private Post all get the same rejection, so the lookup can't be used
1771
- * to learn whether a Post exists or when it was published. Its values come
1772
- * from the same key expressions as the ORDER BY.
1843
+ * the page starts. The cursor must come from a list in the same order.
1773
1844
  */
1774
- async function resolveListCursor(
1845
+ function resolveListCursor(
1775
1846
  cursor: string,
1776
1847
  sort: ListSort,
1777
1848
  keys: readonly ListSortKey[],
1778
- filters: PostFilters,
1779
- ): Promise<PostListCursorValue[]> {
1780
- if (!isLegacyPostListCursor(cursor)) {
1781
- return decodePostListCursor(cursor, {
1782
- mode: listSortMode(sort),
1783
- kinds: keys.map((key) => key.kind),
1784
- });
1785
- }
1786
-
1787
- const rows = await db
1788
- .select(listSortKeyFields(keys))
1789
- .from(posts)
1790
- .where(
1791
- and(
1792
- eq(posts.siteId, siteId),
1793
- eq(posts.id, cursor),
1794
- ...buildReaderVisibilityConditions(posts, siteId, {
1795
- status: filters.status,
1796
- excludePrivate: filters.excludePrivate,
1797
- }),
1798
- ),
1799
- )
1800
- .limit(1);
1801
- const row = rows[0];
1802
- if (!row) {
1803
- throw new ValidationError(MISSING_LEGACY_CURSOR_MESSAGE);
1804
- }
1805
- return readListSortKeyValues(keys, row);
1849
+ ): PostListCursorValue[] {
1850
+ return decodePostListCursor(cursor, {
1851
+ mode: listSortMode(sort),
1852
+ kinds: keys.map((key) => key.kind),
1853
+ });
1806
1854
  }
1807
1855
 
1808
1856
  function toPost(
@@ -1853,95 +1901,57 @@ export function createPostService(
1853
1901
  }
1854
1902
 
1855
1903
  /**
1856
- * Thread visibility the loaded rows already answer, plus the thread ids they
1857
- * do not.
1904
+ * A post row together with what turning it into a {@link Post} takes from
1905
+ * other rows: its slug, from `path_registry`, and its Thread's visibility,
1906
+ * which a reply inherits from the root (a reply's own column is null).
1858
1907
  *
1859
- * A reply's own `visibility` column is null — it inherits the root's — so a
1860
- * row only speaks for its thread when it *is* the root. List surfaces query
1861
- * thread roots exclusively (`excludeReplies`), so for them this covers every
1862
- * thread and the follow-up read never runs.
1908
+ * Both ride along as correlated subqueries, so reading posts is one
1909
+ * statement. On D1 each follow-up lookup was one more round trip on every
1910
+ * page that shows a post.
1863
1911
  *
1864
- * Entries are set only for a non-null visibility, matching
1865
- * {@link getThreadVisibilityMap}: a root row with no visibility is treated as
1866
- * unreadable by both paths.
1912
+ * The outer columns are written out rather than interpolated: Drizzle only
1913
+ * qualifies projection columns when the query has a join, so `${posts.id}`
1914
+ * would render as a bare "id" and bind to the subquery's own table.
1867
1915
  */
1868
- function seedThreadVisibility(rows: (typeof posts.$inferSelect)[]): {
1869
- known: Map<string, Visibility>;
1870
- missingThreadIds: string[];
1871
- } {
1872
- const known = new Map<string, Visibility>();
1873
- const covered = new Set<string>();
1874
- for (const row of rows) {
1875
- if (row.id !== row.threadId) continue;
1876
- covered.add(row.threadId);
1877
- if (row.visibility) {
1878
- known.set(row.threadId, ensurePostVisibility(row.visibility, Error));
1879
- }
1880
- }
1881
- const missingThreadIds = [
1882
- ...new Set(
1883
- rows
1884
- .map((row) => row.threadId)
1885
- .filter((threadId) => !covered.has(threadId)),
1886
- ),
1887
- ];
1888
- return { known, missingThreadIds };
1889
- }
1916
+ const hydratedPostColumns = {
1917
+ ...getTableColumns(posts),
1918
+ slug: sql<string | null>`(
1919
+ SELECT post_slug.path
1920
+ FROM path_registry AS post_slug
1921
+ WHERE post_slug.site_id = ${siteId}
1922
+ AND post_slug.post_id = "post"."id"
1923
+ AND post_slug.kind = 'slug'
1924
+ )`.as("post_slug"),
1925
+ threadVisibility: sql<string | null>`(
1926
+ SELECT thread_root.visibility
1927
+ FROM post AS thread_root
1928
+ WHERE thread_root.site_id = ${siteId}
1929
+ AND thread_root.id = "post"."thread_id"
1930
+ )`.as("thread_visibility"),
1931
+ };
1932
+
1933
+ type HydratedPostRow = typeof posts.$inferSelect & {
1934
+ slug: string | null;
1935
+ threadVisibility: string | null;
1936
+ };
1890
1937
 
1891
1938
  /**
1892
- * Slug lookup and root-visibility lookup are independent, so they go out
1893
- * together rather than one after the other.
1939
+ * Turn a row read with {@link hydratedPostColumns} into a `Post`.
1940
+ *
1941
+ * Null for a row with no slug — a Post with no address — or with no
1942
+ * visibility on its Thread root.
1894
1943
  */
1895
- async function loadHydrationMaps(
1896
- rows: (typeof posts.$inferSelect)[],
1897
- ): Promise<{
1898
- slugMap: Map<string, string>;
1899
- visibilityMap: Map<string, Visibility>;
1900
- }> {
1901
- const { known, missingThreadIds } = seedThreadVisibility(rows);
1902
- const [slugMap, fetched] = await Promise.all([
1903
- resolvedPaths.getPostSlugMap(rows.map((row) => row.id)),
1904
- missingThreadIds.length > 0
1905
- ? getThreadVisibilityMap(missingThreadIds)
1906
- : Promise.resolve(new Map<string, Visibility>()),
1907
- ]);
1908
- for (const [threadId, visibility] of fetched) {
1909
- known.set(threadId, visibility);
1910
- }
1911
- return { slugMap, visibilityMap: known };
1912
- }
1913
-
1914
- async function hydratePost(
1915
- row: typeof posts.$inferSelect | undefined,
1916
- knownSlug?: string,
1917
- ): Promise<Post | null> {
1918
- if (!row) return null;
1919
- const { known, missingThreadIds } = seedThreadVisibility([row]);
1920
- const [slug, fetched] = await Promise.all([
1921
- knownSlug ?? resolvedPaths.getPostSlug(row.id),
1922
- missingThreadIds.length > 0
1923
- ? getThreadVisibilityMap(missingThreadIds)
1924
- : Promise.resolve(new Map<string, Visibility>()),
1925
- ]);
1926
- if (!slug) return null;
1927
- const visibility =
1928
- known.get(row.threadId) ?? fetched.get(row.threadId) ?? row.visibility;
1944
+ function hydratePost(row: HydratedPostRow | undefined): Post | null {
1945
+ if (!row?.slug) return null;
1946
+ const visibility = row.threadVisibility ?? row.visibility;
1929
1947
  if (!visibility) return null;
1930
- return toPost(row, slug, visibility);
1948
+ return toPost(row, row.slug, visibility);
1931
1949
  }
1932
1950
 
1933
- async function hydratePosts(
1934
- rows: (typeof posts.$inferSelect)[],
1935
- ): Promise<Post[]> {
1936
- if (rows.length === 0) return [];
1937
- const { slugMap, visibilityMap } = await loadHydrationMaps(rows);
1951
+ function hydratePosts(rows: HydratedPostRow[]): Post[] {
1938
1952
  return rows
1939
- .map((row) => {
1940
- const slug = slugMap.get(row.id);
1941
- const visibility = visibilityMap.get(row.threadId) ?? row.visibility;
1942
- return slug && visibility ? toPost(row, slug, visibility) : null;
1943
- })
1944
- .filter((row): row is Post => row !== null);
1953
+ .map((row) => hydratePost(row))
1954
+ .filter((post): post is Post => post !== null);
1945
1955
  }
1946
1956
 
1947
1957
  async function hydratePostsById(ids: string[]): Promise<Map<string, Post>> {
@@ -1954,7 +1964,7 @@ export function createPostService(
1954
1964
 
1955
1965
  const rows = await batchQueryRows(uniqueIds, (chunk) =>
1956
1966
  db
1957
- .select()
1967
+ .select(hydratedPostColumns)
1958
1968
  .from(posts)
1959
1969
  .where(
1960
1970
  and(
@@ -1965,36 +1975,13 @@ export function createPostService(
1965
1975
  ),
1966
1976
  );
1967
1977
 
1968
- for (const post of await hydratePosts(rows)) {
1978
+ for (const post of hydratePosts(rows)) {
1969
1979
  result.set(post.id, post);
1970
1980
  }
1971
1981
 
1972
1982
  return result;
1973
1983
  }
1974
1984
 
1975
- async function getThreadVisibilityMap(
1976
- threadIds: string[],
1977
- ): Promise<Map<string, Visibility>> {
1978
- const uniqueThreadIds = [...new Set(threadIds)];
1979
- const result = new Map<string, Visibility>();
1980
- if (uniqueThreadIds.length === 0) return result;
1981
-
1982
- const rows = await batchQueryRows(uniqueThreadIds, (chunk) =>
1983
- db
1984
- .select({ id: posts.id, visibility: posts.visibility })
1985
- .from(posts)
1986
- .where(and(eq(posts.siteId, siteId), inArray(posts.id, chunk))),
1987
- );
1988
-
1989
- for (const row of rows) {
1990
- if (row.visibility) {
1991
- result.set(row.id, ensurePostVisibility(row.visibility, Error));
1992
- }
1993
- }
1994
-
1995
- return result;
1996
- }
1997
-
1998
1985
  function buildThreadRootPageConditions(options?: ThreadRootPageOptions) {
1999
1986
  const conditions: SQL[] = [
2000
1987
  eq(posts.siteId, siteId),
@@ -2188,33 +2175,15 @@ export function createPostService(
2188
2175
  /**
2189
2176
  * The position a collection cursor names, as the tuple of sort-key values
2190
2177
  * after which the page starts.
2191
- *
2192
- * A bare root ID, the cursor earlier releases returned, is looked up in the
2193
- * request's own `sortedThreads`, so only among Threads this request could
2194
- * list. A Thread that is gone, private, a draft, or no longer in the
2195
- * collection gets the same rejection as an ID that never existed.
2196
2178
  */
2197
- async function resolveCollectionThreadCursor(
2179
+ function resolveCollectionThreadCursor(
2198
2180
  cursor: string,
2199
2181
  sort: ReturnType<typeof buildCollectionThreadSort>,
2200
- ): Promise<PostListCursorValue[]> {
2201
- if (!isLegacyPostListCursor(cursor)) {
2202
- return decodePostListCursor(cursor, {
2203
- mode: sort.mode,
2204
- kinds: sort.keys.map((key) => key.kind),
2205
- });
2206
- }
2207
-
2208
- const rows = await db
2209
- .select(listSortKeyFields(sort.keys))
2210
- .from(sort.sortedThreads)
2211
- .where(eq(sort.sortedThreads.threadId, cursor))
2212
- .limit(1);
2213
- const row = rows[0];
2214
- if (!row) {
2215
- throw new ValidationError(MISSING_LEGACY_CURSOR_MESSAGE);
2216
- }
2217
- return readListSortKeyValues(sort.keys, row);
2182
+ ): PostListCursorValue[] {
2183
+ return decodePostListCursor(cursor, {
2184
+ mode: sort.mode,
2185
+ kinds: sort.keys.map((key) => key.kind),
2186
+ });
2218
2187
  }
2219
2188
 
2220
2189
  function isMediaAttachmentInput(
@@ -2223,9 +2192,19 @@ export function createPostService(
2223
2192
  return attachment.type === "media";
2224
2193
  }
2225
2194
 
2195
+ /** IDs of the uploaded media that attachment inputs reference. */
2196
+ function referencedMediaIds(
2197
+ attachments: PostAttachmentInput[] | undefined,
2198
+ ): string[] {
2199
+ return (attachments ?? [])
2200
+ .filter(isMediaAttachmentInput)
2201
+ .map((attachment) => attachment.mediaId);
2202
+ }
2203
+
2226
2204
  async function createAttachmentMediaIds(
2227
2205
  attachments: PostAttachmentInput[],
2228
2206
  deps: PostAttachmentDeps,
2207
+ postId?: string,
2229
2208
  ) {
2230
2209
  if (attachments.length > MAX_MEDIA_ATTACHMENTS) {
2231
2210
  throw new ValidationError(
@@ -2235,11 +2214,7 @@ export function createPostService(
2235
2214
 
2236
2215
  const orderedMediaIds: string[] = [];
2237
2216
  const createdTextMediaIds: string[] = [];
2238
- const referencedMediaIds = attachments
2239
- .filter(isMediaAttachmentInput)
2240
- .map((attachment) => attachment.mediaId);
2241
-
2242
- await deps.media.validateIds(referencedMediaIds);
2217
+ await deps.media.validateIds(referencedMediaIds(attachments), postId);
2243
2218
 
2244
2219
  try {
2245
2220
  for (const attachment of attachments) {
@@ -2356,7 +2331,7 @@ export function createPostService(
2356
2331
  return {
2357
2332
  async getById(id) {
2358
2333
  const result = await db
2359
- .select()
2334
+ .select(hydratedPostColumns)
2360
2335
  .from(posts)
2361
2336
  .where(and(eq(posts.siteId, siteId), eq(posts.id, id)))
2362
2337
  .limit(1);
@@ -2364,55 +2339,35 @@ export function createPostService(
2364
2339
  },
2365
2340
 
2366
2341
  async getWithCanonicalAlias(postId) {
2342
+ // The oldest alias is the post's address, as feeds, the sitemap, and
2343
+ // the export name it: a second custom URL is another way in, not a new
2344
+ // identity. Ties within a second fall to the lower id, not to the
2345
+ // storage engine's order.
2367
2346
  const rows = await db
2368
- .select({ post: posts, path: pathRegistry })
2347
+ .select({
2348
+ ...hydratedPostColumns,
2349
+ canonicalAlias: sql<string | null>`(
2350
+ SELECT post_alias.path
2351
+ FROM path_registry AS post_alias
2352
+ WHERE post_alias.site_id = ${siteId}
2353
+ AND post_alias.post_id = "post"."id"
2354
+ AND post_alias.kind = 'alias'
2355
+ ORDER BY post_alias.created_at, post_alias.id
2356
+ LIMIT 1
2357
+ )`.as("canonical_alias"),
2358
+ })
2369
2359
  .from(posts)
2370
- .leftJoin(
2371
- pathRegistry,
2372
- and(
2373
- eq(pathRegistry.siteId, siteId),
2374
- eq(pathRegistry.postId, posts.id),
2375
- ),
2376
- )
2377
2360
  .where(and(eq(posts.siteId, siteId), eq(posts.id, postId)))
2378
- .orderBy(asc(pathRegistry.createdAt), asc(pathRegistry.id));
2361
+ .limit(1);
2379
2362
 
2380
2363
  const row = rows[0];
2381
- if (!row) return null;
2382
-
2383
- let slug: string | null = null;
2384
- let canonicalAlias: string | null = null;
2385
- for (const { path } of rows) {
2386
- if (!path) continue;
2387
- if (path.kind === "slug") {
2388
- slug = path.path;
2389
- continue;
2390
- }
2391
- // Rows arrive oldest first, so the last `alias` seen is the newest —
2392
- // the one a slug URL redirects to. Ties within a second fall to the
2393
- // higher id rather than to whatever the storage engine returned first.
2394
- if (path.kind === "alias") canonicalAlias = `/${path.path}`;
2395
- }
2396
-
2397
2364
  // A Post with no slug row has no address, which is what `hydratePost`
2398
2365
  // says by returning null for it.
2399
- if (!slug) return null;
2400
-
2401
- const post = await hydratePost(row.post, slug);
2402
- return post ? { post, canonicalAlias } : null;
2403
- },
2404
-
2405
- async getBodyContent(id) {
2406
- const post = await this.getById(id);
2407
- if (!post) return null;
2408
-
2366
+ const post = hydratePost(row);
2367
+ if (!row || !post) return null;
2409
2368
  return {
2410
- id: post.id,
2411
- type: "post",
2412
- format: post.format,
2413
- contentFormat: "markdown",
2414
- content: post.body ? tiptapJsonToMarkdown(post.body) : "",
2415
- chars: post.bodyText?.length ?? 0,
2369
+ post,
2370
+ canonicalAlias: row.canonicalAlias ? `/${row.canonicalAlias}` : null,
2416
2371
  };
2417
2372
  },
2418
2373
 
@@ -2422,13 +2377,11 @@ export function createPostService(
2422
2377
  return null;
2423
2378
  }
2424
2379
  const result = await db
2425
- .select()
2380
+ .select(hydratedPostColumns)
2426
2381
  .from(posts)
2427
2382
  .where(and(eq(posts.siteId, siteId), eq(posts.id, resolved.postId)))
2428
2383
  .limit(1);
2429
- // The registry row that answered is the slug, so hydration does not go
2430
- // back for it.
2431
- return hydratePost(result[0], resolved.path);
2384
+ return hydratePost(result[0]);
2432
2385
  },
2433
2386
 
2434
2387
  async suggestSlug(input) {
@@ -2458,7 +2411,7 @@ export function createPostService(
2458
2411
  const conditions = buildFilterConditions(filters);
2459
2412
 
2460
2413
  let query = db
2461
- .select()
2414
+ .select(hydratedPostColumns)
2462
2415
  .from(posts)
2463
2416
  .where(conditions.length > 0 ? and(...conditions) : undefined)
2464
2417
  .orderBy(...listOrderBy(keys))
@@ -2480,17 +2433,14 @@ export function createPostService(
2480
2433
  // `?cursor=` before it has one keeps working.
2481
2434
  if (cursor) {
2482
2435
  conditions.push(
2483
- buildListKeysetCondition(
2484
- keys,
2485
- await resolveListCursor(cursor, sort, keys, filters),
2486
- ),
2436
+ buildListKeysetCondition(keys, resolveListCursor(cursor, sort, keys)),
2487
2437
  );
2488
2438
  }
2489
2439
 
2490
2440
  // One row past the page says whether another page exists, so the last
2491
2441
  // page carries a null cursor rather than one that leads to an empty page.
2492
2442
  const rows = await db
2493
- .select({ post: posts, sortKey: listSortKeyFields(keys) })
2443
+ .select({ post: hydratedPostColumns, sortKey: listSortKeyFields(keys) })
2494
2444
  .from(posts)
2495
2445
  .where(conditions.length > 0 ? and(...conditions) : undefined)
2496
2446
  .orderBy(...listOrderBy(keys))
@@ -2510,7 +2460,7 @@ export function createPostService(
2510
2460
  : null;
2511
2461
 
2512
2462
  return {
2513
- posts: await hydratePosts(pageRows.map((row) => row.post)),
2463
+ posts: hydratePosts(pageRows.map((row) => row.post)),
2514
2464
  nextCursor,
2515
2465
  };
2516
2466
  },
@@ -2696,20 +2646,19 @@ export function createPostService(
2696
2646
  return rows.length;
2697
2647
  },
2698
2648
 
2699
- async countByYearMonth(filters = {}) {
2700
- const axis = timeAxisColumn(filters);
2701
- const conditions = [...buildFilterConditions(filters), isNotNull(axis)];
2702
- const publishedYearMonthExpr = buildYearMonthExpr(axis);
2649
+ async countByYearMonth(filters, timeZone) {
2650
+ const months = await calendarPeriodsOf(filters, "month", timeZone);
2651
+ if (!months) return [];
2703
2652
 
2704
2653
  return db
2705
2654
  .select({
2706
- yearMonth: publishedYearMonthExpr.as("year_month"),
2655
+ yearMonth: months.expr.as("year_month"),
2707
2656
  count: sql<number>`CAST(count(*) AS INTEGER)`.as("count"),
2708
2657
  })
2709
2658
  .from(posts)
2710
- .where(conditions.length > 0 ? and(...conditions) : undefined)
2711
- .groupBy(publishedYearMonthExpr)
2712
- .orderBy(desc(publishedYearMonthExpr));
2659
+ .where(months.where)
2660
+ .groupBy(months.expr)
2661
+ .orderBy(desc(months.expr));
2713
2662
  },
2714
2663
 
2715
2664
  async create(data, summaryConfig) {
@@ -3325,8 +3274,23 @@ export function createPostService(
3325
3274
  );
3326
3275
  created.push(post);
3327
3276
  } catch (error) {
3328
- // Rollback: delete all already-created posts in reverse order
3277
+ // Roll back the posts created so far, in reverse order. Uploads they
3278
+ // reference by ID are detached first rather than deleted with them:
3279
+ // the composer keeps those in its local draft, and a retry attaches
3280
+ // them again.
3281
+ const uploadIds = new Set(
3282
+ items.flatMap((entry) => referencedMediaIds(entry.attachments)),
3283
+ );
3329
3284
  for (const p of [...created].reverse()) {
3285
+ const attached = await deps.media.getByPostId(p.id).catch(() => []);
3286
+ await deps.media
3287
+ .attachToPost(
3288
+ p.id,
3289
+ attached
3290
+ .filter((item) => !uploadIds.has(item.id))
3291
+ .map((item) => item.id),
3292
+ )
3293
+ .catch(() => undefined);
3330
3294
  await this.delete(p.id, {
3331
3295
  media: deps.media,
3332
3296
  storage: deps.storage,
@@ -3567,9 +3531,10 @@ export function createPostService(
3567
3531
  .returning();
3568
3532
  if (needsThreadActivityRecalc) {
3569
3533
  await recalculateThreadActivity(existing.threadId);
3570
- return this.getById(id);
3571
3534
  }
3572
- return hydratePost(result[0]);
3535
+ // A row from RETURNING has no slug or Thread visibility with it, so
3536
+ // the post is read back whole.
3537
+ return result[0] ? this.getById(id) : null;
3573
3538
  }
3574
3539
 
3575
3540
  // Complex case: cascade + update + Thread collection sync atomically.
@@ -3801,9 +3766,8 @@ export function createPostService(
3801
3766
 
3802
3767
  if (needsThreadActivityRecalc) {
3803
3768
  await recalculateThreadActivity(existing.threadId);
3804
- return this.getById(id);
3805
3769
  }
3806
- return hydratePost(updateResult?.[0]);
3770
+ return updateResult?.[0] ? this.getById(id) : null;
3807
3771
  },
3808
3772
 
3809
3773
  async updateWithAttachments(id, data, attachments, deps, summaryConfig) {
@@ -3857,7 +3821,7 @@ export function createPostService(
3857
3821
  ]),
3858
3822
  );
3859
3823
  const { orderedMediaIds, createdTextMediaIds } =
3860
- await createAttachmentMediaIds(attachments, deps);
3824
+ await createAttachmentMediaIds(attachments, deps, id);
3861
3825
  const post = await this.update(id, data, summaryConfig);
3862
3826
 
3863
3827
  if (!post) {
@@ -3994,13 +3958,46 @@ export function createPostService(
3994
3958
  return true;
3995
3959
  },
3996
3960
 
3997
- async deleteThreadDraft(id, deps) {
3998
- return this.delete(id, deps);
3961
+ async replaceThreadDraft(id, items, deps, summaryConfig) {
3962
+ const existing = await this.getById(id);
3963
+ const oldPosts = !existing
3964
+ ? []
3965
+ : isThreadReply(existing)
3966
+ ? [existing]
3967
+ : await this.getThread(id);
3968
+ const oldMedia = [
3969
+ ...(
3970
+ await deps.media.getByPostIds(oldPosts.map((post) => post.id))
3971
+ ).values(),
3972
+ ].flat();
3973
+ for (const post of oldPosts) {
3974
+ await deps.media.detachFromPost(post.id);
3975
+ }
3976
+ if (existing) {
3977
+ await this.delete(id, { media: deps.media, storage: deps.storage });
3978
+ }
3979
+
3980
+ const created = await this.createThreadWithAttachments(
3981
+ items,
3982
+ deps,
3983
+ summaryConfig,
3984
+ );
3985
+
3986
+ const kept = new Set(
3987
+ items.flatMap((item) => referencedMediaIds(item.attachments)),
3988
+ );
3989
+ await deps.media
3990
+ .deleteByIds(
3991
+ oldMedia.filter((item) => !kept.has(item.id)).map((item) => item.id),
3992
+ deps.storage,
3993
+ )
3994
+ .catch(() => undefined);
3995
+ return created;
3999
3996
  },
4000
3997
 
4001
3998
  async getThread(rootId) {
4002
3999
  const rows = await db
4003
- .select()
4000
+ .select(hydratedPostColumns)
4004
4001
  .from(posts)
4005
4002
  .where(and(eq(posts.siteId, siteId), eq(posts.threadId, rootId)))
4006
4003
  .orderBy(...threadOrder());
@@ -4017,32 +4014,15 @@ export function createPostService(
4017
4014
  ];
4018
4015
 
4019
4016
  if (cursor) {
4020
- let values: PostListCursorValue[];
4021
- if (isLegacyPostListCursor(cursor)) {
4022
- // A Post ID names a position only inside the Thread being listed,
4023
- // and only among the Posts this request would return, so it can't
4024
- // be used to learn anything about a Post elsewhere.
4025
- const rows = await db
4026
- .select(listSortKeyFields(keys))
4027
- .from(posts)
4028
- .where(and(...conditions, eq(posts.id, cursor)))
4029
- .limit(1);
4030
- const row = rows[0];
4031
- if (!row) {
4032
- throw new ValidationError(MISSING_LEGACY_CURSOR_MESSAGE);
4033
- }
4034
- values = readListSortKeyValues(keys, row);
4035
- } else {
4036
- values = decodePostListCursor(cursor, {
4037
- mode: THREAD_POSTS_SORT_MODE,
4038
- kinds: keys.map((key) => key.kind),
4039
- });
4040
- }
4017
+ const values = decodePostListCursor(cursor, {
4018
+ mode: THREAD_POSTS_SORT_MODE,
4019
+ kinds: keys.map((key) => key.kind),
4020
+ });
4041
4021
  conditions.push(buildListKeysetCondition(keys, values));
4042
4022
  }
4043
4023
 
4044
4024
  const rows = await db
4045
- .select({ post: posts, sortKey: listSortKeyFields(keys) })
4025
+ .select({ post: hydratedPostColumns, sortKey: listSortKeyFields(keys) })
4046
4026
  .from(posts)
4047
4027
  .where(and(...conditions))
4048
4028
  .orderBy(...listOrderBy(keys))
@@ -4051,7 +4031,7 @@ export function createPostService(
4051
4031
  const pageRows = rows.slice(0, limit);
4052
4032
  const lastRow = pageRows[pageRows.length - 1];
4053
4033
  return {
4054
- posts: await hydratePosts(pageRows.map((row) => row.post)),
4034
+ posts: hydratePosts(pageRows.map((row) => row.post)),
4055
4035
  nextCursor:
4056
4036
  rows.length > limit && lastRow
4057
4037
  ? encodePostListCursor(
@@ -4317,8 +4297,8 @@ export function createPostService(
4317
4297
  .map((row) => ({ language: row.language, count: Number(row.count) }));
4318
4298
  },
4319
4299
 
4320
- async listTranslations(postId) {
4321
- const map = await this.getTranslationsMap([postId]);
4300
+ async listTranslations(postId, reader) {
4301
+ const map = await this.getTranslationsMap([postId], reader);
4322
4302
  return map.get(postId) ?? [];
4323
4303
  },
4324
4304
 
@@ -4375,7 +4355,7 @@ export function createPostService(
4375
4355
  }
4376
4356
 
4377
4357
  const rows = await db
4378
- .select()
4358
+ .select(hydratedPostColumns)
4379
4359
  .from(posts)
4380
4360
  .where(and(...conditions))
4381
4361
  .orderBy(desc(posts.publishedAt))
@@ -4435,40 +4415,62 @@ export function createPostService(
4435
4415
  return { status: "ok", post: candidate };
4436
4416
  },
4437
4417
 
4438
- async getTranslationsMap(postIds) {
4418
+ async getTranslationsMap(postIds, reader) {
4439
4419
  const result = new Map<string, Post[]>();
4440
4420
  const uniqueIds = [...new Set(postIds)].filter(Boolean);
4441
4421
  if (uniqueIds.length === 0) return result;
4442
4422
 
4443
- const seedRows = await db
4444
- .select({ id: posts.id, translationGroupId: posts.translationGroupId })
4445
- .from(posts)
4446
- .where(
4447
- and(
4448
- eq(posts.siteId, siteId),
4449
- inArray(posts.id, uniqueIds),
4450
- isNotNull(posts.translationGroupId),
4451
- ),
4423
+ // The members query finds the seeds' groups itself, through a
4424
+ // subquery, so it does not wait for the seeds to come back: both reads
4425
+ // go out together. The seeds are still read on their own, because the
4426
+ // reader's view may leave a seed out of the members, and its group is
4427
+ // what names its siblings. A sitemap shard asks about hundreds of
4428
+ // posts, past what one D1 statement may bind, hence the chunks.
4429
+ const seedConditions = (chunk: string[]) =>
4430
+ and(
4431
+ eq(posts.siteId, siteId),
4432
+ inArray(posts.id, chunk),
4433
+ isNotNull(posts.translationGroupId),
4452
4434
  );
4435
+ const [seedRows, memberRows] = await Promise.all([
4436
+ batchQueryRows(uniqueIds, (chunk) =>
4437
+ db
4438
+ .select({
4439
+ id: posts.id,
4440
+ translationGroupId: posts.translationGroupId,
4441
+ })
4442
+ .from(posts)
4443
+ .where(seedConditions(chunk)),
4444
+ ),
4445
+ batchQueryRows(uniqueIds, (chunk) =>
4446
+ db
4447
+ .select(hydratedPostColumns)
4448
+ .from(posts)
4449
+ .where(
4450
+ and(
4451
+ eq(posts.siteId, siteId),
4452
+ inArray(
4453
+ posts.translationGroupId,
4454
+ db
4455
+ .select({ groupId: posts.translationGroupId })
4456
+ .from(posts)
4457
+ .where(seedConditions(chunk)),
4458
+ ),
4459
+ ...(reader
4460
+ ? buildReaderVisibilityConditions(posts, siteId, reader)
4461
+ : []),
4462
+ ),
4463
+ ),
4464
+ ),
4465
+ ]);
4453
4466
  if (seedRows.length === 0) return result;
4454
4467
 
4455
- const groupIds = [
4456
- ...new Set(
4457
- seedRows
4458
- .map((row) => row.translationGroupId)
4459
- .filter((groupId): groupId is string => groupId !== null),
4460
- ),
4468
+ // Seeds of one group in two chunks bring its members back twice.
4469
+ const members = [
4470
+ ...new Map(
4471
+ hydratePosts(memberRows).map((member) => [member.id, member]),
4472
+ ).values(),
4461
4473
  ];
4462
- const memberRows = await db
4463
- .select()
4464
- .from(posts)
4465
- .where(
4466
- and(
4467
- eq(posts.siteId, siteId),
4468
- inArray(posts.translationGroupId, groupIds),
4469
- ),
4470
- );
4471
- const members = await hydratePosts(memberRows);
4472
4474
  const byGroup = new Map<string, Post[]>();
4473
4475
  for (const member of members) {
4474
4476
  const groupId = member.translationGroupId;
@@ -4667,14 +4669,14 @@ export function createPostService(
4667
4669
 
4668
4670
  // A page of Threads can outgrow one statement's parameter budget — the
4669
4671
  // API lists up to 100. Each Thread lands in one chunk, so every window
4670
- // below still partitions over a whole Thread.
4672
+ // below still partitions over a whole Thread. The replies come back
4673
+ // whole, ranked and ready to hydrate, so the preview is one read.
4671
4674
  const contextRows = await batchQueryRows(
4672
4675
  [...new Set(rootIds)],
4673
4676
  (chunk) => {
4674
4677
  const rankedReplies = db
4675
4678
  .select({
4676
- id: posts.id,
4677
- threadId: posts.threadId,
4679
+ ...hydratedPostColumns,
4678
4680
  firstReplyRank: sql<number>`CAST(ROW_NUMBER() OVER (
4679
4681
  PARTITION BY ${posts.threadId}
4680
4682
  ORDER BY ${sql.join(threadOrder(), sql`, `)}
@@ -4699,13 +4701,7 @@ export function createPostService(
4699
4701
  .as("ranked_replies");
4700
4702
 
4701
4703
  return db
4702
- .select({
4703
- threadId: rankedReplies.threadId,
4704
- id: rankedReplies.id,
4705
- firstReplyRank: rankedReplies.firstReplyRank,
4706
- latestReplyRank: rankedReplies.latestReplyRank,
4707
- totalReplyCount: rankedReplies.totalReplyCount,
4708
- })
4704
+ .select()
4709
4705
  .from(rankedReplies)
4710
4706
  .where(
4711
4707
  or(
@@ -4719,9 +4715,16 @@ export function createPostService(
4719
4715
  },
4720
4716
  );
4721
4717
 
4722
- const hydratedPosts = await hydratePostsById(
4723
- contextRows.map((row) => row.id),
4724
- );
4718
+ const hydratedPosts = new Map<string, Post>();
4719
+ for (const {
4720
+ firstReplyRank: _first,
4721
+ latestReplyRank: _latest,
4722
+ totalReplyCount: _total,
4723
+ ...row
4724
+ } of contextRows) {
4725
+ const post = hydratePost(row);
4726
+ if (post) hydratedPosts.set(post.id, post);
4727
+ }
4725
4728
 
4726
4729
  const contextByThreadId = new Map<
4727
4730
  string,
@@ -4865,33 +4868,35 @@ export function createPostService(
4865
4868
  if (rootIds.length === 0) return result;
4866
4869
 
4867
4870
  const uniqueRootIds = [...new Set(rootIds)];
4868
- const threadPosition = sql<number>`CAST(
4869
- row_number() OVER (
4870
- PARTITION BY ${posts.threadId}
4871
- ORDER BY ${sql.join(threadOrder(), sql`, `)}
4872
- ) - 1 AS INTEGER
4873
- )`.as("thread_position");
4874
- const threadPostCount = sql<number>`CAST(
4875
- count(*) OVER (PARTITION BY ${posts.threadId}) AS INTEGER
4876
- )`.as("thread_post_count");
4871
+ const inThreadOrder = () => sql`
4872
+ PARTITION BY ${posts.threadId}
4873
+ ORDER BY ${sql.join(threadOrder(), sql`, `)}
4874
+ `;
4875
+ const threadPosition = () =>
4876
+ sql<number>`CAST(
4877
+ row_number() OVER (${inThreadOrder()}) - 1 AS INTEGER
4878
+ )`.as("thread_position");
4879
+ const threadPostCount = () =>
4880
+ sql<number>`CAST(
4881
+ count(*) OVER (PARTITION BY ${posts.threadId}) AS INTEGER
4882
+ )`.as("thread_post_count");
4883
+ const inRequestedThreads = and(
4884
+ eq(posts.siteId, siteId),
4885
+ inArray(posts.threadId, uniqueRootIds),
4886
+ eq(posts.status, "published"),
4887
+ );
4877
4888
 
4889
+ // The Posts shown: the Root, every Featured Post, and the last Post.
4878
4890
  const rankedPosts = db
4879
4891
  .select({
4880
- ...getTableColumns(posts),
4881
- threadPosition,
4882
- threadPostCount,
4892
+ ...hydratedPostColumns,
4893
+ threadPosition: threadPosition(),
4894
+ threadPostCount: threadPostCount(),
4883
4895
  })
4884
4896
  .from(posts)
4885
- .where(
4886
- and(
4887
- eq(posts.siteId, siteId),
4888
- inArray(posts.threadId, uniqueRootIds),
4889
- eq(posts.status, "published"),
4890
- ),
4891
- )
4897
+ .where(inRequestedThreads)
4892
4898
  .as("ranked_featured_thread_post");
4893
-
4894
- const rows = await db
4899
+ const shownQuery = db
4895
4900
  .select()
4896
4901
  .from(rankedPosts)
4897
4902
  .where(
@@ -4903,14 +4908,61 @@ export function createPostService(
4903
4908
  )
4904
4909
  .orderBy(rankedPosts.threadId, sql`${rankedPosts.threadPosition}`);
4905
4910
 
4906
- const hydratedPosts = await hydratePosts(
4907
- rows.map(
4908
- ({ threadPosition: _position, threadPostCount: _count, ...row }) =>
4909
- row,
4910
- ),
4911
- );
4911
+ // Where each gap points: the Post right after a shown one, when it is
4912
+ // hidden itself. Read beside the shown Posts rather than with them, and
4913
+ // only as far as its address, since nothing renders it.
4914
+ const gapCandidates = db
4915
+ .select({
4916
+ id: posts.id,
4917
+ threadId: posts.threadId,
4918
+ slug: hydratedPostColumns.slug,
4919
+ featuredAt: posts.featuredAt,
4920
+ threadPosition: threadPosition(),
4921
+ threadPostCount: threadPostCount(),
4922
+ previousPostId: sql<
4923
+ string | null
4924
+ >`LAG(${posts.id}) OVER (${inThreadOrder()})`.as("previous_post_id"),
4925
+ previousFeaturedAt: sql<
4926
+ number | null
4927
+ >`LAG(${posts.featuredAt}) OVER (${inThreadOrder()})`.as(
4928
+ "previous_featured_at",
4929
+ ),
4930
+ })
4931
+ .from(posts)
4932
+ .where(inRequestedThreads)
4933
+ .as("featured_thread_gap_candidate");
4934
+ const gapQuery = db
4935
+ .select({
4936
+ id: gapCandidates.id,
4937
+ threadId: gapCandidates.threadId,
4938
+ slug: gapCandidates.slug,
4939
+ previousPostId: gapCandidates.previousPostId,
4940
+ })
4941
+ .from(gapCandidates)
4942
+ .where(
4943
+ and(
4944
+ // Hidden: not the Root, not Featured, not the last Post...
4945
+ ne(gapCandidates.id, gapCandidates.threadId),
4946
+ isNull(gapCandidates.featuredAt),
4947
+ sql`${gapCandidates.threadPosition} < ${gapCandidates.threadPostCount} - 1`,
4948
+ // ...right after a shown Post. Nothing follows the last one, so
4949
+ // that is the Root or a Featured Post.
4950
+ or(
4951
+ eq(gapCandidates.previousPostId, gapCandidates.threadId),
4952
+ isNotNull(gapCandidates.previousFeaturedAt),
4953
+ ),
4954
+ ),
4955
+ );
4956
+
4957
+ const [rows, gapRows] = await Promise.all([shownQuery, gapQuery]);
4958
+
4912
4959
  const hydratedById = new Map(
4913
- hydratedPosts.map((post) => [post.id, post]),
4960
+ hydratePosts(
4961
+ rows.map(
4962
+ ({ threadPosition: _position, threadPostCount: _count, ...row }) =>
4963
+ row,
4964
+ ),
4965
+ ).map((post) => [post.id, post]),
4914
4966
  );
4915
4967
 
4916
4968
  for (const row of rows) {
@@ -4920,6 +4972,7 @@ export function createPostService(
4920
4972
  const thread = result.get(row.threadId) ?? {
4921
4973
  posts: [],
4922
4974
  featuredPostIds: [],
4975
+ gapTargets: [],
4923
4976
  };
4924
4977
  thread.posts.push({ post, position: row.threadPosition });
4925
4978
  if (row.featuredAt !== null) {
@@ -4928,6 +4981,16 @@ export function createPostService(
4928
4981
  result.set(row.threadId, thread);
4929
4982
  }
4930
4983
 
4984
+ for (const row of gapRows) {
4985
+ const thread = result.get(row.threadId);
4986
+ if (!row.slug || !thread || !row.previousPostId) continue;
4987
+ thread.gapTargets.push({
4988
+ id: row.id,
4989
+ slug: row.slug,
4990
+ afterPostId: row.previousPostId,
4991
+ });
4992
+ }
4993
+
4931
4994
  return result;
4932
4995
  },
4933
4996
 
@@ -5039,7 +5102,7 @@ export function createPostService(
5039
5102
  const after = cursor
5040
5103
  ? buildListKeysetCondition(
5041
5104
  keys,
5042
- await resolveCollectionThreadCursor(cursor, sort),
5105
+ resolveCollectionThreadCursor(cursor, sort),
5043
5106
  )
5044
5107
  : undefined;
5045
5108
 
@@ -5154,13 +5217,13 @@ export function createPostService(
5154
5217
  );
5155
5218
  }
5156
5219
  return db
5157
- .select()
5220
+ .select(hydratedPostColumns)
5158
5221
  .from(posts)
5159
5222
  .where(and(...conditions))
5160
5223
  .orderBy(posts.threadId, ...threadOrder());
5161
5224
  });
5162
5225
 
5163
- for (const post of await hydratePosts(rows)) {
5226
+ for (const post of hydratePosts(rows)) {
5164
5227
  const thread = result.get(post.threadId);
5165
5228
  if (thread) {
5166
5229
  thread.push(post);
@@ -5200,19 +5263,16 @@ export function createPostService(
5200
5263
  return result;
5201
5264
  },
5202
5265
 
5203
- async getDistinctYears(filters = {}) {
5204
- const axis = timeAxisColumn(filters);
5205
- const conditions = [...buildFilterConditions(filters), isNotNull(axis)];
5206
- const publishedYearExpr = buildYearExpr(axis);
5266
+ async getDistinctYears(filters, timeZone) {
5267
+ const years = await calendarPeriodsOf(filters, "year", timeZone);
5268
+ if (!years) return [];
5207
5269
 
5208
5270
  const rows = await db
5209
- .select({
5210
- year: publishedYearExpr.as("year"),
5211
- })
5271
+ .select({ year: years.expr.as("year") })
5212
5272
  .from(posts)
5213
- .where(conditions.length > 0 ? and(...conditions) : undefined)
5214
- .groupBy(publishedYearExpr)
5215
- .orderBy(desc(publishedYearExpr));
5273
+ .where(years.where)
5274
+ .groupBy(years.expr)
5275
+ .orderBy(desc(years.expr));
5216
5276
 
5217
5277
  return rows.map((r) => parseInt(r.year, 10));
5218
5278
  },