@jant/core 0.10.0 → 0.11.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 (475) 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/migrate.js +4 -4
  4. package/bin/commands/posts/rebuild-html.js +1 -1
  5. package/bin/commands/reset-password.js +1 -1
  6. package/bin/commands/search/reindex.js +1 -1
  7. package/bin/commands/setup.js +4 -2
  8. package/bin/commands/site/export.js +3 -0
  9. package/bin/commands/site/import.js +178 -91
  10. package/bin/commands/site/pull-media.js +3 -2
  11. package/bin/commands/site/snapshot/export.js +3 -1
  12. package/bin/commands/site/snapshot/import.js +3 -2
  13. package/bin/commands/start.js +44 -0
  14. package/bin/commands/telegram/register-webhooks.js +1 -1
  15. package/bin/commands/uploads/cleanup.js +48 -9
  16. package/bin/jant.js +39 -4
  17. package/bin/lib/import-sources.js +151 -0
  18. package/bin/lib/node-env.js +14 -9
  19. package/bin/lib/runtime-target.js +1 -1
  20. package/bin/lib/site-pull-media.js +56 -4
  21. package/bin/lib/site-snapshot.js +39 -2
  22. package/bin/lib/sql-export.js +66 -10
  23. package/dist/{app-DIVtyB4m.js → app-jQI4OPRe.js} +5055 -4448
  24. package/dist/client/.vite/manifest.json +38 -38
  25. package/dist/client/_assets/chunks/{create-editor-B-m7X7S5.js → create-editor-5Y49x7h5.js} +2 -2
  26. package/dist/client/_assets/chunks/{footnote-rail-CmeoVtnU.js → footnote-rail-BJwswtVQ.js} +1 -1
  27. package/dist/client/_assets/chunks/{settings-paths-C-ZZBTau.js → settings-paths-h6RjIe3C.js} +2 -2
  28. package/dist/client/_assets/chunks/{slug-format-BcIsNKz-.js → slug-format-Dsi0e9Xn.js} +1 -1
  29. package/dist/client/_assets/chunks/{slugify-373citbs.js → slugify-DlHLyUHS.js} +1 -1
  30. package/dist/client/_assets/chunks/sortable-list-DYMcJrlS.js +2 -0
  31. package/dist/client/_assets/chunks/unsafe-svg-DxrzM_Gb.js +2 -0
  32. package/dist/client/_assets/client-52vQhZAv.js +296 -0
  33. package/dist/client/_assets/client-BaqmpPQ-.css +2 -0
  34. package/dist/client/_assets/{client-auth-BpkkKTsV.js → client-auth-BDcCR6u1.js} +2 -2
  35. package/dist/client/_assets/client-author-CGVvrNZ8.css +2 -0
  36. package/dist/client/_assets/{client-compose-C-DXzcFR.js → client-compose-CzEwT5qX.js} +4 -4
  37. package/dist/client/_assets/{client-manage-BfT7ht4M.js → client-manage-CF7x21L4.js} +37 -37
  38. package/dist/client/_assets/{client-settings-CGR_nZ78.js → client-settings-DIM44Zqh.js} +2 -2
  39. package/dist/{url-CKlGzvdN.js → constants-DEgyqWDl.js} +340 -1
  40. package/dist/index.d.ts +44 -0
  41. package/dist/index.js +33 -1
  42. package/dist/node.js +57 -13
  43. package/package.json +13 -18
  44. package/src/__tests__/api-docs.test.ts +168 -1
  45. package/src/__tests__/bin/import-sources.test.ts +85 -0
  46. package/src/__tests__/bin/uploads-cleanup.test.ts +66 -26
  47. package/src/__tests__/cli-commands.test.ts +40 -0
  48. package/src/__tests__/config-docs.test.ts +119 -16
  49. package/src/__tests__/custom-url-redirects.test.ts +108 -0
  50. package/src/__tests__/export-collection-custom-urls.test.ts +69 -0
  51. package/src/__tests__/export-docs.test.ts +113 -41
  52. package/src/__tests__/export-feed-ids.test.ts +1 -0
  53. package/src/__tests__/export-format-version.test.ts +88 -0
  54. package/src/__tests__/export-hugo-build.test.ts +139 -4
  55. package/src/__tests__/export-import-roundtrip.test.ts +2 -1
  56. package/src/__tests__/export-service.test.ts +42 -13
  57. package/src/__tests__/export-smart-collection.test.ts +1 -1
  58. package/src/__tests__/feed-docs.test.ts +287 -21
  59. package/src/__tests__/feed-reply-addresses.test.ts +100 -0
  60. package/src/__tests__/feeds-disabled.test.ts +98 -0
  61. package/src/__tests__/fixtures/export-format/1.json +76 -0
  62. package/src/__tests__/fixtures/export-format/2.json +80 -0
  63. package/src/__tests__/fixtures/releases/0.10.0/site-export/README.md +130 -0
  64. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/2thjq/_index.md +25 -0
  65. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/2u5e5/_index.md +35 -0
  66. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/0x4nv/index.md +18 -0
  67. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/_index.md +44 -0
  68. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/faqyt/index.md +30 -0
  69. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +20 -0
  70. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5kayp/_index.md +23 -0
  71. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5ynfs/_index.md +31 -0
  72. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5ynfs/hu597/index.md +21 -0
  73. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/_index.md +5 -0
  74. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +31 -0
  75. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +36 -0
  76. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/archive/_index.md +8 -0
  77. 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
  78. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/bought-too-many-lemons-again/_index.md +37 -0
  79. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/city-walks/_index.md +12 -0
  80. 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
  81. 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
  82. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/co344/_index.md +25 -0
  83. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/collections/_index.md +5 -0
  84. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/current-tea-rotation/_index.md +34 -0
  85. 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
  86. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/desk-but-better/_index.md +25 -0
  87. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/e0kcg/_index.md +22 -0
  88. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/egi3c/_index.md +24 -0
  89. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/evf9j/_index.md +152 -0
  90. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/featured/_index.md +8 -0
  91. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-basho/_index.md +25 -0
  92. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-epictetus/_index.md +25 -0
  93. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-marcus-aurelius/_index.md +25 -0
  94. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-seneca/_index.md +26 -0
  95. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-thoreau/_index.md +25 -0
  96. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/2cl6d/index.md +18 -0
  97. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/3zqv7/index.md +30 -0
  98. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/5oxsv/index.md +18 -0
  99. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/_index.md +39 -0
  100. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gwob9/_index.md +25 -0
  101. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/home-cooking/_index.md +12 -0
  102. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/hz729/_index.md +24 -0
  103. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/inaturalist-ai-zi-ran-she-qu/_index.md +44 -0
  104. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/j4v0q/_index.md +35 -0
  105. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k278t/_index.md +25 -0
  106. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k4eee/_index.md +22 -0
  107. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/_index.md +32 -0
  108. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +20 -0
  109. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/a83qu/index.md +18 -0
  110. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/from-seneca-5hibo/index.md +21 -0
  111. 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
  112. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/l2m7y/_index.md +29 -0
  113. 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
  114. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/mynoise-for-rainy-afternoons/_index.md +30 -0
  115. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/n09le/_index.md +23 -0
  116. 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
  117. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/nts-archives-are-good-cleaning-music/_index.md +30 -0
  118. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/_index.md +32 -0
  119. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/c91j0/index.md +18 -0
  120. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/qyucy/index.md +18 -0
  121. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/wsgck/index.md +18 -0
  122. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +46 -0
  123. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/reading-notes/_index.md +12 -0
  124. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/s4r3e/_index.md +25 -0
  125. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +30 -0
  126. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/_index.md +44 -0
  127. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/cxiu6/index.md +18 -0
  128. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/t77ms/index.md +18 -0
  129. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/the-soup-trick-i-always-forget/index.md +20 -0
  130. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/telk3/_index.md +30 -0
  131. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/telk3/from-thoreau-pawt2/index.md +21 -0
  132. 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
  133. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +32 -0
  134. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +30 -0
  135. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/tiny-projects/_index.md +12 -0
  136. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/tong-wang-xing-fu-zhi-lu/_index.md +68 -0
  137. 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
  138. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/useful-links/_index.md +12 -0
  139. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/weekend-notes/_index.md +12 -0
  140. package/src/__tests__/fixtures/releases/0.10.0/site-export/content/what-i-actually-use-my-notebook-for/_index.md +52 -0
  141. package/src/__tests__/fixtures/releases/0.10.0/site-export/data/jant.toml +124 -0
  142. package/src/__tests__/fixtures/releases/0.10.0/site-export/hugo.toml +45 -0
  143. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/_redirects +25 -0
  144. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/40bc6cd1f12e-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
  145. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
  146. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
  147. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
  148. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
  149. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
  150. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
  151. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
  152. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
  153. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q1hme4e8cmby77dn66yy.webp +0 -0
  154. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q2w7e4e8cmc20036yh66.webp +0 -0
  155. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q7d2e4e8cmdeqjmyafby.webp +0 -0
  156. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q887e4e8cmdjssych7yh.webp +0 -0
  157. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp-poster.webp +0 -0
  158. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp.mp4 +0 -0
  159. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf-poster.webp +0 -0
  160. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf.mp4 +0 -0
  161. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb-poster.webp +0 -0
  162. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb.mp4 +0 -0
  163. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83-poster.webp +0 -0
  164. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83.mp4 +0 -0
  165. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167sm0f6ct88qw5brtsgcw.webp +0 -0
  166. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167tf8f6ct88r169s51j49.webp +0 -0
  167. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167vaaf6ct88rbx5ztenwb.webp +0 -0
  168. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167w51f6ct88rp19pybkw1.webp +0 -0
  169. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167x0nf6ct88rzajb84tw3.webp +0 -0
  170. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167xxbf6ct88s5t2300bjk.webp +0 -0
  171. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167yq5f6ct88s9pjwt5fxg.webp +0 -0
  172. package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167zg4f6ct88sge8jp28ja.webp +0 -0
  173. package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/apple-touch-icon.png +0 -0
  174. package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/custom.css +0 -0
  175. package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/favicon.ico +0 -0
  176. package/src/__tests__/fixtures/releases/0.10.0/site-export/wrangler.jsonc +24 -0
  177. package/src/__tests__/fixtures/releases/0.10.0/snapshot/db.sql +322 -0
  178. package/src/__tests__/fixtures/releases/0.10.0/snapshot/meta.json +11 -0
  179. package/src/__tests__/helpers/app.ts +6 -1
  180. package/src/__tests__/helpers/export-fixtures.ts +1 -0
  181. package/src/__tests__/import-refused-aliases.test.ts +98 -0
  182. package/src/__tests__/import-site-command.test.ts +73 -8
  183. package/src/__tests__/public-types.test.ts +64 -0
  184. package/src/__tests__/release-fixtures.test.ts +79 -24
  185. package/src/__tests__/release-version.test.ts +84 -0
  186. package/src/__tests__/site-pull-media.test.ts +48 -0
  187. package/src/__tests__/snapshot-tables.test.ts +37 -0
  188. package/src/__tests__/sql-export.test.ts +21 -1
  189. package/src/__tests__/stored-file-headers.test.ts +94 -0
  190. package/src/__tests__/template-deploy-workflow.test.ts +101 -0
  191. package/src/__tests__/theme-docs.test.ts +113 -24
  192. package/src/__tests__/toolchain-versions.test.ts +54 -0
  193. package/src/__tests__/trailing-slash-redirect.test.ts +61 -0
  194. package/src/__tests__/vite-config-graph.test.ts +98 -0
  195. package/src/app.tsx +89 -66
  196. package/src/client/__tests__/compose-bridge-image-upload.test.ts +1 -0
  197. package/src/client/__tests__/compose-bridge.test.ts +87 -0
  198. package/src/client/__tests__/compose-shortcuts.test.ts +4 -4
  199. package/src/client/__tests__/footnote-rail.test.ts +1 -1
  200. package/src/client/__tests__/lazy-entries.test.ts +1 -1
  201. package/src/client/__tests__/media-scroll-hint.test.ts +2 -2
  202. package/src/client/avatar-upload.ts +10 -10
  203. package/src/client/components/__tests__/jant-compose-dialog.test.ts +295 -4
  204. package/src/client/components/__tests__/jant-compose-editor.test.ts +34 -0
  205. package/src/client/components/__tests__/jant-settings-general.test.ts +0 -32
  206. package/src/client/components/compose-types.ts +14 -0
  207. package/src/client/components/jant-compose-dialog.ts +96 -41
  208. package/src/client/components/jant-compose-editor.ts +21 -4
  209. package/src/client/components/jant-config-editor.ts +4 -6
  210. package/src/client/components/jant-media-lightbox.ts +4 -4
  211. package/src/client/components/jant-settings-general.ts +0 -4
  212. package/src/client/components/nav-manager-types.ts +6 -5
  213. package/src/client/compose-bridge.ts +15 -4
  214. package/src/client/compose-launch.ts +4 -6
  215. package/src/client/compose-shortcuts.ts +1 -1
  216. package/src/client/footnote-rail.ts +1 -1
  217. package/src/client/lazy-entries.ts +1 -1
  218. package/src/client/media-scroll-hint.ts +2 -2
  219. package/src/client/tiptap/__tests__/markdown-clipboard.test.ts +55 -0
  220. package/src/client/tiptap/markdown-clipboard.ts +50 -2
  221. package/src/client/upload-session.ts +7 -6
  222. package/src/db/__tests__/backfill-external-redirects.test.ts +59 -0
  223. package/src/db/__tests__/backfill-featured-discover.test.ts +56 -0
  224. package/src/db/backfills/0007_restore_external_redirect_scheme.sql +20 -0
  225. package/src/db/backfills/0008_turn_off_featured_only_discover.sql +11 -0
  226. package/src/i18n/locales/public/en.po +46 -48
  227. package/src/i18n/locales/public/en.ts +1 -1
  228. package/src/i18n/locales/public/zh-Hans.po +45 -46
  229. package/src/i18n/locales/public/zh-Hans.ts +1 -1
  230. package/src/i18n/locales/public/zh-Hant.po +45 -46
  231. package/src/i18n/locales/public/zh-Hant.ts +1 -1
  232. package/src/i18n/locales/settings/en.po +15 -29
  233. package/src/i18n/locales/settings/en.ts +1 -1
  234. package/src/i18n/locales/settings/zh-Hans.po +15 -29
  235. package/src/i18n/locales/settings/zh-Hans.ts +1 -1
  236. package/src/i18n/locales/settings/zh-Hant.po +15 -29
  237. package/src/i18n/locales/settings/zh-Hant.ts +1 -1
  238. package/src/index.ts +43 -2
  239. package/src/lib/__tests__/api-settings.test.ts +3 -3
  240. package/src/lib/__tests__/constants.test.ts +10 -0
  241. package/src/lib/__tests__/discover.test.ts +8 -9
  242. package/src/lib/__tests__/env-values.test.ts +125 -0
  243. package/src/lib/__tests__/feed-path.test.ts +29 -0
  244. package/src/lib/__tests__/feed.test.ts +50 -22
  245. package/src/lib/__tests__/filter-dimensions.test.ts +22 -8
  246. package/src/lib/__tests__/post-list-cursor.test.ts +0 -10
  247. package/src/lib/__tests__/rate-limit.test.ts +22 -7
  248. package/src/lib/__tests__/resolve-config.test.ts +5 -3
  249. package/src/lib/__tests__/schemas.test.ts +72 -23
  250. package/src/lib/__tests__/slugify.test.ts +9 -0
  251. package/src/lib/__tests__/startup-config.test.ts +12 -0
  252. package/src/lib/__tests__/storage-s3.test.ts +214 -0
  253. package/src/lib/__tests__/theme.test.ts +20 -1
  254. package/src/lib/__tests__/time.test.ts +56 -0
  255. package/src/lib/__tests__/timeline.test.ts +46 -0
  256. package/src/lib/__tests__/url-fetch.test.ts +65 -1
  257. package/src/lib/__tests__/url.test.ts +60 -1
  258. package/src/lib/api-nav-items.ts +16 -20
  259. package/src/lib/api-post-input.ts +34 -1
  260. package/src/lib/api-posts.ts +125 -23
  261. package/src/lib/api-public-posts.ts +28 -37
  262. package/src/lib/api-search.ts +49 -2
  263. package/src/lib/api-settings.ts +159 -54
  264. package/src/lib/api-threads.ts +34 -11
  265. package/src/lib/constants.ts +6 -0
  266. package/src/lib/discover.ts +7 -23
  267. package/src/lib/env-values.ts +140 -0
  268. package/src/lib/env.ts +203 -12
  269. package/src/lib/feed-path.ts +8 -2
  270. package/src/lib/feed-policy.ts +110 -7
  271. package/src/lib/feed.ts +69 -25
  272. package/src/lib/filter-dimensions.ts +17 -10
  273. package/src/lib/github-sync-site-config.ts +1 -0
  274. package/src/lib/hugo-markdown.ts +5 -6
  275. package/src/lib/navigation.ts +4 -1
  276. package/src/lib/post-list-cursor.ts +33 -29
  277. package/src/lib/public-storage.ts +43 -0
  278. package/src/lib/rate-limit.ts +31 -16
  279. package/src/lib/render.tsx +5 -0
  280. package/src/lib/resolve-config.ts +16 -19
  281. package/src/lib/schemas.ts +248 -180
  282. package/src/lib/slugify.ts +6 -1
  283. package/src/lib/sse.ts +1 -1
  284. package/src/lib/startup-config.ts +20 -1
  285. package/src/lib/theme.ts +8 -5
  286. package/src/lib/thread-fold.ts +6 -0
  287. package/src/lib/thread-query.ts +19 -24
  288. package/src/lib/time.ts +137 -17
  289. package/src/lib/timeline.ts +56 -13
  290. package/src/lib/url-fetch.ts +141 -40
  291. package/src/lib/url.ts +86 -1
  292. package/src/middleware/__tests__/auth.test.ts +27 -0
  293. package/src/middleware/__tests__/cors.test.ts +54 -0
  294. package/src/middleware/__tests__/cross-origin.test.ts +149 -0
  295. package/src/middleware/__tests__/public-content-access.test.ts +2 -42
  296. package/src/middleware/auth.ts +34 -3
  297. package/src/middleware/cors.ts +4 -4
  298. package/src/middleware/cross-origin.ts +124 -0
  299. package/src/middleware/error-handler.ts +7 -0
  300. package/src/middleware/public-content-access.ts +3 -26
  301. package/src/middleware/secure-headers.ts +8 -2
  302. package/src/node/__tests__/cli-migrate.test.ts +2 -2
  303. package/src/node/__tests__/cli-runtime-target.test.ts +13 -2
  304. package/src/node/__tests__/cli-site-snapshot.test.ts +57 -0
  305. package/src/node/__tests__/cli-snapshot-meta.test.ts +11 -1
  306. package/src/node/__tests__/cli-sql-export.test.ts +25 -1
  307. package/src/node/__tests__/cli-start.test.ts +66 -0
  308. package/src/node/__tests__/request-handler.test.ts +37 -0
  309. package/src/node/__tests__/runtime.test.ts +56 -1
  310. package/src/node/request-handler.ts +58 -5
  311. package/src/node/runtime.ts +37 -11
  312. package/src/preset.css +3 -3
  313. package/src/routes/__tests__/compose.test.ts +84 -0
  314. package/src/routes/api/__tests__/collections.test.ts +68 -0
  315. package/src/routes/api/__tests__/mcp.test.ts +164 -9
  316. package/src/routes/api/__tests__/media.test.ts +9 -1
  317. package/src/routes/api/__tests__/nav-items.test.ts +27 -1
  318. package/src/routes/api/__tests__/posts.test.ts +269 -78
  319. package/src/routes/api/__tests__/search.test.ts +17 -4
  320. package/src/routes/api/__tests__/settings.test.ts +119 -85
  321. package/src/routes/api/__tests__/telegram.test.ts +11 -6
  322. package/src/routes/api/__tests__/threads.test.ts +11 -0
  323. package/src/routes/api/__tests__/upload-response.test.ts +48 -0
  324. package/src/routes/api/__tests__/uploads.test.ts +35 -2
  325. package/src/routes/api/collections.ts +3 -3
  326. package/src/routes/api/custom-urls.ts +2 -1
  327. package/src/routes/api/export.ts +1 -0
  328. package/src/routes/api/internal/__tests__/post-body-html.test.ts +19 -0
  329. package/src/routes/api/internal/__tests__/uploads.test.ts +2 -0
  330. package/src/routes/api/internal/sites.ts +16 -4
  331. package/src/routes/api/mcp.ts +1 -0
  332. package/src/routes/api/media.ts +7 -8
  333. package/src/routes/api/nav-items.ts +2 -1
  334. package/src/routes/api/posts.ts +18 -24
  335. package/src/routes/api/public/__tests__/posts.test.ts +15 -0
  336. package/src/routes/api/public/__tests__/threads-collections.test.ts +12 -45
  337. package/src/routes/api/public/__tests__/threads.test.ts +41 -9
  338. package/src/routes/api/public/posts.ts +2 -2
  339. package/src/routes/api/public/threads.ts +16 -26
  340. package/src/routes/api/search.ts +7 -41
  341. package/src/routes/api/settings.ts +32 -28
  342. package/src/routes/api/smart-collections.ts +6 -1
  343. package/src/routes/api/threads.ts +25 -26
  344. package/src/routes/api/upload.ts +6 -21
  345. package/src/routes/api/uploads.ts +14 -20
  346. package/src/routes/auth/__tests__/dev.test.ts +16 -13
  347. package/src/routes/auth/__tests__/hosted-sso.test.ts +51 -0
  348. package/src/routes/auth/__tests__/setup-auth.test.ts +2 -0
  349. package/src/routes/auth/__tests__/setup-discover.test.ts +2 -0
  350. package/src/routes/auth/__tests__/setup-flow.test.ts +32 -0
  351. package/src/routes/auth/__tests__/setup-rate-limit.test.ts +72 -0
  352. package/src/routes/auth/__tests__/setup-steps.test.ts +2 -0
  353. package/src/routes/auth/__tests__/signin.test.ts +167 -2
  354. package/src/routes/auth/dev.ts +4 -6
  355. package/src/routes/auth/hosted-sso.ts +9 -6
  356. package/src/routes/auth/setup.tsx +35 -5
  357. package/src/routes/auth/signin.tsx +96 -1
  358. package/src/routes/compose.tsx +47 -47
  359. package/src/routes/dash/__tests__/settings-avatar.test.ts +59 -4
  360. package/src/routes/dash/__tests__/settings-demo-locks.test.ts +147 -0
  361. package/src/routes/dash/custom-urls.tsx +2 -0
  362. package/src/routes/dash/settings.tsx +79 -32
  363. package/src/routes/feed/__tests__/feed.test.ts +93 -3
  364. package/src/routes/feed/__tests__/sitemap.test.ts +42 -0
  365. package/src/routes/feed/feed.ts +128 -175
  366. package/src/routes/feed/sitemap.ts +9 -7
  367. package/src/routes/pages/__tests__/archive-years.test.ts +45 -0
  368. package/src/routes/pages/__tests__/collection-routing.test.ts +40 -0
  369. package/src/routes/pages/__tests__/collections.test.ts +3 -0
  370. package/src/routes/pages/__tests__/language-routing.test.ts +31 -0
  371. package/src/routes/pages/__tests__/post-page-round-trips.test.ts +34 -2
  372. package/src/routes/pages/__tests__/search.test.ts +5 -2
  373. package/src/routes/pages/__tests__/thread-gap.test.ts +207 -0
  374. package/src/routes/pages/archive.tsx +33 -94
  375. package/src/routes/pages/brand.tsx +1 -0
  376. package/src/routes/pages/collection.tsx +13 -84
  377. package/src/routes/pages/collections.tsx +2 -0
  378. package/src/routes/pages/featured.tsx +7 -2
  379. package/src/routes/pages/home.tsx +1 -0
  380. package/src/routes/pages/latest.tsx +6 -2
  381. package/src/routes/pages/new.tsx +1 -0
  382. package/src/routes/pages/page.tsx +73 -47
  383. package/src/routes/pages/search.tsx +5 -3
  384. package/src/routes/pages/smart-collection.tsx +11 -70
  385. package/src/routes/pages/subscribe.tsx +1 -0
  386. package/src/routes/pages/theme-sample.tsx +1 -0
  387. package/src/runtime/__tests__/readiness.test.ts +16 -0
  388. package/src/runtime/cloudflare.ts +2 -3
  389. package/src/runtime/index.ts +3 -1
  390. package/src/runtime/node.ts +3 -5
  391. package/src/runtime/readiness.ts +5 -0
  392. package/src/services/__tests__/auth.test.ts +115 -0
  393. package/src/services/__tests__/collection.test.ts +9 -0
  394. package/src/services/__tests__/github-sync-webhook.test.ts +78 -0
  395. package/src/services/__tests__/hosted-handoff.test.ts +208 -1
  396. package/src/services/__tests__/media.test.ts +47 -27
  397. package/src/services/__tests__/navigation.test.ts +67 -15
  398. package/src/services/__tests__/post.test.ts +103 -56
  399. package/src/services/__tests__/search.test.ts +38 -0
  400. package/src/services/__tests__/settings.test.ts +2 -14
  401. package/src/services/__tests__/smart-collection.test.ts +2 -2
  402. package/src/services/__tests__/telegram-ingest.test.ts +113 -0
  403. package/src/services/__tests__/thread.test.ts +26 -11
  404. package/src/services/auth.ts +36 -4
  405. package/src/services/collection.ts +46 -5
  406. package/src/services/custom-url.ts +11 -4
  407. package/src/services/export-theme/assets/client-site.css +1 -1
  408. package/src/services/export-theme/assets/client-site.js +2 -2
  409. package/src/services/export-theme/layouts/_default/baseof.html +1 -1
  410. package/src/services/export-theme/layouts/collection/single.html +1 -1
  411. package/src/services/export-theme/layouts/partials/featured-thread.html +8 -1
  412. package/src/services/export-theme/layouts/partials/head.html +1 -1
  413. package/src/services/export-theme/layouts/partials/media-gallery.html +6 -3
  414. package/src/services/export-theme/layouts/smart_collection/list.html +1 -1
  415. package/src/services/export-theme/styles/main.css +3 -3
  416. package/src/services/export.ts +68 -19
  417. package/src/services/github-sync.ts +10 -10
  418. package/src/services/hosted-handoff.ts +106 -6
  419. package/src/services/index.ts +3 -1
  420. package/src/services/language.ts +33 -0
  421. package/src/services/mcp.ts +176 -438
  422. package/src/services/media.ts +69 -21
  423. package/src/services/navigation.ts +19 -4
  424. package/src/services/path.ts +45 -3
  425. package/src/services/post.ts +329 -214
  426. package/src/services/search.ts +22 -3
  427. package/src/services/settings.ts +36 -3
  428. package/src/services/site-admin.ts +1 -0
  429. package/src/services/smart-collection.ts +10 -3
  430. package/src/services/telegram.ts +23 -6
  431. package/src/services/thread.ts +11 -3
  432. package/src/services/upload-session.ts +14 -15
  433. package/src/styles/components.css +2 -2
  434. package/src/styles/site-media.css +2 -2
  435. package/src/styles/tokens.css +19 -22
  436. package/src/styles/ui-author.css +73 -94
  437. package/src/styles/ui.css +62 -62
  438. package/src/types/app-context.ts +5 -1
  439. package/src/types/bindings.ts +11 -0
  440. package/src/types/config.ts +4 -4
  441. package/src/types/constants.ts +20 -0
  442. package/src/types/props.ts +34 -8
  443. package/src/types/views.ts +28 -13
  444. package/src/ui/color-themes.ts +6 -5
  445. package/src/ui/dash/settings/GeneralContent.tsx +0 -22
  446. package/src/ui/dash/settings/__tests__/GeneralContent.test.tsx +0 -21
  447. package/src/ui/feed/CuratedThreadPreview.tsx +7 -2
  448. package/src/ui/feed/LinkCard.tsx +1 -2
  449. package/src/ui/feed/NoteCard.tsx +1 -2
  450. package/src/ui/feed/QuoteCard.tsx +2 -2
  451. package/src/ui/feed/ThreadPreview.tsx +6 -6
  452. package/src/ui/feed/TimelineFeed.tsx +1 -7
  453. package/src/ui/feed/__tests__/thread-preview.test.ts +123 -10
  454. package/src/ui/feed/__tests__/timeline-cards.test.ts +18 -1
  455. package/src/ui/layouts/BaseLayout.tsx +5 -0
  456. package/src/ui/pages/ArchivePage.tsx +1 -1
  457. package/src/ui/pages/BrandPage.tsx +1 -1
  458. package/src/ui/pages/CollectionPage.tsx +0 -1
  459. package/src/ui/pages/CollectionsPage.tsx +2 -2
  460. package/src/ui/pages/ComposePage.tsx +1 -1
  461. package/src/ui/pages/FeaturedPage.tsx +1 -1
  462. package/src/ui/pages/HomePage.tsx +1 -1
  463. package/src/ui/pages/PostPage.tsx +1 -1
  464. package/src/ui/pages/SearchPage.tsx +1 -1
  465. package/src/ui/pages/SmartCollectionPage.tsx +2 -3
  466. package/src/ui/pages/SubscribePage.tsx +1 -1
  467. package/src/ui/pages/ThemeSamplePage.tsx +1 -1
  468. package/src/ui/shared/MediaGallery.tsx +1 -1
  469. package/src/vendor/datastar.js +9 -1956
  470. package/src/vendor/datastar.js.map +4 -4
  471. package/dist/client/_assets/chunks/sortable-list-BJyd-LXE.js +0 -2
  472. package/dist/client/_assets/chunks/unsafe-svg-DU_DNMy5.js +0 -2
  473. package/dist/client/_assets/client-D4AT9Iqr.js +0 -295
  474. package/dist/client/_assets/client-DRuw7XCt.css +0 -2
  475. package/dist/client/_assets/client-author-DQ8R-8KR.css +0 -2
@@ -37,6 +37,9 @@ export type ThreadSelectionParse =
37
37
 
38
38
  const READER_VISIBILITIES = ["public", "featured", "hidden", "any"] as const;
39
39
  const AUTHOR_VISIBILITIES = [...READER_VISIBILITIES, "private"] as const;
40
+
41
+ /** The `visibility` values an author's Thread list takes. */
42
+ export const THREAD_AUTHOR_VISIBILITIES = AUTHOR_VISIBILITIES;
40
43
  /** Spellings the registry reads that stay valid here. */
41
44
  const LEGACY_VISIBILITIES = ["latest_hidden"] as const;
42
45
 
@@ -47,27 +50,25 @@ function allowedVisibilities(audience: ThreadAudience): readonly string[] {
47
50
  /**
48
51
  * Read a Thread list's filter dimensions.
49
52
  *
53
+ * A parameter that names no dimension is ignored, as the API ignores any
54
+ * request field it doesn't know. A dimension with a value it can't read is
55
+ * refused.
56
+ *
50
57
  * @param read - Reads one parameter; `undefined` when absent
51
- * @param present - Every parameter name the request carries
52
- * @param options.allow - The endpoint's own parameters, which aren't
53
- * dimensions; anything else unknown is refused
54
58
  * @param options.audience - A reader may not name `private`
55
59
  * @param options.loadCollections - Loads the collection vocabulary, called only
56
60
  * when a collection is named
57
61
  * @returns The selection, or `empty` when a named collection doesn't exist
58
- * @throws {ValidationError} On an unknown parameter or an unreadable value
62
+ * @throws {ValidationError} On an unreadable value
59
63
  * @example
60
- * const parsed = await parseThreadSelection(read, Object.keys(query), {
61
- * allow: ["cursor", "limit"],
64
+ * const parsed = await parseThreadSelection(read, {
62
65
  * audience: "reader",
63
66
  * loadCollections: () => services.collections.list(),
64
67
  * });
65
68
  */
66
69
  export async function parseThreadSelection(
67
70
  read: ParamReader,
68
- present: readonly string[],
69
71
  options: {
70
- allow: readonly string[];
71
72
  audience: ThreadAudience;
72
73
  loadCollections: () => Promise<Collection[]>;
73
74
  },
@@ -101,12 +102,9 @@ export async function parseThreadSelection(
101
102
  readCollectionSlugs(readDimension).length > 0
102
103
  ? buildCollectionVocabulary(await options.loadCollections())
103
104
  : EMPTY_COLLECTION_VOCABULARY;
104
- const parsed = parsePostFilterSelectionStrict(
105
- readDimension,
106
- present,
107
- { collections },
108
- { allow: options.allow },
109
- );
105
+ const parsed = parsePostFilterSelectionStrict(readDimension, [], {
106
+ collections,
107
+ });
110
108
 
111
109
  if (parsed.ok) {
112
110
  return { kind: "selection", selection: parsed.selection, includeHidden };
@@ -123,21 +121,18 @@ export async function parseThreadSelection(
123
121
  /**
124
122
  * Read `include`: a comma-separated list of extras to attach to each Thread.
125
123
  *
124
+ * A value this release doesn't offer is skipped, not refused. `include` is
125
+ * the parameter later releases add values to, and a site keeps running the
126
+ * release it was deployed with: a client that asks one for an extra it
127
+ * doesn't have yet still gets the Threads, and the extras it has.
128
+ *
126
129
  * @param raw - The parameter's value, or `undefined`
127
130
  * @returns Whether the fold was asked for
128
- * @throws {ValidationError} On a value this endpoint doesn't offer
129
131
  * @example
130
132
  * parseThreadInclude("fold"); // { fold: true }
133
+ * parseThreadInclude("fold,collections"); // { fold: true }
131
134
  */
132
135
  export function parseThreadInclude(raw: string | undefined): { fold: boolean } {
133
- if (raw === undefined || raw === "") return { fold: false };
134
- const values = raw.split(",").map((value) => value.trim());
135
- for (const value of values) {
136
- if (value !== "fold") {
137
- throw new ValidationError(
138
- `Invalid include value "${value}". Allowed: fold`,
139
- );
140
- }
141
- }
136
+ const values = (raw ?? "").split(",").map((value) => value.trim());
142
137
  return { fold: values.includes("fold") };
143
138
  }
package/src/lib/time.ts CHANGED
@@ -94,23 +94,6 @@ export function formatDate(timestamp: number, timeZone = "UTC"): string {
94
94
  });
95
95
  }
96
96
 
97
- /**
98
- * Formats a Unix timestamp as a year-month string for grouping.
99
- *
100
- * Converts a Unix timestamp (in seconds) to a "YYYY-MM" format string, useful for
101
- * grouping posts by month in archives or creating month-based URLs. Uses the
102
- * provided timezone and defaults to UTC when no explicit timezone is given.
103
- *
104
- * @param timestamp - Unix timestamp in seconds to format
105
- * @param timeZone - IANA timezone identifier used for display
106
- * @returns Year-month string in "YYYY-MM" format
107
- *
108
- * @example
109
- * ```ts
110
- * const yearMonth = formatYearMonth(1706745600);
111
- * // Returns: "2024-02"
112
- * ```
113
- */
114
97
  /**
115
98
  * Formats a Unix timestamp as a 24-hour time string (HH:MM).
116
99
  *
@@ -212,6 +195,23 @@ export function formatRelativeAge(timestamp: number, timeZone = "UTC"): string {
212
195
  return /^[0-9]+[mhd]$/.test(relative) ? `${relative} ago` : relative;
213
196
  }
214
197
 
198
+ /**
199
+ * Formats a Unix timestamp as a year-month string for grouping.
200
+ *
201
+ * Converts a Unix timestamp (in seconds) to a "YYYY-MM" format string, useful for
202
+ * grouping posts by month in archives or creating month-based URLs. Uses the
203
+ * provided timezone and defaults to UTC when no explicit timezone is given.
204
+ *
205
+ * @param timestamp - Unix timestamp in seconds to format
206
+ * @param timeZone - IANA timezone identifier used for display
207
+ * @returns Year-month string in "YYYY-MM" format
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * const yearMonth = formatYearMonth(1706745600);
212
+ * // Returns: "2024-02"
213
+ * ```
214
+ */
215
215
  export function formatYearMonth(timestamp: number, timeZone = "UTC"): string {
216
216
  const date = new Date(timestamp * 1000);
217
217
  const parts = new Intl.DateTimeFormat("en-CA", {
@@ -224,6 +224,126 @@ export function formatYearMonth(timestamp: number, timeZone = "UTC"): string {
224
224
  return `${year}-${month}`;
225
225
  }
226
226
 
227
+ const offsetFormatters = new Map<string, Intl.DateTimeFormat>();
228
+
229
+ /** How far `timeZone`'s wall clock is ahead of UTC at an instant, in ms. */
230
+ function timeZoneOffsetMs(instantMs: number, timeZone: string): number {
231
+ let formatter = offsetFormatters.get(timeZone);
232
+ if (!formatter) {
233
+ formatter = new Intl.DateTimeFormat("en-US", {
234
+ timeZone,
235
+ hourCycle: "h23",
236
+ year: "numeric",
237
+ month: "numeric",
238
+ day: "numeric",
239
+ hour: "numeric",
240
+ minute: "numeric",
241
+ second: "numeric",
242
+ });
243
+ offsetFormatters.set(timeZone, formatter);
244
+ }
245
+ const wall: Record<string, number> = {};
246
+ for (const part of formatter.formatToParts(instantMs)) {
247
+ if (part.type !== "literal") wall[part.type] = Number(part.value);
248
+ }
249
+ const wallMs = Date.UTC(
250
+ wall.year ?? 1970,
251
+ (wall.month ?? 1) - 1,
252
+ wall.day ?? 1,
253
+ wall.hour ?? 0,
254
+ wall.minute ?? 0,
255
+ wall.second ?? 0,
256
+ );
257
+ return wallMs - Math.floor(instantMs / 1000) * 1000;
258
+ }
259
+
260
+ /**
261
+ * The Unix timestamp at which a calendar month begins on a time zone's wall
262
+ * clock.
263
+ *
264
+ * @param year - Calendar year
265
+ * @param month - Month from 1 to 12; 13 is January of the next year
266
+ * @param timeZone - IANA time zone identifier
267
+ * @returns Unix seconds of 00:00 on the month's first day in that zone
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * startOfMonthIn(2025, 1, "Asia/Shanghai");
272
+ * // Returns: 1735660800 (2024-12-31T16:00:00Z)
273
+ * ```
274
+ */
275
+ export function startOfMonthIn(
276
+ year: number,
277
+ month: number,
278
+ timeZone: string,
279
+ ): number {
280
+ const wallMs = Date.UTC(year, month - 1, 1);
281
+ // The offset at a first guess can differ from the one at the answer when a
282
+ // daylight-saving change falls between the two; one more pass settles it.
283
+ const guessMs = wallMs - timeZoneOffsetMs(wallMs, timeZone);
284
+ return Math.floor((wallMs - timeZoneOffsetMs(guessMs, timeZone)) / 1000);
285
+ }
286
+
287
+ /** A calendar year or month, and the Unix second it begins. */
288
+ export interface CalendarPeriod {
289
+ /** `YYYY` for a year, `YYYY-MM` for a month. */
290
+ key: string;
291
+ start: number;
292
+ }
293
+
294
+ /**
295
+ * The calendar years or months on a time zone's wall clock that cover a span
296
+ * of time, oldest first.
297
+ *
298
+ * @param from - Earliest Unix timestamp to cover, in seconds
299
+ * @param to - Latest Unix timestamp to cover, in seconds
300
+ * @param unit - `year` or `month`
301
+ * @param timeZone - IANA time zone identifier
302
+ * @returns Every period from the one holding `from` to the one holding `to`
303
+ *
304
+ * @example
305
+ * ```ts
306
+ * calendarPeriodsIn(1735660800, 1735700000, "month", "Asia/Shanghai");
307
+ * // Returns: [{ key: "2025-01", start: 1735660800 }]
308
+ * ```
309
+ */
310
+ export function calendarPeriodsIn(
311
+ from: number,
312
+ to: number,
313
+ unit: "year" | "month",
314
+ timeZone: string,
315
+ ): CalendarPeriod[] {
316
+ const [fromYear = 1970, fromMonth = 1] = formatYearMonth(from, timeZone)
317
+ .split("-")
318
+ .map(Number);
319
+ const [toYear = 1970, toMonth = 1] = formatYearMonth(to, timeZone)
320
+ .split("-")
321
+ .map(Number);
322
+ const periods: CalendarPeriod[] = [];
323
+ if (unit === "year") {
324
+ for (let year = fromYear; year <= toYear; year++) {
325
+ periods.push({
326
+ key: String(year),
327
+ start: startOfMonthIn(year, 1, timeZone),
328
+ });
329
+ }
330
+ return periods;
331
+ }
332
+ for (
333
+ let index = fromYear * 12 + fromMonth - 1;
334
+ index <= toYear * 12 + toMonth - 1;
335
+ index++
336
+ ) {
337
+ const year = Math.floor(index / 12);
338
+ const month = (index % 12) + 1;
339
+ periods.push({
340
+ key: `${year}-${String(month).padStart(2, "0")}`,
341
+ start: startOfMonthIn(year, month, timeZone),
342
+ });
343
+ }
344
+ return periods;
345
+ }
346
+
227
347
  /**
228
348
  * Formats a "YYYY-MM" grouping key as a readable month label.
229
349
  *
@@ -16,7 +16,7 @@ import type { AppVariables } from "../types/app-context.js";
16
16
  import { buildMediaMap } from "./media-helpers.js";
17
17
  import { createMediaContext, resolveDraftTailId, toPostView } from "./view.js";
18
18
  import { getViewLang } from "./view-language.js";
19
- import { toPublicPath } from "./url.js";
19
+ import { getPostPath, toPublicPath } from "./url.js";
20
20
 
21
21
  type Env = { Bindings: Bindings; Variables: AppVariables };
22
22
 
@@ -46,6 +46,11 @@ export interface TimelineResult {
46
46
  interface CuratedThreadSource {
47
47
  posts: Array<{ post: Post; position: number }>;
48
48
  highlightedPostIds: ReadonlySet<string>;
49
+ /**
50
+ * The first Post of each hidden run, keyed by the shown Post it follows —
51
+ * where that run's gap link points.
52
+ */
53
+ gapTargets: ReadonlyMap<string, Pick<Post, "id" | "slug">>;
49
54
  }
50
55
 
51
56
  interface CuratedThreadDisplayOptions {
@@ -55,6 +60,27 @@ interface CuratedThreadDisplayOptions {
55
60
  showContextRatings: boolean;
56
61
  }
57
62
 
63
+ /**
64
+ * Where a gap link points: the first post the gap hides, at its permalink.
65
+ *
66
+ * @param target - The first hidden post
67
+ * @param aliasesMap - Custom paths by post ID, `paths.getPostAliases()`'s
68
+ * @param sitePathPrefix - Public site path prefix
69
+ * @returns Public path of the post
70
+ * @example
71
+ * toGapHref({ id: "pst_…", slug: "abc12" }, new Map(), ""); // "/abc12"
72
+ */
73
+ function toGapHref(
74
+ target: Pick<Post, "id" | "slug">,
75
+ aliasesMap: ReadonlyMap<string, string[]>,
76
+ sitePathPrefix: string | undefined,
77
+ ): string {
78
+ return toPublicPath(
79
+ getPostPath(target.slug, aliasesMap.get(target.id)?.[0]),
80
+ sitePathPrefix,
81
+ );
82
+ }
83
+
58
84
  async function buildTimelineItems(
59
85
  c: Context<Env>,
60
86
  posts: Post[],
@@ -203,11 +229,12 @@ async function buildTimelineItems(
203
229
  trailingReplies: trailingReplyViews,
204
230
  latestReply: latestReplyView,
205
231
  gapHref: threadCtx.firstHiddenReply
206
- ? toPublicPath(
207
- `/${firstContextAlias(threadCtx.firstHiddenReply.id) ?? threadCtx.firstHiddenReply.slug}`,
232
+ ? toGapHref(
233
+ threadCtx.firstHiddenReply,
234
+ contextAliasesMap,
208
235
  mediaCtx.sitePathPrefix,
209
236
  )
210
- : undefined,
237
+ : null,
211
238
  totalReplyCount: threadCtx.totalReplyCount,
212
239
  },
213
240
  };
@@ -256,10 +283,15 @@ async function buildCuratedThreadItems(
256
283
  const postIds = orderedThreads.flatMap((thread) =>
257
284
  thread.posts.map(({ post }) => post.id),
258
285
  );
286
+ const gapPostIds = orderedThreads.flatMap((thread) =>
287
+ [...thread.gapTargets.values()].map((target) => target.id),
288
+ );
259
289
  const [rawMediaMap, collectionsMap, curatedAliasesMap] = await Promise.all([
260
290
  c.var.services.media.getByPostIds(postIds),
261
291
  c.var.services.collections.getCollectionsByPostIds(postIds),
262
- c.var.services.paths.getPostAliases(postIds),
292
+ // Gap targets are never rendered, so they need only the alias that
293
+ // decides their address.
294
+ c.var.services.paths.getPostAliases([...postIds, ...gapPostIds]),
263
295
  ]);
264
296
  const mediaMap = buildMediaMap(
265
297
  rawMediaMap,
@@ -301,17 +333,23 @@ async function buildCuratedThreadItems(
301
333
  const segments = renderedPosts.reduce<
302
334
  NonNullable<TimelineItemView["curatedThread"]>["segments"]
303
335
  >((items, renderedPost, segmentIndex) => {
304
- const previousPosition =
305
- segmentIndex === 0
306
- ? undefined
307
- : renderedPosts[segmentIndex - 1]?.position;
336
+ const previous =
337
+ segmentIndex === 0 ? undefined : renderedPosts[segmentIndex - 1];
338
+ const hiddenBeforeCount =
339
+ previous === undefined
340
+ ? renderedPost.position
341
+ : renderedPost.position - previous.position - 1;
342
+ const gapTarget =
343
+ previous && hiddenBeforeCount > 0
344
+ ? thread.gapTargets.get(previous.view.id)
345
+ : undefined;
308
346
 
309
347
  items.push({
310
348
  post: renderedPost.view,
311
- hiddenBeforeCount:
312
- previousPosition === undefined
313
- ? renderedPost.position
314
- : renderedPost.position - previousPosition - 1,
349
+ hiddenBeforeCount,
350
+ gapHref: gapTarget
351
+ ? toGapHref(gapTarget, curatedAliasesMap, mediaCtx.sitePathPrefix)
352
+ : null,
315
353
  highlighted:
316
354
  thread.highlightedPostIds.has(renderedPost.view.id) ||
317
355
  (display.highlightLatestPost === true &&
@@ -485,6 +523,9 @@ export async function assembleFeaturedTimeline(
485
523
  {
486
524
  posts: thread.posts,
487
525
  highlightedPostIds: new Set(thread.featuredPostIds),
526
+ gapTargets: new Map(
527
+ thread.gapTargets.map((target) => [target.afterPostId, target]),
528
+ ),
488
529
  },
489
530
  ]),
490
531
  );
@@ -560,6 +601,8 @@ export async function assembleCollectionTimeline(
560
601
  {
561
602
  posts: thread.map((post, position) => ({ post, position })),
562
603
  highlightedPostIds: new Set<string>(),
604
+ // Every post is shown, so there is no gap to point anywhere.
605
+ gapTargets: new Map(),
563
606
  },
564
607
  ]),
565
608
  );
@@ -8,10 +8,14 @@
8
8
  * attacker-influenced, so every fetch passes through an SSRF guard and a bounded
9
9
  * reader that caps size and time.
10
10
  *
11
- * Note: DNS is not resolvable from a Cloudflare Worker, so the IP-literal checks
12
- * here are defense-in-depth for self-hosted (Node) deployments and for URLs that
13
- * embed a literal address. They are not a substitute for network-level egress
14
- * controls.
11
+ * Two layers guard the address. {@link assertPublicHttpUrl} refuses a URL whose
12
+ * host is a private name or IP literal, in any of the forms an IPv6 address can
13
+ * carry an IPv4 one. On Node, {@link fetchImageBytes} also resolves each host
14
+ * and refuses it when any address it resolves to is private, which catches
15
+ * names like `127.0.0.1.nip.io`. A Worker's fetch can't reach a private network
16
+ * at all, so it skips the lookup. A host that answers a public address to the
17
+ * check and a private one to the fetch a moment later (DNS rebinding) is out of
18
+ * reach of both; that needs network-level egress control.
15
19
  */
16
20
 
17
21
  import { ValidationError } from "./errors.js";
@@ -64,13 +68,12 @@ export function assertPublicHttpUrl(raw: string): URL {
64
68
  throw new ValidationError("Image URLs can't include credentials.");
65
69
  }
66
70
 
67
- const host = url.hostname.toLowerCase();
71
+ // A trailing dot names the same host (`localhost.` is `localhost`).
72
+ const host = url.hostname.toLowerCase().replace(/\.+$/, "");
68
73
  if (
69
74
  host === "localhost" ||
70
75
  host.endsWith(".localhost") ||
71
- host === "0.0.0.0" ||
72
- isPrivateIpv4(host) ||
73
- isPrivateIpv6(host)
76
+ isPrivateAddress(host)
74
77
  ) {
75
78
  throw new ValidationError("That image URL points to a private address.");
76
79
  }
@@ -78,6 +81,47 @@ export function assertPublicHttpUrl(raw: string): URL {
78
81
  return url;
79
82
  }
80
83
 
84
+ /**
85
+ * Resolves a URL's host and refuses it when any address is private.
86
+ *
87
+ * Skipped on Cloudflare Workers, whose fetch can't reach a private network.
88
+ *
89
+ * @param url - A URL already accepted by {@link assertPublicHttpUrl}
90
+ * @throws {ValidationError} When the host resolves to a private address or
91
+ * doesn't resolve
92
+ * @example
93
+ * ```ts
94
+ * await assertResolvesPublic(new URL("https://127.0.0.1.nip.io/a.png")); // throws
95
+ * ```
96
+ */
97
+ export async function assertResolvesPublic(url: URL): Promise<void> {
98
+ if (isCloudflareWorker()) return;
99
+ const host = url.hostname.replace(/^\[|\]$/g, "");
100
+ if (isIpLiteral(host)) return; // Already checked by assertPublicHttpUrl.
101
+
102
+ const { lookup } = await import("node:dns/promises");
103
+ let addresses: { address: string }[];
104
+ try {
105
+ addresses = await lookup(host, { all: true, verbatim: true });
106
+ } catch {
107
+ throw new ValidationError("Couldn't find the image's host.");
108
+ }
109
+ if (addresses.some(({ address }) => isPrivateAddress(address))) {
110
+ throw new ValidationError("That image URL points to a private address.");
111
+ }
112
+ }
113
+
114
+ function isCloudflareWorker(): boolean {
115
+ return (
116
+ typeof navigator !== "undefined" &&
117
+ navigator.userAgent === "Cloudflare-Workers"
118
+ );
119
+ }
120
+
121
+ function isIpLiteral(host: string): boolean {
122
+ return /^\d{1,3}(\.\d{1,3}){3}$/.test(host) || host.includes(":");
123
+ }
124
+
81
125
  /**
82
126
  * Fetch a remote image with an SSRF-checked redirect chain, a size cap, and a
83
127
  * timeout. Reads the body in chunks and aborts the moment it exceeds `maxBytes`
@@ -107,6 +151,7 @@ export async function fetchImageBytes(
107
151
  let response: Response | null = null;
108
152
 
109
153
  for (let hop = 0; hop <= maxRedirects; hop++) {
154
+ await assertResolvesPublic(url);
110
155
  response = await fetch(url.toString(), {
111
156
  method: "GET",
112
157
  redirect: "manual",
@@ -211,53 +256,109 @@ function normalizeContentType(raw: string | null): string | null {
211
256
  }
212
257
 
213
258
  /**
214
- * True when a canonicalized IPv4 dotted-quad host is in a private, loopback,
215
- * link-local, CGNAT, or otherwise non-public range. The WHATWG URL parser
216
- * already normalizes decimal/octal/hex IPv4 forms to dotted-quad, so checking
217
- * `url.hostname` is sufficient.
259
+ * True when a host or resolved address is not a public unicast address: a
260
+ * private, loopback, link-local, CGNAT, multicast, or reserved IPv4 address,
261
+ * or an IPv6 address in the matching ranges, including every form that embeds
262
+ * an IPv4 address (mapped, compatible, NAT64, 6to4). Names return `false`.
263
+ *
264
+ * @param host - An IP literal, bracketed or bare, or a host name
265
+ * @returns `true` when the address must not be fetched
266
+ *
267
+ * @example
268
+ * ```ts
269
+ * isPrivateAddress("10.0.0.1"); // true
270
+ * isPrivateAddress("[::7f00:1]"); // true: IPv4-compatible 127.0.0.1
271
+ * isPrivateAddress("example.com"); // false
272
+ * ```
273
+ */
274
+ export function isPrivateAddress(host: string): boolean {
275
+ const bare = host.replace(/^\[|\]$/g, "").toLowerCase();
276
+ if (/^\d{1,3}(\.\d{1,3}){3}$/.test(bare)) return isPrivateIpv4(bare);
277
+ if (bare.includes(":")) return isPrivateIpv6(bare);
278
+ return false;
279
+ }
280
+
281
+ /**
282
+ * True when a dotted-quad IPv4 address is in a non-public range. The WHATWG
283
+ * URL parser already normalizes decimal, octal, and hex IPv4 forms to
284
+ * dotted-quad, so checking `url.hostname` is sufficient.
218
285
  */
219
286
  function isPrivateIpv4(host: string): boolean {
220
- const match = host.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
221
- if (!match) return false;
222
- const octets = match.slice(1, 5).map(Number);
223
- if (octets.some((part) => part > 255)) return true; // Malformed → unsafe.
224
- const a = octets[0] ?? 0;
225
- const b = octets[1] ?? 0;
287
+ const octets = host.split(".").map(Number);
288
+ if (octets.length !== 4 || octets.some((part) => part > 255)) return true;
289
+ const [a = 0, b = 0] = octets;
226
290
  if (a === 0) return true; // 0.0.0.0/8 "this" network
227
291
  if (a === 10) return true; // 10/8 private
228
292
  if (a === 127) return true; // 127/8 loopback
229
293
  if (a === 169 && b === 254) return true; // 169.254/16 link-local (metadata)
230
294
  if (a === 172 && b >= 16 && b <= 31) return true; // 172.16/12 private
231
295
  if (a === 192 && b === 168) return true; // 192.168/16 private
296
+ if (a === 192 && b === 0 && octets[2] === 0) return true; // 192.0.0/24 IETF
297
+ if (a === 198 && (b === 18 || b === 19)) return true; // 198.18/15 benchmarking
232
298
  if (a === 100 && b >= 64 && b <= 127) return true; // 100.64/10 CGNAT
233
- if (a === 255 && b === 255) return true; // broadcast
299
+ if (a >= 224) return true; // multicast, reserved, broadcast
234
300
  return false;
235
301
  }
236
302
 
237
- /** True when an IPv6 host (bracketed or bare) is loopback/link-local/ULA/mapped-private. */
238
- function isPrivateIpv6(host: string): boolean {
239
- let inner = host;
240
- if (inner.startsWith("[") && inner.endsWith("]")) {
241
- inner = inner.slice(1, -1);
303
+ /** Expands an IPv6 address to its eight 16-bit groups, or null if malformed. */
304
+ function expandIpv6(address: string): number[] | null {
305
+ let text = address.split("%")[0] ?? "";
306
+ // A trailing dotted IPv4 part becomes two groups.
307
+ const v4 = text.match(/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
308
+ if (v4) {
309
+ const [p1, p2, p3, p4] = v4.slice(1, 5).map(Number) as [
310
+ number,
311
+ number,
312
+ number,
313
+ number,
314
+ ];
315
+ if ([p1, p2, p3, p4].some((part) => part > 255)) return null;
316
+ text = `${text.slice(0, v4.index)}${((p1 << 8) | p2).toString(16)}:${((p3 << 8) | p4).toString(16)}`;
242
317
  }
243
- if (!inner.includes(":")) return false;
244
- const lower = inner.toLowerCase();
245
- if (lower === "::" || lower === "::1") return true; // unspecified / loopback
246
318
 
247
- // IPv4-mapped, dotted form (::ffff:1.2.3.4).
248
- const dotted = lower.match(/^::ffff:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
249
- if (dotted?.[1]) return isPrivateIpv4(dotted[1]);
250
-
251
- // IPv4-mapped, hex form (::ffff:a00:1) — what the URL parser normalizes to.
252
- const hex = lower.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
253
- if (hex) {
254
- const hi = parseInt(hex[1] ?? "0", 16);
255
- const lo = parseInt(hex[2] ?? "0", 16);
256
- const v4 = `${(hi >> 8) & 0xff}.${hi & 0xff}.${(lo >> 8) & 0xff}.${lo & 0xff}`;
257
- return isPrivateIpv4(v4);
319
+ const halves = text.split("::");
320
+ if (halves.length > 2) return null;
321
+ const parse = (part: string | undefined) =>
322
+ part ? part.split(":").map((group) => parseInt(group, 16)) : [];
323
+ const head = parse(halves[0]);
324
+ const tail = parse(halves[1]);
325
+ const missing = 8 - head.length - tail.length;
326
+ if (halves.length === 1 ? missing !== 0 : missing < 0) return null;
327
+ const groups = [...head, ...Array<number>(missing).fill(0), ...tail];
328
+ if (
329
+ groups.some(
330
+ (group) => !Number.isInteger(group) || group < 0 || group > 0xffff,
331
+ )
332
+ ) {
333
+ return null;
258
334
  }
335
+ return groups;
336
+ }
259
337
 
260
- if (/^fe[89ab]/.test(lower)) return true; // fe80::/10 link-local
261
- if (/^f[cd]/.test(lower)) return true; // fc00::/7 unique local
338
+ function embeddedIpv4(high: number, low: number): string {
339
+ return `${high >> 8}.${high & 0xff}.${low >> 8}.${low & 0xff}`;
340
+ }
341
+
342
+ /** True when an IPv6 address is in a non-public range, or embeds a private IPv4. */
343
+ function isPrivateIpv6(address: string): boolean {
344
+ const groups = expandIpv6(address);
345
+ if (!groups) return true; // Malformed → unsafe.
346
+ const [g0 = 0, g1 = 0, g2 = 0, g3 = 0, g4 = 0, g5 = 0, g6 = 0, g7 = 0] =
347
+ groups;
348
+
349
+ if (g0 === 0 && g1 === 0 && g2 === 0 && g3 === 0 && g4 === 0) {
350
+ // ::ffff:a.b.c.d (mapped) and ::a.b.c.d (compatible, which covers :: and ::1).
351
+ if (g5 === 0xffff || g5 === 0) return true;
352
+ }
353
+ if (g0 === 0x64 && g1 === 0xff9b) {
354
+ // 64:ff9b::/96 well-known NAT64 prefix; 64:ff9b:1::/48 is local-use.
355
+ return g2 !== 0 || isPrivateIpv4(embeddedIpv4(g6, g7));
356
+ }
357
+ if (g0 === 0x2002) return isPrivateIpv4(embeddedIpv4(g1, g2)); // 6to4
358
+ if (g0 === 0x2001 && g1 === 0) return true; // 2001::/32 Teredo
359
+ if (g0 === 0x2001 && g1 === 0xdb8) return true; // 2001:db8::/32 documentation
360
+ if ((g0 & 0xffc0) === 0xfe80) return true; // fe80::/10 link-local
361
+ if ((g0 & 0xfe00) === 0xfc00) return true; // fc00::/7 unique local
362
+ if ((g0 & 0xff00) === 0xff00) return true; // ff00::/8 multicast
262
363
  return false;
263
364
  }