@jant/core 0.3.6 → 0.3.8

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 (264) hide show
  1. package/dist/app.js +11 -21
  2. package/dist/client.js +1 -0
  3. package/dist/db/schema.js +15 -0
  4. package/dist/i18n/locales/en.js +1 -1
  5. package/dist/i18n/locales/zh-Hans.js +1 -1
  6. package/dist/i18n/locales/zh-Hant.js +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lib/image.js +3 -3
  9. package/dist/lib/media-helpers.js +43 -0
  10. package/dist/lib/nav-reorder.js +27 -0
  11. package/dist/lib/navigation.js +35 -0
  12. package/dist/lib/schemas.js +32 -2
  13. package/dist/lib/sse.js +7 -8
  14. package/dist/lib/theme-components.js +49 -0
  15. package/dist/routes/api/posts.js +101 -5
  16. package/dist/routes/api/timeline.js +115 -0
  17. package/dist/routes/api/upload.js +9 -5
  18. package/dist/routes/dash/media.js +38 -0
  19. package/dist/routes/dash/navigation.js +274 -0
  20. package/dist/routes/dash/posts.js +45 -6
  21. package/dist/routes/feed/rss.js +10 -1
  22. package/dist/routes/pages/archive.js +14 -27
  23. package/dist/routes/pages/collection.js +10 -19
  24. package/dist/routes/pages/home.js +88 -98
  25. package/dist/routes/pages/page.js +19 -38
  26. package/dist/routes/pages/post.js +61 -48
  27. package/dist/routes/pages/search.js +13 -26
  28. package/dist/services/collection.js +13 -0
  29. package/dist/services/index.js +3 -1
  30. package/dist/services/media.js +55 -2
  31. package/dist/services/navigation.js +115 -0
  32. package/dist/services/post.js +26 -1
  33. package/dist/theme/components/MediaGallery.js +107 -0
  34. package/dist/theme/components/PostForm.js +158 -2
  35. package/dist/theme/components/PostList.js +5 -0
  36. package/dist/theme/components/index.js +3 -0
  37. package/dist/theme/components/timeline/ArticleCard.js +50 -0
  38. package/dist/theme/components/timeline/ImageCard.js +86 -0
  39. package/dist/theme/components/timeline/LinkCard.js +62 -0
  40. package/dist/theme/components/timeline/NoteCard.js +37 -0
  41. package/dist/theme/components/timeline/QuoteCard.js +51 -0
  42. package/dist/theme/components/timeline/ThreadPreview.js +52 -0
  43. package/dist/theme/components/timeline/TimelineFeed.js +43 -0
  44. package/dist/theme/components/timeline/TimelineItem.js +25 -0
  45. package/dist/theme/components/timeline/index.js +8 -0
  46. package/dist/theme/layouts/DashLayout.js +8 -0
  47. package/dist/theme/layouts/SiteLayout.js +160 -0
  48. package/dist/theme/layouts/index.js +1 -0
  49. package/dist/types/sortablejs.d.js +5 -0
  50. package/dist/types.js +27 -0
  51. package/package.json +3 -2
  52. package/src/__tests__/helpers/app.ts +6 -1
  53. package/src/__tests__/helpers/db.ts +20 -0
  54. package/src/app.tsx +11 -25
  55. package/src/client.ts +1 -0
  56. package/src/db/migrations/0002_add_media_attachments.sql +3 -0
  57. package/src/db/migrations/0003_add_navigation_links.sql +8 -0
  58. package/src/db/migrations/meta/0003_snapshot.json +821 -0
  59. package/src/db/migrations/meta/_journal.json +14 -0
  60. package/src/db/schema.ts +15 -0
  61. package/src/i18n/locales/en.po +170 -58
  62. package/src/i18n/locales/en.ts +1 -1
  63. package/src/i18n/locales/zh-Hans.po +162 -71
  64. package/src/i18n/locales/zh-Hans.ts +1 -1
  65. package/src/i18n/locales/zh-Hant.po +162 -71
  66. package/src/i18n/locales/zh-Hant.ts +1 -1
  67. package/src/index.ts +13 -1
  68. package/src/lib/__tests__/schemas.test.ts +89 -1
  69. package/src/lib/__tests__/sse.test.ts +13 -1
  70. package/src/lib/__tests__/theme-components.test.ts +107 -0
  71. package/src/lib/image.ts +3 -3
  72. package/src/lib/media-helpers.ts +54 -0
  73. package/src/lib/nav-reorder.ts +26 -0
  74. package/src/lib/navigation.ts +46 -0
  75. package/src/lib/schemas.ts +47 -1
  76. package/src/lib/sse.ts +10 -11
  77. package/src/lib/theme-components.ts +76 -0
  78. package/src/routes/api/__tests__/posts.test.ts +239 -0
  79. package/src/routes/api/__tests__/timeline.test.ts +242 -0
  80. package/src/routes/api/posts.ts +134 -5
  81. package/src/routes/api/timeline.tsx +145 -0
  82. package/src/routes/api/upload.ts +9 -5
  83. package/src/routes/dash/media.tsx +50 -0
  84. package/src/routes/dash/navigation.tsx +306 -0
  85. package/src/routes/dash/posts.tsx +79 -7
  86. package/src/routes/feed/rss.ts +14 -1
  87. package/src/routes/pages/archive.tsx +15 -23
  88. package/src/routes/pages/collection.tsx +8 -15
  89. package/src/routes/pages/home.tsx +121 -88
  90. package/src/routes/pages/page.tsx +17 -30
  91. package/src/routes/pages/post.tsx +64 -40
  92. package/src/routes/pages/search.tsx +18 -22
  93. package/src/services/__tests__/collection.test.ts +102 -0
  94. package/src/services/__tests__/media.test.ts +282 -7
  95. package/src/services/__tests__/navigation.test.ts +213 -0
  96. package/src/services/__tests__/post-timeline.test.ts +220 -0
  97. package/src/services/collection.ts +19 -0
  98. package/src/services/index.ts +7 -0
  99. package/src/services/media.ts +78 -2
  100. package/src/services/navigation.ts +165 -0
  101. package/src/services/post.ts +48 -1
  102. package/src/styles/components.css +59 -0
  103. package/src/theme/components/MediaGallery.tsx +128 -0
  104. package/src/theme/components/PostForm.tsx +170 -2
  105. package/src/theme/components/PostList.tsx +7 -0
  106. package/src/theme/components/index.ts +13 -0
  107. package/src/theme/components/timeline/ArticleCard.tsx +57 -0
  108. package/src/theme/components/timeline/ImageCard.tsx +80 -0
  109. package/src/theme/components/timeline/LinkCard.tsx +66 -0
  110. package/src/theme/components/timeline/NoteCard.tsx +41 -0
  111. package/src/theme/components/timeline/QuoteCard.tsx +55 -0
  112. package/src/theme/components/timeline/ThreadPreview.tsx +49 -0
  113. package/src/theme/components/timeline/TimelineFeed.tsx +52 -0
  114. package/src/theme/components/timeline/TimelineItem.tsx +39 -0
  115. package/src/theme/components/timeline/index.ts +8 -0
  116. package/src/theme/layouts/DashLayout.tsx +10 -0
  117. package/src/theme/layouts/SiteLayout.tsx +184 -0
  118. package/src/theme/layouts/index.ts +1 -0
  119. package/src/types/sortablejs.d.ts +23 -0
  120. package/src/types.ts +97 -0
  121. package/dist/app.d.ts +0 -38
  122. package/dist/app.d.ts.map +0 -1
  123. package/dist/auth.d.ts +0 -25
  124. package/dist/auth.d.ts.map +0 -1
  125. package/dist/db/index.d.ts +0 -10
  126. package/dist/db/index.d.ts.map +0 -1
  127. package/dist/db/schema.d.ts +0 -1507
  128. package/dist/db/schema.d.ts.map +0 -1
  129. package/dist/i18n/Trans.d.ts +0 -25
  130. package/dist/i18n/Trans.d.ts.map +0 -1
  131. package/dist/i18n/context.d.ts +0 -69
  132. package/dist/i18n/context.d.ts.map +0 -1
  133. package/dist/i18n/detect.d.ts +0 -20
  134. package/dist/i18n/detect.d.ts.map +0 -1
  135. package/dist/i18n/i18n.d.ts +0 -32
  136. package/dist/i18n/i18n.d.ts.map +0 -1
  137. package/dist/i18n/index.d.ts +0 -41
  138. package/dist/i18n/index.d.ts.map +0 -1
  139. package/dist/i18n/locales/en.d.ts +0 -3
  140. package/dist/i18n/locales/en.d.ts.map +0 -1
  141. package/dist/i18n/locales/zh-Hans.d.ts +0 -3
  142. package/dist/i18n/locales/zh-Hans.d.ts.map +0 -1
  143. package/dist/i18n/locales/zh-Hant.d.ts +0 -3
  144. package/dist/i18n/locales/zh-Hant.d.ts.map +0 -1
  145. package/dist/i18n/locales.d.ts +0 -11
  146. package/dist/i18n/locales.d.ts.map +0 -1
  147. package/dist/i18n/middleware.d.ts +0 -21
  148. package/dist/i18n/middleware.d.ts.map +0 -1
  149. package/dist/index.d.ts +0 -16
  150. package/dist/index.d.ts.map +0 -1
  151. package/dist/lib/config.d.ts +0 -83
  152. package/dist/lib/config.d.ts.map +0 -1
  153. package/dist/lib/constants.d.ts +0 -37
  154. package/dist/lib/constants.d.ts.map +0 -1
  155. package/dist/lib/image.d.ts +0 -73
  156. package/dist/lib/image.d.ts.map +0 -1
  157. package/dist/lib/index.d.ts +0 -9
  158. package/dist/lib/index.d.ts.map +0 -1
  159. package/dist/lib/markdown.d.ts +0 -60
  160. package/dist/lib/markdown.d.ts.map +0 -1
  161. package/dist/lib/schemas.d.ts +0 -113
  162. package/dist/lib/schemas.d.ts.map +0 -1
  163. package/dist/lib/sqid.d.ts +0 -60
  164. package/dist/lib/sqid.d.ts.map +0 -1
  165. package/dist/lib/sse.d.ts +0 -192
  166. package/dist/lib/sse.d.ts.map +0 -1
  167. package/dist/lib/theme.d.ts +0 -44
  168. package/dist/lib/theme.d.ts.map +0 -1
  169. package/dist/lib/time.d.ts +0 -90
  170. package/dist/lib/time.d.ts.map +0 -1
  171. package/dist/lib/url.d.ts +0 -82
  172. package/dist/lib/url.d.ts.map +0 -1
  173. package/dist/middleware/auth.d.ts +0 -24
  174. package/dist/middleware/auth.d.ts.map +0 -1
  175. package/dist/middleware/onboarding.d.ts +0 -26
  176. package/dist/middleware/onboarding.d.ts.map +0 -1
  177. package/dist/routes/api/posts.d.ts +0 -13
  178. package/dist/routes/api/posts.d.ts.map +0 -1
  179. package/dist/routes/api/search.d.ts +0 -13
  180. package/dist/routes/api/search.d.ts.map +0 -1
  181. package/dist/routes/api/upload.d.ts +0 -16
  182. package/dist/routes/api/upload.d.ts.map +0 -1
  183. package/dist/routes/dash/collections.d.ts +0 -13
  184. package/dist/routes/dash/collections.d.ts.map +0 -1
  185. package/dist/routes/dash/index.d.ts +0 -15
  186. package/dist/routes/dash/index.d.ts.map +0 -1
  187. package/dist/routes/dash/media.d.ts +0 -16
  188. package/dist/routes/dash/media.d.ts.map +0 -1
  189. package/dist/routes/dash/pages.d.ts +0 -15
  190. package/dist/routes/dash/pages.d.ts.map +0 -1
  191. package/dist/routes/dash/posts.d.ts +0 -13
  192. package/dist/routes/dash/posts.d.ts.map +0 -1
  193. package/dist/routes/dash/redirects.d.ts +0 -13
  194. package/dist/routes/dash/redirects.d.ts.map +0 -1
  195. package/dist/routes/dash/settings.d.ts +0 -15
  196. package/dist/routes/dash/settings.d.ts.map +0 -1
  197. package/dist/routes/feed/rss.d.ts +0 -13
  198. package/dist/routes/feed/rss.d.ts.map +0 -1
  199. package/dist/routes/feed/sitemap.d.ts +0 -13
  200. package/dist/routes/feed/sitemap.d.ts.map +0 -1
  201. package/dist/routes/pages/archive.d.ts +0 -15
  202. package/dist/routes/pages/archive.d.ts.map +0 -1
  203. package/dist/routes/pages/collection.d.ts +0 -13
  204. package/dist/routes/pages/collection.d.ts.map +0 -1
  205. package/dist/routes/pages/home.d.ts +0 -13
  206. package/dist/routes/pages/home.d.ts.map +0 -1
  207. package/dist/routes/pages/page.d.ts +0 -15
  208. package/dist/routes/pages/page.d.ts.map +0 -1
  209. package/dist/routes/pages/post.d.ts +0 -13
  210. package/dist/routes/pages/post.d.ts.map +0 -1
  211. package/dist/routes/pages/search.d.ts +0 -13
  212. package/dist/routes/pages/search.d.ts.map +0 -1
  213. package/dist/services/collection.d.ts +0 -31
  214. package/dist/services/collection.d.ts.map +0 -1
  215. package/dist/services/index.d.ts +0 -28
  216. package/dist/services/index.d.ts.map +0 -1
  217. package/dist/services/media.d.ts +0 -27
  218. package/dist/services/media.d.ts.map +0 -1
  219. package/dist/services/post.d.ts +0 -31
  220. package/dist/services/post.d.ts.map +0 -1
  221. package/dist/services/redirect.d.ts +0 -15
  222. package/dist/services/redirect.d.ts.map +0 -1
  223. package/dist/services/search.d.ts +0 -26
  224. package/dist/services/search.d.ts.map +0 -1
  225. package/dist/services/settings.d.ts +0 -18
  226. package/dist/services/settings.d.ts.map +0 -1
  227. package/dist/theme/color-themes.d.ts +0 -30
  228. package/dist/theme/color-themes.d.ts.map +0 -1
  229. package/dist/theme/components/ActionButtons.d.ts +0 -43
  230. package/dist/theme/components/ActionButtons.d.ts.map +0 -1
  231. package/dist/theme/components/CrudPageHeader.d.ts +0 -23
  232. package/dist/theme/components/CrudPageHeader.d.ts.map +0 -1
  233. package/dist/theme/components/DangerZone.d.ts +0 -36
  234. package/dist/theme/components/DangerZone.d.ts.map +0 -1
  235. package/dist/theme/components/EmptyState.d.ts +0 -27
  236. package/dist/theme/components/EmptyState.d.ts.map +0 -1
  237. package/dist/theme/components/ListItemRow.d.ts +0 -15
  238. package/dist/theme/components/ListItemRow.d.ts.map +0 -1
  239. package/dist/theme/components/PageForm.d.ts +0 -14
  240. package/dist/theme/components/PageForm.d.ts.map +0 -1
  241. package/dist/theme/components/Pagination.d.ts +0 -46
  242. package/dist/theme/components/Pagination.d.ts.map +0 -1
  243. package/dist/theme/components/PostForm.d.ts +0 -11
  244. package/dist/theme/components/PostForm.d.ts.map +0 -1
  245. package/dist/theme/components/PostList.d.ts +0 -10
  246. package/dist/theme/components/PostList.d.ts.map +0 -1
  247. package/dist/theme/components/ThreadView.d.ts +0 -15
  248. package/dist/theme/components/ThreadView.d.ts.map +0 -1
  249. package/dist/theme/components/TypeBadge.d.ts +0 -12
  250. package/dist/theme/components/TypeBadge.d.ts.map +0 -1
  251. package/dist/theme/components/VisibilityBadge.d.ts +0 -12
  252. package/dist/theme/components/VisibilityBadge.d.ts.map +0 -1
  253. package/dist/theme/components/index.d.ts +0 -13
  254. package/dist/theme/components/index.d.ts.map +0 -1
  255. package/dist/theme/index.d.ts +0 -21
  256. package/dist/theme/index.d.ts.map +0 -1
  257. package/dist/theme/layouts/BaseLayout.d.ts +0 -23
  258. package/dist/theme/layouts/BaseLayout.d.ts.map +0 -1
  259. package/dist/theme/layouts/DashLayout.d.ts +0 -17
  260. package/dist/theme/layouts/DashLayout.d.ts.map +0 -1
  261. package/dist/theme/layouts/index.d.ts +0 -3
  262. package/dist/theme/layouts/index.d.ts.map +0 -1
  263. package/dist/types.d.ts +0 -213
  264. package/dist/types.d.ts.map +0 -1
@@ -1 +1 @@
1
- /*eslint-disable*/import type{Messages}from"@lingui/core";export const messages=JSON.parse("{\"+7Wr2a\":[\"Edit: \",[\"title\"]],\"+MACwa\":[\"尚未有任何收藏。\"],\"+owNNn\":[\"文章\"],\"+zy2Nq\":[\"類型\"],\"/0D1Xp\":[\"編輯收藏集\"],\"/Rj5P4\":[\"您的姓名\"],\"07Epll\":[\"這將為您的網站和儀表板設置主題。所有顏色主題都支持深色模式。\"],\"0JkyS7\":[\"建立您的第一個頁面\"],\"0a6MpL\":[\"新重定向\"],\"1CU1Td\":[\"網址安全識別碼(小寫、數字、連字符)\"],\"1DBGsz\":[\"筆記\"],\"2N0qpv\":[\"文章標題...\"],\"2q/Q7x\":[\"可見性\"],\"2rJGtU\":[\"頁面標題...\"],\"3Yvsaz\":[\"302(臨時)\"],\"4/SFQS\":[\"查看網站\"],\"40TVQj\":[\"自訂路徑(選填)\"],\"4KzVT6\":[\"刪除頁面\"],\"4b3oEV\":[\"內容\"],\"4mDPGp\":[\"此頁面的 URL 路徑。使用小寫字母、數字和連字符。\"],\"6WdDG7\":[\"頁面\"],\"6YtxFj\":[\"名稱\"],\"7G4SBz\":[\"頁面內容(支持Markdown)...\"],\"7Mk+/h\":[\"更新收藏集\"],\"7Q1KKN\":[\"來源路徑\"],\"7aECQB\":[\"無效或已過期的連結\"],\"7nGhhM\":[\"你在想什麼?\"],\"7p5kLi\":[\"儀表板\"],\"7vhWI8\":[\"新密碼\"],\"8ZsakT\":[\"密碼\"],\"90Luob\":[[\"count\"],\" 條回覆\"],\"A1taO8\":[\"搜尋\"],\"AeXO77\":[\"帳戶\"],\"AyHO4m\":[\"這個收藏是關於什麼的?\"],\"B373X+\":[\"編輯文章\"],\"B495Gs\":[\"檔案館\"],\"BjF0Jv\":[\"僅限小寫字母、數字和連字符\"],\"D9Oea+\":[\"永久鏈接\"],\"DCKkhU\":[\"當前密碼\"],\"DHhJ7s\":[\"上一頁\"],\"DoJzLz\":[\"收藏夾\"],\"E80cJw\":[\"刪除此媒體將永久從存儲中移除它。\"],\"EEYbdt\":[\"發佈\"],\"EGwzOK\":[\"完成設置\"],\"EkH9pt\":[\"更新\"],\"FGrimz\":[\"新帖子\"],\"FkMol5\":[\"精選\"],\"Fxf4jq\":[\"描述(可選)\"],\"GA5A5H\":[\"刪除收藏夾\"],\"GX2VMa\":[\"建立您的管理員帳戶。\"],\"GbVAnd\":[\"此密碼重設連結無效或已過期。請生成一個新的連結。\"],\"GorKul\":[\"歡迎來到 Jant\"],\"GrZ6fH\":[\"新頁面\"],\"GxkJXS\":[\"上傳中...\"],\"HfyyXl\":[\"My Blog\"],\"HiETwV\":[\"安靜(正常)\"],\"Hzi9AA\":[\"未找到任何帖子。\"],\"I6gXOa\":[\"路徑\"],\"IagCbF\":[\"網址\"],\"J4FNfC\":[\"此集合中沒有帖子。\"],\"JIBC/T\":[\"Supported formats: JPEG, PNG, GIF, WebP, SVG. Max size: 10MB.\"],\"Jed1wB\":[\"需要幫助嗎?請訪問<0>文檔</0>。\"],\"JiP4aa\":[\"已發佈的頁面可以通過其路徑訪問。草稿不可見。\"],\"K9NcLu\":[\"使用此 URL 將媒體嵌入到您的帖子中。\"],\"KbS2K9\":[\"重設密碼\"],\"KiJn9B\":[\"備註\"],\"L85WcV\":[\"縮略名\"],\"LkvLQe\":[\"尚未有頁面。\"],\"M1RvTd\":[\"點擊圖片以查看完整大小\"],\"M8kJqa\":[\"草稿\"],\"M9xgHy\":[\"重定向\"],\"MHrjPM\":[\"標題\"],\"MZbQHL\":[\"未找到結果。\"],\"Mhf/H/\":[\"建立重定向\"],\"MqghUt\":[\"搜尋帖子...\"],\"N40H+G\":[\"所有\"],\"O3oNi5\":[\"電子郵件\"],\"OCNZaU\":[\"重定向來源的路徑\"],\"ODiSoW\":[\"尚未有帖子。\"],\"ONWvwQ\":[\"上傳\"],\"Pbm2/N\":[\"創建收藏夾\"],\"RDjuBN\":[\"Setup\"],\"Rj01Fz\":[\"連結\"],\"RwGhWy\":[\"包含 \",[\"count\"],\" 則帖子的主題\"],\"SJmfuf\":[\"網站名稱\"],\"ST+lN2\":[\"尚未上傳任何媒體。\"],\"Tt5T6+\":[\"文章\"],\"TxE+Mj\":[\"1 條回覆\"],\"Tz0i8g\":[\"設定\"],\"U5v6Gh\":[\"編輯頁面\"],\"UDMjsP\":[\"快速操作\"],\"UGT5vp\":[\"保存設定\"],\"VUSy8D\":[\"Search failed. Please try again.\"],\"VhMDMg\":[\"更改密碼\"],\"WDcQq9\":[\"不公開\"],\"Weq9zb\":[\"一般設定\"],\"WmZ/rP\":[\"到路徑\"],\"Y+7JGK\":[\"創建頁面\"],\"ZQKLI1\":[\"危險區域\"],\"ZhhOwV\":[\"引用\"],\"aAIQg2\":[\"外觀\"],\"an5hVd\":[\"圖片\"],\"b+/jO6\":[\"301(永久)\"],\"bHYIks\":[\"登出\"],\"biOepV\":[\"← 返回首頁\"],\"cnGeoo\":[\"刪除\"],\"dEgA5A\":[\"取消\"],\"e6Jr7Q\":[\"← 返回收藏夾\"],\"ePK91l\":[\"編輯\"],\"eWLklq\":[\"引用\"],\"eneWvv\":[\"草稿\"],\"er8+x7\":[\"示範帳戶已預填。只需點擊登入。\"],\"f6e0Ry\":[\"文章\"],\"fG7BxZ\":[\"Upload images via the API: POST /api/upload with a file form field.\"],\"fttd2R\":[\"我的收藏\"],\"hG89Ed\":[\"圖片\"],\"hWOZIv\":[\"請輸入您的新密碼。\"],\"hXzOVo\":[\"下一頁\"],\"he3ygx\":[\"複製\"],\"iH8pgl\":[\"返回\"],\"ig4hg2\":[\"Let's set up your site.\"],\"jpctdh\":[\"查看\"],\"k1ifdL\":[\"處理中...\"],\"mTOYla\":[\"查看所有文章 →\"],\"n1ekoW\":[\"登入\"],\"oYPBa0\":[\"更新頁面\"],\"p2/GCq\":[\"確認密碼\"],\"pRhYH2\":[\"收藏中的帖子 (\",[\"count\"],\")\"],\"pZq3aX\":[\"上傳失敗。請再試一次。\"],\"qMyM2u\":[\"來源網址(選填)\"],\"r1MpXi\":[\"安靜\"],\"rFmBG3\":[\"顏色主題\"],\"rdUucN\":[\"預覽\"],\"rzNUSl\":[\"包含 1 則貼文的主題\"],\"sGajR7\":[\"線程開始\"],\"ssqvZi\":[\"保存個人資料\"],\"t/YqKh\":[\"移除\"],\"tfrt7B\":[\"未配置任何重定向。\"],\"tiq7kl\":[\"頁面 \",[\"page\"]],\"u2f7vd\":[\"網站描述\"],\"u3wRF+\":[\"已發佈\"],\"u6Hp4N\":[\"Markdown\"],\"uAQUqI\":[\"狀態\"],\"vERlcd\":[\"個人資料\"],\"vXIe7J\":[\"語言\"],\"vzU4k9\":[\"新收藏集\"],\"wEF6Ix\":[\"目的地路徑或 URL\"],\"wK4OTM\":[\"標題(選填)\"],\"wM5UXj\":[\"刪除媒體\"],\"wRR604\":[\"頁面\"],\"wja8aL\":[\"無標題\"],\"x+doid\":[\"圖片會自動優化:調整大小至最大 1920 像素,轉換為 WebP 格式,並去除元數據。\"],\"x0mzE0\":[\"創建你的第一篇帖子\"],\"x4RuFo\":[\"回到首頁\"],\"xYilR2\":[\"媒體\"],\"y28hnO\":[\"文章\"],\"yQ2kGp\":[\"載入更多\"],\"yjkELF\":[\"確認新密碼\"],\"yzF66j\":[\"連結\"],\"z8ajIE\":[\"找到 1 個結果\"],\"zH6KqE\":[\"找到 \",[\"count\"],\" 個結果\"]}")as Messages;
1
+ /*eslint-disable*/import type{Messages}from"@lingui/core";export const messages=JSON.parse("{\"+7Wr2a\":[\"Edit: \",[\"title\"]],\"+MACwa\":[\"尚未有任何收藏。\"],\"+bHzpy\":[\"顯示連結的文字\"],\"+owNNn\":[\"文章\"],\"+zy2Nq\":[\"類型\"],\"/0D1Xp\":[\"編輯收藏集\"],\"/Rj5P4\":[\"您的姓名\"],\"07Epll\":[\"這將為您的網站和儀表板設置主題。所有顏色主題都支持深色模式。\"],\"0JkyS7\":[\"建立您的第一個頁面\"],\"0a6MpL\":[\"新重定向\"],\"1CU1Td\":[\"網址安全識別碼(小寫、數字、連字符)\"],\"1DBGsz\":[\"筆記\"],\"1o+wgo\":[\"例如:The Verge,約翰·多伊\"],\"2N0qpv\":[\"文章標題...\"],\"2fUwEY\":[\"選擇媒體\"],\"2q/Q7x\":[\"可見性\"],\"2rJGtU\":[\"頁面標題...\"],\"3Yvsaz\":[\"302(臨時)\"],\"4/SFQS\":[\"查看網站\"],\"40TVQj\":[\"自訂路徑(選填)\"],\"4KzVT6\":[\"刪除頁面\"],\"4b3oEV\":[\"內容\"],\"4mDPGp\":[\"此頁面的 URL 路徑。使用小寫字母、數字和連字符。\"],\"6WdDG7\":[\"頁面\"],\"6YtxFj\":[\"名稱\"],\"7G4SBz\":[\"頁面內容(支持Markdown)...\"],\"7Mk+/h\":[\"更新收藏集\"],\"7Q1KKN\":[\"來源路徑\"],\"7aECQB\":[\"無效或已過期的連結\"],\"7nGhhM\":[\"你在想什麼?\"],\"7p5kLi\":[\"儀表板\"],\"7vhWI8\":[\"新密碼\"],\"87a/t/\":[\"標籤\"],\"8ZsakT\":[\"密碼\"],\"90Luob\":[[\"count\"],\" 條回覆\"],\"A1taO8\":[\"搜尋\"],\"AeXO77\":[\"帳戶\"],\"AyHO4m\":[\"這個收藏是關於什麼的?\"],\"B373X+\":[\"編輯文章\"],\"B495Gs\":[\"檔案館\"],\"BjF0Jv\":[\"僅限小寫字母、數字和連字符\"],\"D9Oea+\":[\"永久鏈接\"],\"DCKkhU\":[\"當前密碼\"],\"DHhJ7s\":[\"上一頁\"],\"DPfwMq\":[\"完成\"],\"DoJzLz\":[\"收藏夾\"],\"E80cJw\":[\"刪除此媒體將永久從存儲中移除它。\"],\"EEYbdt\":[\"發佈\"],\"EGwzOK\":[\"完成設置\"],\"EkH9pt\":[\"更新\"],\"FGrimz\":[\"新帖子\"],\"FkMol5\":[\"精選\"],\"Fxf4jq\":[\"描述(可選)\"],\"GA5A5H\":[\"刪除收藏夾\"],\"GX2VMa\":[\"建立您的管理員帳戶。\"],\"GbVAnd\":[\"此密碼重設連結無效或已過期。請生成一個新的連結。\"],\"GorKul\":[\"歡迎來到 Jant\"],\"GrZ6fH\":[\"新頁面\"],\"GxkJXS\":[\"上傳中...\"],\"HfyyXl\":[\"My Blog\"],\"HiETwV\":[\"安靜(正常)\"],\"Hzi9AA\":[\"未找到任何帖子。\"],\"I6gXOa\":[\"路徑\"],\"I8hDlV\":[\"至少需要 1 張圖片才能發佈圖片帖子。\"],\"IUwGEM\":[\"保存更改\"],\"IagCbF\":[\"網址\"],\"J4FNfC\":[\"此集合中沒有帖子。\"],\"JIBC/T\":[\"Supported formats: JPEG, PNG, GIF, WebP, SVG. Max size: 10MB.\"],\"Jed1wB\":[\"需要幫助嗎?請訪問<0>文檔</0>。\"],\"JiP4aa\":[\"已發佈的頁面可以通過其路徑訪問。草稿不可見。\"],\"K9NcLu\":[\"使用此 URL 將媒體嵌入到您的帖子中。\"],\"KbS2K9\":[\"重設密碼\"],\"KiJn9B\":[\"備註\"],\"KmGXnO\":[\"Are you sure you want to delete this post? This cannot be undone.\"],\"L85WcV\":[\"縮略名\"],\"LkvLQe\":[\"尚未有頁面。\"],\"M1RvTd\":[\"點擊圖片以查看完整大小\"],\"M8kJqa\":[\"草稿\"],\"M9xgHy\":[\"重定向\"],\"MHrjPM\":[\"標題\"],\"MWBOxm\":[\"收藏(可選)\"],\"MZbQHL\":[\"未找到結果。\"],\"Mhf/H/\":[\"建立重定向\"],\"MqghUt\":[\"搜尋帖子...\"],\"N40H+G\":[\"所有\"],\"O3oNi5\":[\"電子郵件\"],\"OCNZaU\":[\"重定向來源的路徑\"],\"ODiSoW\":[\"尚未有帖子。\"],\"ONWvwQ\":[\"上傳\"],\"Pbm2/N\":[\"創建收藏夾\"],\"QEbNBb\":[\"路徑(例如 /archive)或完整網址(例如 https://example.com)\"],\"RDjuBN\":[\"Setup\"],\"Rj01Fz\":[\"連結\"],\"RwGhWy\":[\"包含 \",[\"count\"],\" 則帖子的主題\"],\"SJmfuf\":[\"網站名稱\"],\"ST+lN2\":[\"尚未上傳任何媒體。\"],\"Tt5T6+\":[\"文章\"],\"TxE+Mj\":[\"1 條回覆\"],\"Tz0i8g\":[\"設定\"],\"U5v6Gh\":[\"編輯頁面\"],\"UDMjsP\":[\"快速操作\"],\"UGT5vp\":[\"保存設定\"],\"UxKoFf\":[\"導航\"],\"VUSy8D\":[\"Search failed. Please try again.\"],\"VhMDMg\":[\"更改密碼\"],\"WDcQq9\":[\"不公開\"],\"Weq9zb\":[\"一般設定\"],\"WmZ/rP\":[\"到路徑\"],\"Y+7JGK\":[\"創建頁面\"],\"Z3FXyt\":[\"載入中...\"],\"ZQKLI1\":[\"危險區域\"],\"ZhhOwV\":[\"引用\"],\"aAIQg2\":[\"外觀\"],\"aaGV/9\":[\"新連結\"],\"an5hVd\":[\"圖片\"],\"b+/jO6\":[\"301(永久)\"],\"bHYIks\":[\"登出\"],\"biOepV\":[\"← Back to home\"],\"cnGeoo\":[\"刪除\"],\"dEgA5A\":[\"取消\"],\"e6Jr7Q\":[\"← 返回收藏夾\"],\"ePK91l\":[\"編輯\"],\"eWLklq\":[\"引用\"],\"eneWvv\":[\"草稿\"],\"er8+x7\":[\"示範帳戶已預填。只需點擊登入。\"],\"f6e0Ry\":[\"文章\"],\"fG7BxZ\":[\"Upload images via the API: POST /api/upload with a file form field.\"],\"fttd2R\":[\"我的收藏\"],\"gDx5MG\":[\"編輯連結\"],\"hG89Ed\":[\"圖片\"],\"hWOZIv\":[\"請輸入您的新密碼。\"],\"hXzOVo\":[\"下一頁\"],\"he3ygx\":[\"複製\"],\"iH8pgl\":[\"返回\"],\"ig4hg2\":[\"Let's set up your site.\"],\"jpctdh\":[\"查看\"],\"k1ifdL\":[\"處理中...\"],\"kd7eBB\":[\"建立連結\"],\"mTOYla\":[\"View all posts →\"],\"n1ekoW\":[\"登入\"],\"oJFOZk\":[\"來源名稱(選填)\"],\"oYPBa0\":[\"更新頁面\"],\"p2/GCq\":[\"確認密碼\"],\"pRhYH2\":[\"收藏中的帖子 (\",[\"count\"],\")\"],\"pZq3aX\":[\"上傳失敗。請再試一次。\"],\"qMyM2u\":[\"來源網址(選填)\"],\"qiXmlF\":[\"添加媒體\"],\"r1MpXi\":[\"安靜\"],\"rFmBG3\":[\"顏色主題\"],\"rdUucN\":[\"預覽\"],\"rzNUSl\":[\"包含 1 則貼文的主題\"],\"sGajR7\":[\"線程開始\"],\"smzF8S\":[\"顯示 \",[\"remainingCount\"],\" 個更多 \",[\"0\"]],\"ssqvZi\":[\"保存個人資料\"],\"t/YqKh\":[\"移除\"],\"tfrt7B\":[\"未配置任何重定向。\"],\"tiq7kl\":[\"頁面 \",[\"page\"]],\"u2f7vd\":[\"網站描述\"],\"u3wRF+\":[\"已發佈\"],\"u6Hp4N\":[\"Markdown\"],\"uAQUqI\":[\"狀態\"],\"vERlcd\":[\"個人資料\"],\"vXIe7J\":[\"語言\"],\"vzU4k9\":[\"新收藏集\"],\"wEF6Ix\":[\"目的地路徑或 URL\"],\"wK4OTM\":[\"標題(選填)\"],\"wM5UXj\":[\"刪除媒體\"],\"wRR604\":[\"頁面\"],\"wdGjkd\":[\"未配置導航連結。\"],\"wja8aL\":[\"無標題\"],\"x+doid\":[\"圖片會自動優化:調整大小至最大 1920 像素,轉換為 WebP 格式,並去除元數據。\"],\"x0mzE0\":[\"創建你的第一篇帖子\"],\"x4RuFo\":[\"Back to home\"],\"xYilR2\":[\"媒體\"],\"y28hnO\":[\"文章\"],\"yQ2kGp\":[\"載入更多\"],\"yjkELF\":[\"確認新密碼\"],\"yzF66j\":[\"連結\"],\"z8ajIE\":[\"找到 1 個結果\"],\"zH6KqE\":[\"找到 \",[\"count\"],\" 個結果\"]}")as Messages;
package/src/index.ts CHANGED
@@ -17,18 +17,30 @@ export type {
17
17
  Bindings,
18
18
  Post,
19
19
  Media,
20
+ MediaAttachment,
21
+ PostWithMedia,
20
22
  Collection,
21
23
  PostCollection,
22
24
  Redirect,
23
25
  Setting,
26
+ NavigationLink,
24
27
  CreatePost,
25
28
  UpdatePost,
26
29
  JantConfig,
27
30
  JantTheme,
28
31
  ThemeComponents,
32
+ TimelineCardProps,
33
+ ThreadPreviewProps,
34
+ TimelineItemData,
35
+ TimelineFeedProps,
29
36
  } from "./types.js";
30
37
 
31
- export { POST_TYPES, VISIBILITY_LEVELS } from "./types.js";
38
+ export {
39
+ POST_TYPES,
40
+ VISIBILITY_LEVELS,
41
+ MAX_MEDIA_ATTACHMENTS,
42
+ POST_TYPE_MEDIA_RULES,
43
+ } from "./types.js";
32
44
 
33
45
  // Utilities (for theme authors)
34
46
  export * as time from "./lib/time.js";
@@ -7,9 +7,14 @@ import {
7
7
  UpdatePostSchema,
8
8
  parseFormData,
9
9
  parseFormDataOptional,
10
+ validateMediaForPostType,
10
11
  } from "../schemas.js";
11
12
  import { z } from "zod";
12
- import { POST_TYPES, VISIBILITY_LEVELS } from "../../types.js";
13
+ import {
14
+ POST_TYPES,
15
+ VISIBILITY_LEVELS,
16
+ MAX_MEDIA_ATTACHMENTS,
17
+ } from "../../types.js";
13
18
 
14
19
  describe("PostTypeSchema", () => {
15
20
  it("accepts all valid post types", () => {
@@ -145,6 +150,37 @@ describe("CreatePostSchema", () => {
145
150
  ).toThrow();
146
151
  });
147
152
 
153
+ it("accepts valid mediaIds", () => {
154
+ const result = CreatePostSchema.parse({
155
+ ...validPost,
156
+ mediaIds: ["id-1", "id-2"],
157
+ });
158
+ expect(result.mediaIds).toEqual(["id-1", "id-2"]);
159
+ });
160
+
161
+ it("accepts empty mediaIds array", () => {
162
+ const result = CreatePostSchema.parse({
163
+ ...validPost,
164
+ mediaIds: [],
165
+ });
166
+ expect(result.mediaIds).toEqual([]);
167
+ });
168
+
169
+ it("accepts omitted mediaIds", () => {
170
+ const result = CreatePostSchema.parse(validPost);
171
+ expect(result.mediaIds).toBeUndefined();
172
+ });
173
+
174
+ it("rejects mediaIds over MAX_MEDIA_ATTACHMENTS", () => {
175
+ const tooMany = Array.from(
176
+ { length: MAX_MEDIA_ATTACHMENTS + 1 },
177
+ (_, i) => `id-${i}`,
178
+ );
179
+ expect(() =>
180
+ CreatePostSchema.parse({ ...validPost, mediaIds: tooMany }),
181
+ ).toThrow();
182
+ });
183
+
148
184
  it("rejects missing required fields", () => {
149
185
  expect(() => CreatePostSchema.parse({})).toThrow();
150
186
  expect(() => CreatePostSchema.parse({ type: "note" })).toThrow();
@@ -218,3 +254,55 @@ describe("parseFormDataOptional", () => {
218
254
  expect(() => parseFormDataOptional(form, "type", PostTypeSchema)).toThrow();
219
255
  });
220
256
  });
257
+
258
+ describe("validateMediaForPostType", () => {
259
+ it("returns null for note with no media", () => {
260
+ expect(validateMediaForPostType("note", [])).toBeNull();
261
+ });
262
+
263
+ it("returns null for note with media", () => {
264
+ expect(validateMediaForPostType("note", ["id-1", "id-2"])).toBeNull();
265
+ });
266
+
267
+ it("returns null for article with media", () => {
268
+ expect(validateMediaForPostType("article", ["id-1"])).toBeNull();
269
+ });
270
+
271
+ it("returns null for image with at least 1 media", () => {
272
+ expect(validateMediaForPostType("image", ["id-1"])).toBeNull();
273
+ });
274
+
275
+ it("returns error for image with no media", () => {
276
+ const error = validateMediaForPostType("image", []);
277
+ expect(error).toBe("image posts require at least 1 media attachment");
278
+ });
279
+
280
+ it("returns null for link with 0 or 1 media", () => {
281
+ expect(validateMediaForPostType("link", [])).toBeNull();
282
+ expect(validateMediaForPostType("link", ["id-1"])).toBeNull();
283
+ });
284
+
285
+ it("returns error for link with more than 1 media", () => {
286
+ const error = validateMediaForPostType("link", ["id-1", "id-2"]);
287
+ expect(error).toBe("link posts allow at most 1 media attachment");
288
+ });
289
+
290
+ it("returns error for page with any media", () => {
291
+ const error = validateMediaForPostType("page", ["id-1"]);
292
+ expect(error).toBe("page posts do not allow media attachments");
293
+ });
294
+
295
+ it("returns null for page with no media", () => {
296
+ expect(validateMediaForPostType("page", [])).toBeNull();
297
+ });
298
+
299
+ it("returns null for quote with media", () => {
300
+ expect(validateMediaForPostType("quote", ["id-1", "id-2"])).toBeNull();
301
+ });
302
+
303
+ it("returns error when exceeding max for note", () => {
304
+ const tooMany = Array.from({ length: 21 }, (_, i) => `id-${i}`);
305
+ const error = validateMediaForPostType("note", tooMany);
306
+ expect(error).toBe("note posts allow at most 20 media attachments");
307
+ });
308
+ });
@@ -25,13 +25,25 @@ describe("dsRedirect", () => {
25
25
  expect(body).toContain("\\'");
26
26
  });
27
27
 
28
- it("merges additional headers", () => {
28
+ it("merges additional headers from plain object", () => {
29
29
  const res = dsRedirect("/dash", {
30
30
  headers: { "Set-Cookie": "session=abc" },
31
31
  });
32
32
  expect(res.headers.get("Set-Cookie")).toBe("session=abc");
33
33
  expect(res.headers.get("Content-Type")).toBe("text/html");
34
34
  });
35
+
36
+ it("merges additional headers from Headers instance", () => {
37
+ const headers = new Headers();
38
+ headers.append("set-cookie", "session=abc; Path=/; HttpOnly");
39
+ headers.append("set-cookie", "data=xyz; Path=/; Max-Age=300");
40
+ const res = dsRedirect("/dash", { headers });
41
+ const cookies = res.headers.getSetCookie();
42
+ expect(cookies).toHaveLength(2);
43
+ expect(cookies[0]).toBe("session=abc; Path=/; HttpOnly");
44
+ expect(cookies[1]).toBe("data=xyz; Path=/; Max-Age=300");
45
+ expect(res.headers.get("Content-Type")).toBe("text/html");
46
+ });
35
47
  });
36
48
 
37
49
  describe("dsToast", () => {
@@ -0,0 +1,107 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ resolveCardComponent,
4
+ resolveThreadPreview,
5
+ resolveTimelineFeed,
6
+ } from "../theme-components.js";
7
+ import type {
8
+ ThemeComponents,
9
+ TimelineCardProps,
10
+ ThreadPreviewProps,
11
+ TimelineFeedProps,
12
+ PostType,
13
+ } from "../../types.js";
14
+ import type { FC } from "hono/jsx";
15
+
16
+ // Create simple mock components for testing (avoids importing .tsx files with i18n)
17
+ const MockNoteCard: FC<TimelineCardProps> = () => null;
18
+ const MockArticleCard: FC<TimelineCardProps> = () => null;
19
+ const MockLinkCard: FC<TimelineCardProps> = () => null;
20
+ const MockQuoteCard: FC<TimelineCardProps> = () => null;
21
+ const MockImageCard: FC<TimelineCardProps> = () => null;
22
+ const MockThreadPreview: FC<ThreadPreviewProps> = () => null;
23
+ const MockTimelineFeed: FC<TimelineFeedProps> = () => null;
24
+
25
+ const DEFAULT_CARD_MAP: Record<PostType, FC<TimelineCardProps>> = {
26
+ note: MockNoteCard,
27
+ article: MockArticleCard,
28
+ link: MockLinkCard,
29
+ quote: MockQuoteCard,
30
+ image: MockImageCard,
31
+ page: MockNoteCard,
32
+ };
33
+
34
+ describe("theme-components", () => {
35
+ describe("resolveCardComponent", () => {
36
+ it("returns default NoteCard for note type", () => {
37
+ expect(resolveCardComponent("note", DEFAULT_CARD_MAP)).toBe(MockNoteCard);
38
+ });
39
+
40
+ it("returns default ArticleCard for article type", () => {
41
+ expect(resolveCardComponent("article", DEFAULT_CARD_MAP)).toBe(
42
+ MockArticleCard,
43
+ );
44
+ });
45
+
46
+ it("returns default LinkCard for link type", () => {
47
+ expect(resolveCardComponent("link", DEFAULT_CARD_MAP)).toBe(MockLinkCard);
48
+ });
49
+
50
+ it("returns default QuoteCard for quote type", () => {
51
+ expect(resolveCardComponent("quote", DEFAULT_CARD_MAP)).toBe(
52
+ MockQuoteCard,
53
+ );
54
+ });
55
+
56
+ it("returns default ImageCard for image type", () => {
57
+ expect(resolveCardComponent("image", DEFAULT_CARD_MAP)).toBe(
58
+ MockImageCard,
59
+ );
60
+ });
61
+
62
+ it("returns NoteCard as fallback for page type", () => {
63
+ expect(resolveCardComponent("page", DEFAULT_CARD_MAP)).toBe(MockNoteCard);
64
+ });
65
+
66
+ it("returns theme override when provided", () => {
67
+ const CustomNote: FC<TimelineCardProps> = () => null;
68
+ const overrides: ThemeComponents = { NoteCard: CustomNote };
69
+ expect(resolveCardComponent("note", DEFAULT_CARD_MAP, overrides)).toBe(
70
+ CustomNote,
71
+ );
72
+ });
73
+
74
+ it("returns default when theme has no override for type", () => {
75
+ const overrides: ThemeComponents = {};
76
+ expect(resolveCardComponent("article", DEFAULT_CARD_MAP, overrides)).toBe(
77
+ MockArticleCard,
78
+ );
79
+ });
80
+ });
81
+
82
+ describe("resolveThreadPreview", () => {
83
+ it("returns default ThreadPreview when no override", () => {
84
+ expect(resolveThreadPreview(MockThreadPreview)).toBe(MockThreadPreview);
85
+ });
86
+
87
+ it("returns theme override when provided", () => {
88
+ const Custom: FC<ThreadPreviewProps> = () => null;
89
+ expect(
90
+ resolveThreadPreview(MockThreadPreview, { ThreadPreview: Custom }),
91
+ ).toBe(Custom);
92
+ });
93
+ });
94
+
95
+ describe("resolveTimelineFeed", () => {
96
+ it("returns default TimelineFeed when no override", () => {
97
+ expect(resolveTimelineFeed(MockTimelineFeed)).toBe(MockTimelineFeed);
98
+ });
99
+
100
+ it("returns theme override when provided", () => {
101
+ const Custom: FC<TimelineFeedProps> = () => null;
102
+ expect(
103
+ resolveTimelineFeed(MockTimelineFeed, { TimelineFeed: Custom }),
104
+ ).toBe(Custom);
105
+ });
106
+ });
107
+ });
package/src/lib/image.ts CHANGED
@@ -85,12 +85,12 @@ export function getImageUrl(
85
85
  * @example
86
86
  * ```ts
87
87
  * // Without R2 public URL - uses UUID with extension
88
- * getMediaUrl("01902a9f-1a2b-7c3d-8e4f-5a6b7c8d9e0f", "uploads/file.webp");
88
+ * getMediaUrl("01902a9f-1a2b-7c3d-8e4f-5a6b7c8d9e0f", "media/2025/01/01902a9f-1a2b-7c3d-8e4f-5a6b7c8d9e0f.webp");
89
89
  * // Returns: "/media/01902a9f-1a2b-7c3d-8e4f-5a6b7c8d9e0f.webp"
90
90
  *
91
91
  * // With R2 public URL - uses direct CDN
92
- * getMediaUrl("01902a9f-1a2b-7c3d-8e4f-5a6b7c8d9e0f", "uploads/file.webp", "https://cdn.example.com");
93
- * // Returns: "https://cdn.example.com/uploads/file.webp"
92
+ * getMediaUrl("01902a9f-1a2b-7c3d-8e4f-5a6b7c8d9e0f", "media/2025/01/01902a9f-1a2b-7c3d-8e4f-5a6b7c8d9e0f.webp", "https://cdn.example.com");
93
+ * // Returns: "https://cdn.example.com/media/2025/01/01902a9f-1a2b-7c3d-8e4f-5a6b7c8d9e0f.webp"
94
94
  * ```
95
95
  */
96
96
  export function getMediaUrl(
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Media Helper Utilities
3
+ *
4
+ * Shared logic for building MediaAttachment maps from raw media data.
5
+ */
6
+
7
+ import type { Media, MediaAttachment } from "../types.js";
8
+ import { getMediaUrl, getImageUrl } from "./image.js";
9
+
10
+ /**
11
+ * Builds a map of post IDs to MediaAttachment arrays from raw media data.
12
+ *
13
+ * Transforms raw Media objects (with R2 keys) into MediaAttachment objects
14
+ * (with public URLs and preview URLs) suitable for rendering.
15
+ *
16
+ * @param rawMediaMap - Map of post IDs to raw Media arrays from the media service
17
+ * @param r2PublicUrl - Optional R2 public URL for direct CDN access
18
+ * @param imageTransformUrl - Optional image transformation service URL
19
+ * @returns Map of post IDs to MediaAttachment arrays
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const rawMediaMap = await services.media.getByPostIds(postIds);
24
+ * const mediaMap = buildMediaMap(rawMediaMap, c.env.R2_PUBLIC_URL, c.env.IMAGE_TRANSFORM_URL);
25
+ * ```
26
+ */
27
+ export function buildMediaMap(
28
+ rawMediaMap: Map<number, Media[]>,
29
+ r2PublicUrl?: string,
30
+ imageTransformUrl?: string,
31
+ ): Map<number, MediaAttachment[]> {
32
+ const mediaMap = new Map<number, MediaAttachment[]>();
33
+ for (const [postId, mediaList] of rawMediaMap) {
34
+ mediaMap.set(
35
+ postId,
36
+ mediaList.map((m) => ({
37
+ id: m.id,
38
+ url: getMediaUrl(m.id, m.r2Key, r2PublicUrl),
39
+ previewUrl: getImageUrl(
40
+ getMediaUrl(m.id, m.r2Key, r2PublicUrl),
41
+ imageTransformUrl,
42
+ { width: 400, quality: 80, format: "auto", fit: "cover" },
43
+ ),
44
+ alt: m.alt,
45
+ blurhash: m.blurhash,
46
+ width: m.width,
47
+ height: m.height,
48
+ position: m.position,
49
+ mimeType: m.mimeType,
50
+ })),
51
+ );
52
+ }
53
+ return mediaMap;
54
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Navigation Link Reorder
3
+ *
4
+ * Initializes SortableJS on the navigation links list in the dashboard.
5
+ * Auto-detects the list element and only activates when present.
6
+ */
7
+
8
+ import Sortable from "sortablejs";
9
+
10
+ const list = document.getElementById("nav-links-list");
11
+ if (list) {
12
+ Sortable.create(list, {
13
+ animation: 150,
14
+ handle: "[data-id]",
15
+ onEnd() {
16
+ const ids = [...list.querySelectorAll<HTMLElement>("[data-id]")].map(
17
+ (el) => Number(el.dataset.id),
18
+ );
19
+ fetch("/dash/navigation/reorder", {
20
+ method: "POST",
21
+ headers: { "Content-Type": "application/json" },
22
+ body: JSON.stringify({ ids }),
23
+ });
24
+ },
25
+ });
26
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Navigation Helper
3
+ *
4
+ * Provides shared data fetching for public page navigation.
5
+ */
6
+
7
+ import type { Context } from "hono";
8
+ import { getSiteName } from "./config.js";
9
+ import type { NavigationLink } from "../types.js";
10
+
11
+ /**
12
+ * Navigation data needed by SiteLayout
13
+ */
14
+ export interface NavigationData {
15
+ navigationLinks: NavigationLink[];
16
+ currentPath: string;
17
+ siteName: string;
18
+ }
19
+
20
+ /**
21
+ * Fetch navigation data for public pages.
22
+ *
23
+ * Ensures default links exist (Home, Archive, RSS) and returns
24
+ * the current path and site name alongside the links.
25
+ *
26
+ * @param c - Hono context
27
+ * @returns Navigation data for SiteLayout
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const navData = await getNavigationData(c);
32
+ * return c.html(
33
+ * <BaseLayout c={c}>
34
+ * <SiteLayout {...navData}>
35
+ * <MyContent />
36
+ * </SiteLayout>
37
+ * </BaseLayout>
38
+ * );
39
+ * ```
40
+ */
41
+ export async function getNavigationData(c: Context): Promise<NavigationData> {
42
+ const navigationLinks = await c.var.services.navigationLinks.ensureDefaults();
43
+ const currentPath = new URL(c.req.url).pathname;
44
+ const siteName = await getSiteName(c);
45
+ return { navigationLinks, currentPath, siteName };
46
+ }
@@ -9,7 +9,13 @@
9
9
  */
10
10
 
11
11
  import { z } from "zod";
12
- import { POST_TYPES, VISIBILITY_LEVELS } from "../types.js";
12
+ import {
13
+ POST_TYPES,
14
+ VISIBILITY_LEVELS,
15
+ MAX_MEDIA_ATTACHMENTS,
16
+ POST_TYPE_MEDIA_RULES,
17
+ } from "../types.js";
18
+ import type { PostType } from "../types.js";
13
19
 
14
20
  /**
15
21
  * Post type enum schema
@@ -46,6 +52,7 @@ export const CreatePostSchema = z.object({
46
52
  .or(z.literal("")),
47
53
  replyToId: z.string().optional(), // Sqid format
48
54
  publishedAt: z.number().int().positive().optional(),
55
+ mediaIds: z.array(z.string()).max(MAX_MEDIA_ATTACHMENTS).optional(),
49
56
  });
50
57
 
51
58
  /**
@@ -94,3 +101,42 @@ export function parseFormDataOptional<T>(
94
101
  }
95
102
  return schema.parse(value);
96
103
  }
104
+
105
+ /**
106
+ * Validates media attachment count against post type rules.
107
+ *
108
+ * @param type - The post type to validate against
109
+ * @param mediaIds - Array of media IDs to attach
110
+ * @returns null if valid, error string if invalid
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * const error = validateMediaForPostType("image", []);
115
+ * // Returns: "image posts require at least 1 media attachment"
116
+ * ```
117
+ */
118
+ export function validateMediaForPostType(
119
+ type: PostType,
120
+ mediaIds: string[],
121
+ ): string | null {
122
+ const rules = POST_TYPE_MEDIA_RULES[type];
123
+
124
+ if (rules === null) {
125
+ if (mediaIds.length > 0) {
126
+ return `${type} posts do not allow media attachments`;
127
+ }
128
+ return null;
129
+ }
130
+
131
+ const [min, max] = rules;
132
+
133
+ if (mediaIds.length < min) {
134
+ return `${type} posts require at least ${min} media attachment${min !== 1 ? "s" : ""}`;
135
+ }
136
+
137
+ if (mediaIds.length > max) {
138
+ return `${type} posts allow at most ${max} media attachment${max !== 1 ? "s" : ""}`;
139
+ }
140
+
141
+ return null;
142
+ }
package/src/lib/sse.ts CHANGED
@@ -299,7 +299,7 @@ export function sse(
299
299
  * Use instead of `sse()` when the only action is a redirect.
300
300
  *
301
301
  * @param url - The URL to redirect to
302
- * @param options - Optional extra headers (e.g. Set-Cookie for auth)
302
+ * @param options - Optional extra headers (accepts any `HeadersInit`)
303
303
  * @returns Response with text/html content-type
304
304
  *
305
305
  * @example
@@ -307,21 +307,20 @@ export function sse(
307
307
  * return dsRedirect("/dash/posts");
308
308
  *
309
309
  * // With cookie forwarding (for auth)
310
- * return dsRedirect("/dash", { headers: { "Set-Cookie": cookie } });
310
+ * return dsRedirect("/dash", { headers: authResponse.headers });
311
311
  * ```
312
312
  */
313
313
  export function dsRedirect(
314
314
  url: string,
315
- options?: { headers?: Record<string, string> },
315
+ options?: { headers?: Headers | Record<string, string> | string[][] },
316
316
  ): Response {
317
- return new Response(buildRedirectScript(url), {
318
- headers: {
319
- "Content-Type": "text/html",
320
- "Datastar-Mode": "append",
321
- "Datastar-Selector": "body",
322
- ...options?.headers,
323
- },
324
- });
317
+ const headers = options?.headers
318
+ ? new Headers(options.headers)
319
+ : new Headers();
320
+ headers.set("Content-Type", "text/html");
321
+ headers.set("Datastar-Mode", "append");
322
+ headers.set("Datastar-Selector", "body");
323
+ return new Response(buildRedirectScript(url), { headers });
325
324
  }
326
325
 
327
326
  /**
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Theme Component Resolution
3
+ *
4
+ * Resolves theme-overridable components, falling back to defaults.
5
+ */
6
+
7
+ import type { FC } from "hono/jsx";
8
+ import type {
9
+ PostType,
10
+ ThemeComponents,
11
+ TimelineCardProps,
12
+ ThreadPreviewProps,
13
+ TimelineFeedProps,
14
+ } from "../types.js";
15
+
16
+ const THEME_KEY_MAP: Record<PostType, keyof ThemeComponents> = {
17
+ note: "NoteCard",
18
+ article: "ArticleCard",
19
+ link: "LinkCard",
20
+ quote: "QuoteCard",
21
+ image: "ImageCard",
22
+ page: "NoteCard",
23
+ };
24
+
25
+ /**
26
+ * Resolves the card component for a given post type.
27
+ *
28
+ * Checks theme overrides first, then falls back to the provided default card component.
29
+ *
30
+ * @param type - The post type to resolve a card for
31
+ * @param defaults - Map of post type to default card component
32
+ * @param themeComponents - Optional theme component overrides
33
+ * @returns The resolved card component
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const Card = resolveCardComponent("article", DEFAULT_CARD_MAP, c.var.config.theme?.components);
38
+ * ```
39
+ */
40
+ export function resolveCardComponent(
41
+ type: PostType,
42
+ defaults: Record<PostType, FC<TimelineCardProps>>,
43
+ themeComponents?: ThemeComponents,
44
+ ): FC<TimelineCardProps> {
45
+ const key = THEME_KEY_MAP[type];
46
+ const override = themeComponents?.[key] as FC<TimelineCardProps> | undefined;
47
+ return override ?? defaults[type];
48
+ }
49
+
50
+ /**
51
+ * Resolves the ThreadPreview component.
52
+ *
53
+ * @param defaultComponent - The default ThreadPreview component
54
+ * @param themeComponents - Optional theme component overrides
55
+ * @returns The resolved ThreadPreview component
56
+ */
57
+ export function resolveThreadPreview(
58
+ defaultComponent: FC<ThreadPreviewProps>,
59
+ themeComponents?: ThemeComponents,
60
+ ): FC<ThreadPreviewProps> {
61
+ return themeComponents?.ThreadPreview ?? defaultComponent;
62
+ }
63
+
64
+ /**
65
+ * Resolves the TimelineFeed component.
66
+ *
67
+ * @param defaultComponent - The default TimelineFeed component
68
+ * @param themeComponents - Optional theme component overrides
69
+ * @returns The resolved TimelineFeed component
70
+ */
71
+ export function resolveTimelineFeed(
72
+ defaultComponent: FC<TimelineFeedProps>,
73
+ themeComponents?: ThemeComponents,
74
+ ): FC<TimelineFeedProps> {
75
+ return themeComponents?.TimelineFeed ?? defaultComponent;
76
+ }