@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.
- package/bin/commands/db/execute-file.js +1 -1
- package/bin/commands/db/export.js +1 -1
- package/bin/commands/migrate.js +4 -4
- package/bin/commands/posts/rebuild-html.js +1 -1
- package/bin/commands/reset-password.js +1 -1
- package/bin/commands/search/reindex.js +1 -1
- package/bin/commands/setup.js +4 -2
- package/bin/commands/site/export.js +3 -0
- package/bin/commands/site/import.js +178 -91
- package/bin/commands/site/pull-media.js +3 -2
- package/bin/commands/site/snapshot/export.js +3 -1
- package/bin/commands/site/snapshot/import.js +3 -2
- package/bin/commands/start.js +44 -0
- package/bin/commands/telegram/register-webhooks.js +1 -1
- package/bin/commands/uploads/cleanup.js +48 -9
- package/bin/jant.js +39 -4
- package/bin/lib/import-sources.js +151 -0
- package/bin/lib/node-env.js +14 -9
- package/bin/lib/runtime-target.js +1 -1
- package/bin/lib/site-pull-media.js +56 -4
- package/bin/lib/site-snapshot.js +39 -2
- package/bin/lib/sql-export.js +66 -10
- package/dist/{app-DIVtyB4m.js → app-jQI4OPRe.js} +5055 -4448
- package/dist/client/.vite/manifest.json +38 -38
- package/dist/client/_assets/chunks/{create-editor-B-m7X7S5.js → create-editor-5Y49x7h5.js} +2 -2
- package/dist/client/_assets/chunks/{footnote-rail-CmeoVtnU.js → footnote-rail-BJwswtVQ.js} +1 -1
- package/dist/client/_assets/chunks/{settings-paths-C-ZZBTau.js → settings-paths-h6RjIe3C.js} +2 -2
- package/dist/client/_assets/chunks/{slug-format-BcIsNKz-.js → slug-format-Dsi0e9Xn.js} +1 -1
- package/dist/client/_assets/chunks/{slugify-373citbs.js → slugify-DlHLyUHS.js} +1 -1
- package/dist/client/_assets/chunks/sortable-list-DYMcJrlS.js +2 -0
- package/dist/client/_assets/chunks/unsafe-svg-DxrzM_Gb.js +2 -0
- package/dist/client/_assets/client-52vQhZAv.js +296 -0
- package/dist/client/_assets/client-BaqmpPQ-.css +2 -0
- package/dist/client/_assets/{client-auth-BpkkKTsV.js → client-auth-BDcCR6u1.js} +2 -2
- package/dist/client/_assets/client-author-CGVvrNZ8.css +2 -0
- package/dist/client/_assets/{client-compose-C-DXzcFR.js → client-compose-CzEwT5qX.js} +4 -4
- package/dist/client/_assets/{client-manage-BfT7ht4M.js → client-manage-CF7x21L4.js} +37 -37
- package/dist/client/_assets/{client-settings-CGR_nZ78.js → client-settings-DIM44Zqh.js} +2 -2
- package/dist/{url-CKlGzvdN.js → constants-DEgyqWDl.js} +340 -1
- package/dist/index.d.ts +44 -0
- package/dist/index.js +33 -1
- package/dist/node.js +57 -13
- package/package.json +13 -18
- package/src/__tests__/api-docs.test.ts +168 -1
- package/src/__tests__/bin/import-sources.test.ts +85 -0
- package/src/__tests__/bin/uploads-cleanup.test.ts +66 -26
- package/src/__tests__/cli-commands.test.ts +40 -0
- package/src/__tests__/config-docs.test.ts +119 -16
- package/src/__tests__/custom-url-redirects.test.ts +108 -0
- package/src/__tests__/export-collection-custom-urls.test.ts +69 -0
- package/src/__tests__/export-docs.test.ts +113 -41
- package/src/__tests__/export-feed-ids.test.ts +1 -0
- package/src/__tests__/export-format-version.test.ts +88 -0
- package/src/__tests__/export-hugo-build.test.ts +139 -4
- package/src/__tests__/export-import-roundtrip.test.ts +2 -1
- package/src/__tests__/export-service.test.ts +42 -13
- package/src/__tests__/export-smart-collection.test.ts +1 -1
- package/src/__tests__/feed-docs.test.ts +287 -21
- package/src/__tests__/feed-reply-addresses.test.ts +100 -0
- package/src/__tests__/feeds-disabled.test.ts +98 -0
- package/src/__tests__/fixtures/export-format/1.json +76 -0
- package/src/__tests__/fixtures/export-format/2.json +80 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/README.md +130 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/2thjq/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/2u5e5/_index.md +35 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/0x4nv/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/faqyt/index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5kayp/_index.md +23 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5ynfs/_index.md +31 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5ynfs/hu597/index.md +21 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/_index.md +5 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +31 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +36 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/archive/_index.md +8 -0
- 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
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/bought-too-many-lemons-again/_index.md +37 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/city-walks/_index.md +12 -0
- 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
- 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
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/co344/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/collections/_index.md +5 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/current-tea-rotation/_index.md +34 -0
- 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
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/desk-but-better/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/e0kcg/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/egi3c/_index.md +24 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/evf9j/_index.md +152 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/featured/_index.md +8 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-basho/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-epictetus/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-marcus-aurelius/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-seneca/_index.md +26 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-thoreau/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/2cl6d/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/3zqv7/index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/5oxsv/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/_index.md +39 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gwob9/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/home-cooking/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/hz729/_index.md +24 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/inaturalist-ai-zi-ran-she-qu/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/j4v0q/_index.md +35 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k278t/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k4eee/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/a83qu/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/from-seneca-5hibo/index.md +21 -0
- 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
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/l2m7y/_index.md +29 -0
- 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
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/mynoise-for-rainy-afternoons/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/n09le/_index.md +23 -0
- 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
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/nts-archives-are-good-cleaning-music/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/c91j0/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/qyucy/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/wsgck/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +46 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/reading-notes/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/s4r3e/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/cxiu6/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/t77ms/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/the-soup-trick-i-always-forget/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/telk3/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/telk3/from-thoreau-pawt2/index.md +21 -0
- 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
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/tiny-projects/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/tong-wang-xing-fu-zhi-lu/_index.md +68 -0
- 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
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/useful-links/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/weekend-notes/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/what-i-actually-use-my-notebook-for/_index.md +52 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/data/jant.toml +124 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/hugo.toml +45 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/_redirects +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/40bc6cd1f12e-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q1hme4e8cmby77dn66yy.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q2w7e4e8cmc20036yh66.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q7d2e4e8cmdeqjmyafby.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q887e4e8cmdjssych7yh.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167sm0f6ct88qw5brtsgcw.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167tf8f6ct88r169s51j49.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167vaaf6ct88rbx5ztenwb.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167w51f6ct88rp19pybkw1.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167x0nf6ct88rzajb84tw3.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167xxbf6ct88s5t2300bjk.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167yq5f6ct88s9pjwt5fxg.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167zg4f6ct88sge8jp28ja.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/apple-touch-icon.png +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/custom.css +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/favicon.ico +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/wrangler.jsonc +24 -0
- package/src/__tests__/fixtures/releases/0.10.0/snapshot/db.sql +322 -0
- package/src/__tests__/fixtures/releases/0.10.0/snapshot/meta.json +11 -0
- package/src/__tests__/helpers/app.ts +6 -1
- package/src/__tests__/helpers/export-fixtures.ts +1 -0
- package/src/__tests__/import-refused-aliases.test.ts +98 -0
- package/src/__tests__/import-site-command.test.ts +73 -8
- package/src/__tests__/public-types.test.ts +64 -0
- package/src/__tests__/release-fixtures.test.ts +79 -24
- package/src/__tests__/release-version.test.ts +84 -0
- package/src/__tests__/site-pull-media.test.ts +48 -0
- package/src/__tests__/snapshot-tables.test.ts +37 -0
- package/src/__tests__/sql-export.test.ts +21 -1
- package/src/__tests__/stored-file-headers.test.ts +94 -0
- package/src/__tests__/template-deploy-workflow.test.ts +101 -0
- package/src/__tests__/theme-docs.test.ts +113 -24
- package/src/__tests__/toolchain-versions.test.ts +54 -0
- package/src/__tests__/trailing-slash-redirect.test.ts +61 -0
- package/src/__tests__/vite-config-graph.test.ts +98 -0
- package/src/app.tsx +89 -66
- package/src/client/__tests__/compose-bridge-image-upload.test.ts +1 -0
- package/src/client/__tests__/compose-bridge.test.ts +87 -0
- package/src/client/__tests__/compose-shortcuts.test.ts +4 -4
- package/src/client/__tests__/footnote-rail.test.ts +1 -1
- package/src/client/__tests__/lazy-entries.test.ts +1 -1
- package/src/client/__tests__/media-scroll-hint.test.ts +2 -2
- package/src/client/avatar-upload.ts +10 -10
- package/src/client/components/__tests__/jant-compose-dialog.test.ts +295 -4
- package/src/client/components/__tests__/jant-compose-editor.test.ts +34 -0
- package/src/client/components/__tests__/jant-settings-general.test.ts +0 -32
- package/src/client/components/compose-types.ts +14 -0
- package/src/client/components/jant-compose-dialog.ts +96 -41
- package/src/client/components/jant-compose-editor.ts +21 -4
- package/src/client/components/jant-config-editor.ts +4 -6
- package/src/client/components/jant-media-lightbox.ts +4 -4
- package/src/client/components/jant-settings-general.ts +0 -4
- package/src/client/components/nav-manager-types.ts +6 -5
- package/src/client/compose-bridge.ts +15 -4
- package/src/client/compose-launch.ts +4 -6
- package/src/client/compose-shortcuts.ts +1 -1
- package/src/client/footnote-rail.ts +1 -1
- package/src/client/lazy-entries.ts +1 -1
- package/src/client/media-scroll-hint.ts +2 -2
- package/src/client/tiptap/__tests__/markdown-clipboard.test.ts +55 -0
- package/src/client/tiptap/markdown-clipboard.ts +50 -2
- package/src/client/upload-session.ts +7 -6
- package/src/db/__tests__/backfill-external-redirects.test.ts +59 -0
- package/src/db/__tests__/backfill-featured-discover.test.ts +56 -0
- package/src/db/backfills/0007_restore_external_redirect_scheme.sql +20 -0
- package/src/db/backfills/0008_turn_off_featured_only_discover.sql +11 -0
- package/src/i18n/locales/public/en.po +46 -48
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +45 -46
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +45 -46
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +15 -29
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +15 -29
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +15 -29
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/index.ts +43 -2
- package/src/lib/__tests__/api-settings.test.ts +3 -3
- package/src/lib/__tests__/constants.test.ts +10 -0
- package/src/lib/__tests__/discover.test.ts +8 -9
- package/src/lib/__tests__/env-values.test.ts +125 -0
- package/src/lib/__tests__/feed-path.test.ts +29 -0
- package/src/lib/__tests__/feed.test.ts +50 -22
- package/src/lib/__tests__/filter-dimensions.test.ts +22 -8
- package/src/lib/__tests__/post-list-cursor.test.ts +0 -10
- package/src/lib/__tests__/rate-limit.test.ts +22 -7
- package/src/lib/__tests__/resolve-config.test.ts +5 -3
- package/src/lib/__tests__/schemas.test.ts +72 -23
- package/src/lib/__tests__/slugify.test.ts +9 -0
- package/src/lib/__tests__/startup-config.test.ts +12 -0
- package/src/lib/__tests__/storage-s3.test.ts +214 -0
- package/src/lib/__tests__/theme.test.ts +20 -1
- package/src/lib/__tests__/time.test.ts +56 -0
- package/src/lib/__tests__/timeline.test.ts +46 -0
- package/src/lib/__tests__/url-fetch.test.ts +65 -1
- package/src/lib/__tests__/url.test.ts +60 -1
- package/src/lib/api-nav-items.ts +16 -20
- package/src/lib/api-post-input.ts +34 -1
- package/src/lib/api-posts.ts +125 -23
- package/src/lib/api-public-posts.ts +28 -37
- package/src/lib/api-search.ts +49 -2
- package/src/lib/api-settings.ts +159 -54
- package/src/lib/api-threads.ts +34 -11
- package/src/lib/constants.ts +6 -0
- package/src/lib/discover.ts +7 -23
- package/src/lib/env-values.ts +140 -0
- package/src/lib/env.ts +203 -12
- package/src/lib/feed-path.ts +8 -2
- package/src/lib/feed-policy.ts +110 -7
- package/src/lib/feed.ts +69 -25
- package/src/lib/filter-dimensions.ts +17 -10
- package/src/lib/github-sync-site-config.ts +1 -0
- package/src/lib/hugo-markdown.ts +5 -6
- package/src/lib/navigation.ts +4 -1
- package/src/lib/post-list-cursor.ts +33 -29
- package/src/lib/public-storage.ts +43 -0
- package/src/lib/rate-limit.ts +31 -16
- package/src/lib/render.tsx +5 -0
- package/src/lib/resolve-config.ts +16 -19
- package/src/lib/schemas.ts +248 -180
- package/src/lib/slugify.ts +6 -1
- package/src/lib/sse.ts +1 -1
- package/src/lib/startup-config.ts +20 -1
- package/src/lib/theme.ts +8 -5
- package/src/lib/thread-fold.ts +6 -0
- package/src/lib/thread-query.ts +19 -24
- package/src/lib/time.ts +137 -17
- package/src/lib/timeline.ts +56 -13
- package/src/lib/url-fetch.ts +141 -40
- package/src/lib/url.ts +86 -1
- package/src/middleware/__tests__/auth.test.ts +27 -0
- package/src/middleware/__tests__/cors.test.ts +54 -0
- package/src/middleware/__tests__/cross-origin.test.ts +149 -0
- package/src/middleware/__tests__/public-content-access.test.ts +2 -42
- package/src/middleware/auth.ts +34 -3
- package/src/middleware/cors.ts +4 -4
- package/src/middleware/cross-origin.ts +124 -0
- package/src/middleware/error-handler.ts +7 -0
- package/src/middleware/public-content-access.ts +3 -26
- package/src/middleware/secure-headers.ts +8 -2
- package/src/node/__tests__/cli-migrate.test.ts +2 -2
- package/src/node/__tests__/cli-runtime-target.test.ts +13 -2
- package/src/node/__tests__/cli-site-snapshot.test.ts +57 -0
- package/src/node/__tests__/cli-snapshot-meta.test.ts +11 -1
- package/src/node/__tests__/cli-sql-export.test.ts +25 -1
- package/src/node/__tests__/cli-start.test.ts +66 -0
- package/src/node/__tests__/request-handler.test.ts +37 -0
- package/src/node/__tests__/runtime.test.ts +56 -1
- package/src/node/request-handler.ts +58 -5
- package/src/node/runtime.ts +37 -11
- package/src/preset.css +3 -3
- package/src/routes/__tests__/compose.test.ts +84 -0
- package/src/routes/api/__tests__/collections.test.ts +68 -0
- package/src/routes/api/__tests__/mcp.test.ts +164 -9
- package/src/routes/api/__tests__/media.test.ts +9 -1
- package/src/routes/api/__tests__/nav-items.test.ts +27 -1
- package/src/routes/api/__tests__/posts.test.ts +269 -78
- package/src/routes/api/__tests__/search.test.ts +17 -4
- package/src/routes/api/__tests__/settings.test.ts +119 -85
- package/src/routes/api/__tests__/telegram.test.ts +11 -6
- package/src/routes/api/__tests__/threads.test.ts +11 -0
- package/src/routes/api/__tests__/upload-response.test.ts +48 -0
- package/src/routes/api/__tests__/uploads.test.ts +35 -2
- package/src/routes/api/collections.ts +3 -3
- package/src/routes/api/custom-urls.ts +2 -1
- package/src/routes/api/export.ts +1 -0
- package/src/routes/api/internal/__tests__/post-body-html.test.ts +19 -0
- package/src/routes/api/internal/__tests__/uploads.test.ts +2 -0
- package/src/routes/api/internal/sites.ts +16 -4
- package/src/routes/api/mcp.ts +1 -0
- package/src/routes/api/media.ts +7 -8
- package/src/routes/api/nav-items.ts +2 -1
- package/src/routes/api/posts.ts +18 -24
- package/src/routes/api/public/__tests__/posts.test.ts +15 -0
- package/src/routes/api/public/__tests__/threads-collections.test.ts +12 -45
- package/src/routes/api/public/__tests__/threads.test.ts +41 -9
- package/src/routes/api/public/posts.ts +2 -2
- package/src/routes/api/public/threads.ts +16 -26
- package/src/routes/api/search.ts +7 -41
- package/src/routes/api/settings.ts +32 -28
- package/src/routes/api/smart-collections.ts +6 -1
- package/src/routes/api/threads.ts +25 -26
- package/src/routes/api/upload.ts +6 -21
- package/src/routes/api/uploads.ts +14 -20
- package/src/routes/auth/__tests__/dev.test.ts +16 -13
- package/src/routes/auth/__tests__/hosted-sso.test.ts +51 -0
- package/src/routes/auth/__tests__/setup-auth.test.ts +2 -0
- package/src/routes/auth/__tests__/setup-discover.test.ts +2 -0
- package/src/routes/auth/__tests__/setup-flow.test.ts +32 -0
- package/src/routes/auth/__tests__/setup-rate-limit.test.ts +72 -0
- package/src/routes/auth/__tests__/setup-steps.test.ts +2 -0
- package/src/routes/auth/__tests__/signin.test.ts +167 -2
- package/src/routes/auth/dev.ts +4 -6
- package/src/routes/auth/hosted-sso.ts +9 -6
- package/src/routes/auth/setup.tsx +35 -5
- package/src/routes/auth/signin.tsx +96 -1
- package/src/routes/compose.tsx +47 -47
- package/src/routes/dash/__tests__/settings-avatar.test.ts +59 -4
- package/src/routes/dash/__tests__/settings-demo-locks.test.ts +147 -0
- package/src/routes/dash/custom-urls.tsx +2 -0
- package/src/routes/dash/settings.tsx +79 -32
- package/src/routes/feed/__tests__/feed.test.ts +93 -3
- package/src/routes/feed/__tests__/sitemap.test.ts +42 -0
- package/src/routes/feed/feed.ts +128 -175
- package/src/routes/feed/sitemap.ts +9 -7
- package/src/routes/pages/__tests__/archive-years.test.ts +45 -0
- package/src/routes/pages/__tests__/collection-routing.test.ts +40 -0
- package/src/routes/pages/__tests__/collections.test.ts +3 -0
- package/src/routes/pages/__tests__/language-routing.test.ts +31 -0
- package/src/routes/pages/__tests__/post-page-round-trips.test.ts +34 -2
- package/src/routes/pages/__tests__/search.test.ts +5 -2
- package/src/routes/pages/__tests__/thread-gap.test.ts +207 -0
- package/src/routes/pages/archive.tsx +33 -94
- package/src/routes/pages/brand.tsx +1 -0
- package/src/routes/pages/collection.tsx +13 -84
- package/src/routes/pages/collections.tsx +2 -0
- package/src/routes/pages/featured.tsx +7 -2
- package/src/routes/pages/home.tsx +1 -0
- package/src/routes/pages/latest.tsx +6 -2
- package/src/routes/pages/new.tsx +1 -0
- package/src/routes/pages/page.tsx +73 -47
- package/src/routes/pages/search.tsx +5 -3
- package/src/routes/pages/smart-collection.tsx +11 -70
- package/src/routes/pages/subscribe.tsx +1 -0
- package/src/routes/pages/theme-sample.tsx +1 -0
- package/src/runtime/__tests__/readiness.test.ts +16 -0
- package/src/runtime/cloudflare.ts +2 -3
- package/src/runtime/index.ts +3 -1
- package/src/runtime/node.ts +3 -5
- package/src/runtime/readiness.ts +5 -0
- package/src/services/__tests__/auth.test.ts +115 -0
- package/src/services/__tests__/collection.test.ts +9 -0
- package/src/services/__tests__/github-sync-webhook.test.ts +78 -0
- package/src/services/__tests__/hosted-handoff.test.ts +208 -1
- package/src/services/__tests__/media.test.ts +47 -27
- package/src/services/__tests__/navigation.test.ts +67 -15
- package/src/services/__tests__/post.test.ts +103 -56
- package/src/services/__tests__/search.test.ts +38 -0
- package/src/services/__tests__/settings.test.ts +2 -14
- package/src/services/__tests__/smart-collection.test.ts +2 -2
- package/src/services/__tests__/telegram-ingest.test.ts +113 -0
- package/src/services/__tests__/thread.test.ts +26 -11
- package/src/services/auth.ts +36 -4
- package/src/services/collection.ts +46 -5
- package/src/services/custom-url.ts +11 -4
- package/src/services/export-theme/assets/client-site.css +1 -1
- package/src/services/export-theme/assets/client-site.js +2 -2
- package/src/services/export-theme/layouts/_default/baseof.html +1 -1
- package/src/services/export-theme/layouts/collection/single.html +1 -1
- package/src/services/export-theme/layouts/partials/featured-thread.html +8 -1
- package/src/services/export-theme/layouts/partials/head.html +1 -1
- package/src/services/export-theme/layouts/partials/media-gallery.html +6 -3
- package/src/services/export-theme/layouts/smart_collection/list.html +1 -1
- package/src/services/export-theme/styles/main.css +3 -3
- package/src/services/export.ts +68 -19
- package/src/services/github-sync.ts +10 -10
- package/src/services/hosted-handoff.ts +106 -6
- package/src/services/index.ts +3 -1
- package/src/services/language.ts +33 -0
- package/src/services/mcp.ts +176 -438
- package/src/services/media.ts +69 -21
- package/src/services/navigation.ts +19 -4
- package/src/services/path.ts +45 -3
- package/src/services/post.ts +329 -214
- package/src/services/search.ts +22 -3
- package/src/services/settings.ts +36 -3
- package/src/services/site-admin.ts +1 -0
- package/src/services/smart-collection.ts +10 -3
- package/src/services/telegram.ts +23 -6
- package/src/services/thread.ts +11 -3
- package/src/services/upload-session.ts +14 -15
- package/src/styles/components.css +2 -2
- package/src/styles/site-media.css +2 -2
- package/src/styles/tokens.css +19 -22
- package/src/styles/ui-author.css +73 -94
- package/src/styles/ui.css +62 -62
- package/src/types/app-context.ts +5 -1
- package/src/types/bindings.ts +11 -0
- package/src/types/config.ts +4 -4
- package/src/types/constants.ts +20 -0
- package/src/types/props.ts +34 -8
- package/src/types/views.ts +28 -13
- package/src/ui/color-themes.ts +6 -5
- package/src/ui/dash/settings/GeneralContent.tsx +0 -22
- package/src/ui/dash/settings/__tests__/GeneralContent.test.tsx +0 -21
- package/src/ui/feed/CuratedThreadPreview.tsx +7 -2
- package/src/ui/feed/LinkCard.tsx +1 -2
- package/src/ui/feed/NoteCard.tsx +1 -2
- package/src/ui/feed/QuoteCard.tsx +2 -2
- package/src/ui/feed/ThreadPreview.tsx +6 -6
- package/src/ui/feed/TimelineFeed.tsx +1 -7
- package/src/ui/feed/__tests__/thread-preview.test.ts +123 -10
- package/src/ui/feed/__tests__/timeline-cards.test.ts +18 -1
- package/src/ui/layouts/BaseLayout.tsx +5 -0
- package/src/ui/pages/ArchivePage.tsx +1 -1
- package/src/ui/pages/BrandPage.tsx +1 -1
- package/src/ui/pages/CollectionPage.tsx +0 -1
- package/src/ui/pages/CollectionsPage.tsx +2 -2
- package/src/ui/pages/ComposePage.tsx +1 -1
- package/src/ui/pages/FeaturedPage.tsx +1 -1
- package/src/ui/pages/HomePage.tsx +1 -1
- package/src/ui/pages/PostPage.tsx +1 -1
- package/src/ui/pages/SearchPage.tsx +1 -1
- package/src/ui/pages/SmartCollectionPage.tsx +2 -3
- package/src/ui/pages/SubscribePage.tsx +1 -1
- package/src/ui/pages/ThemeSamplePage.tsx +1 -1
- package/src/ui/shared/MediaGallery.tsx +1 -1
- package/src/vendor/datastar.js +9 -1956
- package/src/vendor/datastar.js.map +4 -4
- package/dist/client/_assets/chunks/sortable-list-BJyd-LXE.js +0 -2
- package/dist/client/_assets/chunks/unsafe-svg-DU_DNMy5.js +0 -2
- package/dist/client/_assets/client-D4AT9Iqr.js +0 -295
- package/dist/client/_assets/client-DRuw7XCt.css +0 -2
- package/dist/client/_assets/client-author-DQ8R-8KR.css +0 -2
package/src/services/post.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type SQL,
|
|
14
14
|
type SQLWrapper,
|
|
15
15
|
isNull,
|
|
16
|
+
ne,
|
|
16
17
|
desc,
|
|
17
18
|
inArray,
|
|
18
19
|
notInArray,
|
|
@@ -37,17 +38,19 @@ import {
|
|
|
37
38
|
buildRootActivityExpr,
|
|
38
39
|
rootActivityColumns,
|
|
39
40
|
} from "../db/thread-activity.js";
|
|
40
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
buildReaderVisibilityConditions,
|
|
43
|
+
type ReaderVisibilityOptions,
|
|
44
|
+
} from "../db/post-visibility.js";
|
|
41
45
|
import { createEntityId } from "../lib/ids.js";
|
|
42
46
|
import {
|
|
43
47
|
decodePostListCursor,
|
|
44
48
|
encodePostListCursor,
|
|
45
|
-
|
|
46
|
-
MISSING_LEGACY_CURSOR_MESSAGE,
|
|
49
|
+
THREAD_POSTS_SORT_MODE,
|
|
47
50
|
type PostListCursorKeyKind,
|
|
48
51
|
type PostListCursorValue,
|
|
49
52
|
} from "../lib/post-list-cursor.js";
|
|
50
|
-
import { now } from "../lib/time.js";
|
|
53
|
+
import { calendarPeriodsIn, now, type CalendarPeriod } from "../lib/time.js";
|
|
51
54
|
import { trimTiptapBody } from "../lib/tiptap-render.js";
|
|
52
55
|
import {
|
|
53
56
|
POST_BODY_HTML_VERSION,
|
|
@@ -61,7 +64,6 @@ import {
|
|
|
61
64
|
THREAD_TRAILING_REPLIES,
|
|
62
65
|
} from "../lib/thread-fold.js";
|
|
63
66
|
import { markdownToTiptapJson } from "../lib/markdown-to-tiptap.js";
|
|
64
|
-
import { tiptapJsonToMarkdown } from "../lib/tiptap-to-markdown.js";
|
|
65
67
|
import { generatePostSlug } from "../lib/slug.js";
|
|
66
68
|
import { getSlugValidationIssue } from "../lib/slug-format.js";
|
|
67
69
|
import { isReservedPath } from "../lib/constants.js";
|
|
@@ -229,10 +231,7 @@ export interface PostFilters {
|
|
|
229
231
|
|
|
230
232
|
/** Where `PostService.listPage` starts, and how much it returns. */
|
|
231
233
|
export interface PostListPageOptions {
|
|
232
|
-
/**
|
|
233
|
-
* `nextCursor` from the previous page; omit for the first. A bare post ID,
|
|
234
|
-
* the format earlier releases returned, is still accepted.
|
|
235
|
-
*/
|
|
234
|
+
/** `nextCursor` from the previous page; omit for the first. */
|
|
236
235
|
cursor?: string;
|
|
237
236
|
/** Posts per page. */
|
|
238
237
|
limit: number;
|
|
@@ -311,12 +310,6 @@ interface ListSort {
|
|
|
311
310
|
pinned: boolean;
|
|
312
311
|
}
|
|
313
312
|
|
|
314
|
-
/**
|
|
315
|
-
* The sort mode a cursor into one Thread's Posts records. Distinct from every
|
|
316
|
-
* `list()` and collection mode, so a position in one never resumes another.
|
|
317
|
-
*/
|
|
318
|
-
const THREAD_POSTS_SORT_MODE = "thread";
|
|
319
|
-
|
|
320
313
|
/** One term of a paged ORDER BY: `list()`'s, a collection's, or a Thread's. */
|
|
321
314
|
interface ListSortKey {
|
|
322
315
|
/** Selectable as a column, so a page's cursor is read from SQL. */
|
|
@@ -336,6 +329,19 @@ export interface FeaturedThreadTimelinePost {
|
|
|
336
329
|
position: number;
|
|
337
330
|
}
|
|
338
331
|
|
|
332
|
+
/**
|
|
333
|
+
* Where one gap in a curated Featured Thread points: the first Post of the run
|
|
334
|
+
* it hides, as `lib/thread-fold.ts` has every gap do. Only its address is
|
|
335
|
+
* loaded, since nothing renders it.
|
|
336
|
+
*/
|
|
337
|
+
export interface FeaturedThreadGapTarget {
|
|
338
|
+
id: string;
|
|
339
|
+
/** Canonical slug from `path_registry`. */
|
|
340
|
+
slug: string;
|
|
341
|
+
/** The shown Post the hidden run starts right after. */
|
|
342
|
+
afterPostId: string;
|
|
343
|
+
}
|
|
344
|
+
|
|
339
345
|
/**
|
|
340
346
|
* Bounded projection for one curated Featured Thread.
|
|
341
347
|
*
|
|
@@ -346,15 +352,8 @@ export interface FeaturedThreadTimelinePost {
|
|
|
346
352
|
export interface FeaturedThreadTimelineData {
|
|
347
353
|
posts: FeaturedThreadTimelinePost[];
|
|
348
354
|
featuredPostIds: string[];
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
export interface PostBodyContent {
|
|
352
|
-
id: string;
|
|
353
|
-
type: "post";
|
|
354
|
-
format: Format;
|
|
355
|
-
contentFormat: "markdown";
|
|
356
|
-
content: string;
|
|
357
|
-
chars: number;
|
|
355
|
+
/** The first hidden Post of each run between two shown ones. */
|
|
356
|
+
gapTargets: FeaturedThreadGapTarget[];
|
|
358
357
|
}
|
|
359
358
|
|
|
360
359
|
/** Minimal projection used by the sitemap renderer. */
|
|
@@ -432,7 +431,6 @@ export interface PostService {
|
|
|
432
431
|
* ```
|
|
433
432
|
*/
|
|
434
433
|
getWithCanonicalAlias(postId: string): Promise<PostWithCanonicalAlias | null>;
|
|
435
|
-
getBodyContent(id: string): Promise<PostBodyContent | null>;
|
|
436
434
|
getBySlug(slug: string): Promise<Post | null>;
|
|
437
435
|
suggestSlug(input: {
|
|
438
436
|
title?: string;
|
|
@@ -459,8 +457,8 @@ export interface PostService {
|
|
|
459
457
|
* @param filters - What to list and in which order, as for {@link list}
|
|
460
458
|
* @param page - The previous page's `nextCursor`, and the page size
|
|
461
459
|
* @returns The page's Posts and the cursor after them, `null` on the last page
|
|
462
|
-
* @throws {ValidationError} When the cursor can't be read
|
|
463
|
-
* another sort mode
|
|
460
|
+
* @throws {ValidationError} When the cursor can't be read or was taken in
|
|
461
|
+
* another sort mode
|
|
464
462
|
* @example
|
|
465
463
|
* ```ts
|
|
466
464
|
* const first = await posts.listPage({ status: "published" }, { limit: 20 });
|
|
@@ -539,9 +537,13 @@ export interface PostService {
|
|
|
539
537
|
filters: readonly PostFilters[],
|
|
540
538
|
base: PostFilters,
|
|
541
539
|
): Promise<PostFilterAggregate[]>;
|
|
542
|
-
/**
|
|
540
|
+
/**
|
|
541
|
+
* Count posts grouped by year-month (YYYY-MM) on the `sortBy` time axis, as
|
|
542
|
+
* the site's wall clock in `timeZone` reads it.
|
|
543
|
+
*/
|
|
543
544
|
countByYearMonth(
|
|
544
|
-
filters
|
|
545
|
+
filters: PostFilters,
|
|
546
|
+
timeZone: string,
|
|
545
547
|
): Promise<{ yearMonth: string; count: number }[]>;
|
|
546
548
|
create(data: CreatePost, summaryConfig?: SummaryConfig): Promise<Post>;
|
|
547
549
|
createWithAttachments(
|
|
@@ -591,10 +593,28 @@ export interface PostService {
|
|
|
591
593
|
*/
|
|
592
594
|
delete(id: string, deps?: PostDeleteDeps): Promise<boolean>;
|
|
593
595
|
/**
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
+
* Replace a saved Thread draft with a new version of it.
|
|
597
|
+
*
|
|
598
|
+
* The old Thread is deleted first, which releases its paths for the new
|
|
599
|
+
* one. Its attachments are detached before that, since the new version
|
|
600
|
+
* sends back the ones it keeps by ID; once the new Thread is created, the
|
|
601
|
+
* ones it left out are deleted.
|
|
602
|
+
*
|
|
603
|
+
* @param id - The old Thread's root, or the one post to replace
|
|
604
|
+
* @param items - The new version, as `createThreadWithAttachments` takes it
|
|
605
|
+
* @param deps - Media/storage dependencies
|
|
606
|
+
* @param summaryConfig - Optional summary extraction config
|
|
607
|
+
* @returns Ordered list of created posts; posts[0] is the root
|
|
596
608
|
*/
|
|
597
|
-
|
|
609
|
+
replaceThreadDraft(
|
|
610
|
+
id: string,
|
|
611
|
+
items: Array<{
|
|
612
|
+
data: CreatePost;
|
|
613
|
+
attachments: PostAttachmentInput[] | undefined;
|
|
614
|
+
}>,
|
|
615
|
+
deps: PostAttachmentDeps,
|
|
616
|
+
summaryConfig?: SummaryConfig,
|
|
617
|
+
): Promise<Post[]>;
|
|
598
618
|
/**
|
|
599
619
|
* Every Post in a Thread, drafts included, in Thread order: the root first,
|
|
600
620
|
* then replies by creation time, then ID.
|
|
@@ -606,17 +626,15 @@ export interface PostService {
|
|
|
606
626
|
*
|
|
607
627
|
* Pages like {@link listPage}. A new reply joins the end of the Thread, so a
|
|
608
628
|
* walk that is still going when one is published reaches it rather than
|
|
609
|
-
* skipping it.
|
|
610
|
-
*
|
|
611
|
-
* it, which is how a reader opens the run a fold hides.
|
|
629
|
+
* skipping it. A fold's gap carries a cursor from
|
|
630
|
+
* `encodeThreadPostsCursorAfter`, which opens the run the fold hides.
|
|
612
631
|
*
|
|
613
632
|
* @param threadId - The Thread root's ID
|
|
614
633
|
* @param options - Which Posts to include; `status` defaults to `published`
|
|
615
|
-
* @param page - The previous page's `nextCursor
|
|
616
|
-
* size
|
|
634
|
+
* @param page - The previous page's `nextCursor`, and the page size
|
|
617
635
|
* @returns The page's Posts and the cursor after them, `null` on the last page
|
|
618
|
-
* @throws {ValidationError} When the cursor can't be read
|
|
619
|
-
* another order
|
|
636
|
+
* @throws {ValidationError} When the cursor can't be read or was taken in
|
|
637
|
+
* another order
|
|
620
638
|
* @example
|
|
621
639
|
* ```ts
|
|
622
640
|
* const first = await posts.listThreadPostsPage(root.id, {}, { limit: 100 });
|
|
@@ -698,13 +716,27 @@ export interface PostService {
|
|
|
698
716
|
/**
|
|
699
717
|
* List the Thread roots that are translations of the given Post, excluding
|
|
700
718
|
* the Post itself. Empty when it belongs to no translation group.
|
|
719
|
+
*
|
|
720
|
+
* @param postId - The Post whose translations to list
|
|
721
|
+
* @param reader - What the audience may see. Omit it for the author's view,
|
|
722
|
+
* which includes drafts and private translations.
|
|
701
723
|
*/
|
|
702
|
-
listTranslations(
|
|
724
|
+
listTranslations(
|
|
725
|
+
postId: string,
|
|
726
|
+
reader?: ReaderVisibilityOptions,
|
|
727
|
+
): Promise<Post[]>;
|
|
703
728
|
/**
|
|
704
729
|
* List translations for many Thread roots in one round trip, keyed by the
|
|
705
|
-
* root ID that was asked about. Roots with no group
|
|
730
|
+
* root ID that was asked about. Roots with no group, or none the audience
|
|
731
|
+
* may see, are omitted.
|
|
732
|
+
*
|
|
733
|
+
* @param postIds - Thread roots to look up
|
|
734
|
+
* @param reader - What the audience may see. Omit it for the author's view.
|
|
706
735
|
*/
|
|
707
|
-
getTranslationsMap(
|
|
736
|
+
getTranslationsMap(
|
|
737
|
+
postIds: string[],
|
|
738
|
+
reader?: ReaderVisibilityOptions,
|
|
739
|
+
): Promise<Map<string, Post[]>>;
|
|
708
740
|
/**
|
|
709
741
|
* Find published Thread roots this Post could be linked to as a translation.
|
|
710
742
|
*
|
|
@@ -826,8 +858,8 @@ export interface PostService {
|
|
|
826
858
|
* @param page - The previous page's `nextCursor`, and the page size
|
|
827
859
|
* @returns The page's Thread roots and the cursor after them, `null` on the
|
|
828
860
|
* last page
|
|
829
|
-
* @throws {ValidationError} When the cursor can't be read
|
|
830
|
-
* another order
|
|
861
|
+
* @throws {ValidationError} When the cursor can't be read or was taken in
|
|
862
|
+
* another order
|
|
831
863
|
* @example
|
|
832
864
|
* ```ts
|
|
833
865
|
* const first = await posts.listCollectionThreadRootPage(
|
|
@@ -860,8 +892,11 @@ export interface PostService {
|
|
|
860
892
|
rootIds: string[],
|
|
861
893
|
options?: Pick<PostFilters, "publishedBefore">,
|
|
862
894
|
): Promise<Map<string, Post[]>>;
|
|
863
|
-
/**
|
|
864
|
-
|
|
895
|
+
/**
|
|
896
|
+
* Get distinct years with posts, bucketed on the `sortBy` time axis as the
|
|
897
|
+
* site's wall clock in `timeZone` reads it.
|
|
898
|
+
*/
|
|
899
|
+
getDistinctYears(filters: PostFilters, timeZone: string): Promise<number[]>;
|
|
865
900
|
/**
|
|
866
901
|
* For each Thread ID, resolve the Post that currently ends the chain: the
|
|
867
902
|
* last in Thread order, so the root only while it has no replies.
|
|
@@ -1176,6 +1211,7 @@ export function createPostService(
|
|
|
1176
1211
|
* cursor. The one definition both read, so a page of a Thread and the
|
|
1177
1212
|
* Thread page itself cannot order its posts differently.
|
|
1178
1213
|
*/
|
|
1214
|
+
/** Thread order; `encodeThreadPostsCursorAfter` writes the same tuple. */
|
|
1179
1215
|
function threadSortKeys(): ListSortKey[] {
|
|
1180
1216
|
return [
|
|
1181
1217
|
{
|
|
@@ -1194,16 +1230,58 @@ export function createPostService(
|
|
|
1194
1230
|
];
|
|
1195
1231
|
}
|
|
1196
1232
|
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1233
|
+
/**
|
|
1234
|
+
* The calendar periods, on the site's wall clock, that the posts matching
|
|
1235
|
+
* `filters` fall in, with the time axis and condition that select them.
|
|
1236
|
+
* `null` when no post matches.
|
|
1237
|
+
*
|
|
1238
|
+
* Neither SQLite nor D1 knows IANA time zones, so the period boundaries are
|
|
1239
|
+
* worked out here from the earliest and latest matching post, and the query
|
|
1240
|
+
* sorts each row into one by comparing against them.
|
|
1241
|
+
*/
|
|
1242
|
+
async function calendarPeriodsOf(
|
|
1243
|
+
filters: PostFilters,
|
|
1244
|
+
unit: "year" | "month",
|
|
1245
|
+
timeZone: string,
|
|
1246
|
+
) {
|
|
1247
|
+
const axis = timeAxisColumn(filters);
|
|
1248
|
+
const where = and(...buildFilterConditions(filters), isNotNull(axis));
|
|
1249
|
+
const [span] = await db
|
|
1250
|
+
.select({
|
|
1251
|
+
from: sql<number | null>`min(${axis})`,
|
|
1252
|
+
to: sql<number | null>`max(${axis})`,
|
|
1253
|
+
})
|
|
1254
|
+
.from(posts)
|
|
1255
|
+
.where(where);
|
|
1256
|
+
if (span?.from == null || span.to == null) return null;
|
|
1257
|
+
const periods = calendarPeriodsIn(
|
|
1258
|
+
Number(span.from),
|
|
1259
|
+
Number(span.to),
|
|
1260
|
+
unit,
|
|
1261
|
+
timeZone,
|
|
1262
|
+
);
|
|
1263
|
+
return { expr: buildPeriodExpr(axis, periods), where };
|
|
1201
1264
|
}
|
|
1202
1265
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1266
|
+
/**
|
|
1267
|
+
* A column's period key: the latest of `periods` (oldest first, the first
|
|
1268
|
+
* beginning at or before every value) that begins at or before it. Every
|
|
1269
|
+
* branch reads the column, even with one period: Postgres refuses to group
|
|
1270
|
+
* or order by a bare constant. Boundaries and keys are generated digits,
|
|
1271
|
+
* written as literals because D1 takes at most 100 bound parameters and a
|
|
1272
|
+
* long archive has more month boundaries than that.
|
|
1273
|
+
*/
|
|
1274
|
+
function buildPeriodExpr(
|
|
1275
|
+
column: SQLWrapper,
|
|
1276
|
+
periods: readonly CalendarPeriod[],
|
|
1277
|
+
): SQL<string> {
|
|
1278
|
+
const branches = [...periods]
|
|
1279
|
+
.reverse()
|
|
1280
|
+
.map(
|
|
1281
|
+
(period) =>
|
|
1282
|
+
sql`WHEN ${column} >= ${sql.raw(String(period.start))} THEN ${sql.raw(`'${period.key}'`)}`,
|
|
1283
|
+
);
|
|
1284
|
+
return sql<string>`CASE ${sql.join(branches, sql` `)} END`;
|
|
1207
1285
|
}
|
|
1208
1286
|
|
|
1209
1287
|
/** Check if a slug is available (not used by posts or path_registry) */
|
|
@@ -1762,47 +1840,17 @@ export function createPostService(
|
|
|
1762
1840
|
|
|
1763
1841
|
/**
|
|
1764
1842
|
* The position a cursor names, as the tuple of sort-key values after which
|
|
1765
|
-
* the page starts.
|
|
1766
|
-
*
|
|
1767
|
-
* A bare post ID, the cursor earlier releases returned, is looked up — but
|
|
1768
|
-
* only among Posts the caller could have been shown: the request's status,
|
|
1769
|
-
* and nothing private when the request excludes it. A deleted Post, a draft,
|
|
1770
|
-
* and a private Post all get the same rejection, so the lookup can't be used
|
|
1771
|
-
* to learn whether a Post exists or when it was published. Its values come
|
|
1772
|
-
* from the same key expressions as the ORDER BY.
|
|
1843
|
+
* the page starts. The cursor must come from a list in the same order.
|
|
1773
1844
|
*/
|
|
1774
|
-
|
|
1845
|
+
function resolveListCursor(
|
|
1775
1846
|
cursor: string,
|
|
1776
1847
|
sort: ListSort,
|
|
1777
1848
|
keys: readonly ListSortKey[],
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
kinds: keys.map((key) => key.kind),
|
|
1784
|
-
});
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
|
-
const rows = await db
|
|
1788
|
-
.select(listSortKeyFields(keys))
|
|
1789
|
-
.from(posts)
|
|
1790
|
-
.where(
|
|
1791
|
-
and(
|
|
1792
|
-
eq(posts.siteId, siteId),
|
|
1793
|
-
eq(posts.id, cursor),
|
|
1794
|
-
...buildReaderVisibilityConditions(posts, siteId, {
|
|
1795
|
-
status: filters.status,
|
|
1796
|
-
excludePrivate: filters.excludePrivate,
|
|
1797
|
-
}),
|
|
1798
|
-
),
|
|
1799
|
-
)
|
|
1800
|
-
.limit(1);
|
|
1801
|
-
const row = rows[0];
|
|
1802
|
-
if (!row) {
|
|
1803
|
-
throw new ValidationError(MISSING_LEGACY_CURSOR_MESSAGE);
|
|
1804
|
-
}
|
|
1805
|
-
return readListSortKeyValues(keys, row);
|
|
1849
|
+
): PostListCursorValue[] {
|
|
1850
|
+
return decodePostListCursor(cursor, {
|
|
1851
|
+
mode: listSortMode(sort),
|
|
1852
|
+
kinds: keys.map((key) => key.kind),
|
|
1853
|
+
});
|
|
1806
1854
|
}
|
|
1807
1855
|
|
|
1808
1856
|
function toPost(
|
|
@@ -2188,33 +2236,15 @@ export function createPostService(
|
|
|
2188
2236
|
/**
|
|
2189
2237
|
* The position a collection cursor names, as the tuple of sort-key values
|
|
2190
2238
|
* after which the page starts.
|
|
2191
|
-
*
|
|
2192
|
-
* A bare root ID, the cursor earlier releases returned, is looked up in the
|
|
2193
|
-
* request's own `sortedThreads`, so only among Threads this request could
|
|
2194
|
-
* list. A Thread that is gone, private, a draft, or no longer in the
|
|
2195
|
-
* collection gets the same rejection as an ID that never existed.
|
|
2196
2239
|
*/
|
|
2197
|
-
|
|
2240
|
+
function resolveCollectionThreadCursor(
|
|
2198
2241
|
cursor: string,
|
|
2199
2242
|
sort: ReturnType<typeof buildCollectionThreadSort>,
|
|
2200
|
-
):
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
});
|
|
2206
|
-
}
|
|
2207
|
-
|
|
2208
|
-
const rows = await db
|
|
2209
|
-
.select(listSortKeyFields(sort.keys))
|
|
2210
|
-
.from(sort.sortedThreads)
|
|
2211
|
-
.where(eq(sort.sortedThreads.threadId, cursor))
|
|
2212
|
-
.limit(1);
|
|
2213
|
-
const row = rows[0];
|
|
2214
|
-
if (!row) {
|
|
2215
|
-
throw new ValidationError(MISSING_LEGACY_CURSOR_MESSAGE);
|
|
2216
|
-
}
|
|
2217
|
-
return readListSortKeyValues(sort.keys, row);
|
|
2243
|
+
): PostListCursorValue[] {
|
|
2244
|
+
return decodePostListCursor(cursor, {
|
|
2245
|
+
mode: sort.mode,
|
|
2246
|
+
kinds: sort.keys.map((key) => key.kind),
|
|
2247
|
+
});
|
|
2218
2248
|
}
|
|
2219
2249
|
|
|
2220
2250
|
function isMediaAttachmentInput(
|
|
@@ -2223,9 +2253,19 @@ export function createPostService(
|
|
|
2223
2253
|
return attachment.type === "media";
|
|
2224
2254
|
}
|
|
2225
2255
|
|
|
2256
|
+
/** IDs of the uploaded media that attachment inputs reference. */
|
|
2257
|
+
function referencedMediaIds(
|
|
2258
|
+
attachments: PostAttachmentInput[] | undefined,
|
|
2259
|
+
): string[] {
|
|
2260
|
+
return (attachments ?? [])
|
|
2261
|
+
.filter(isMediaAttachmentInput)
|
|
2262
|
+
.map((attachment) => attachment.mediaId);
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2226
2265
|
async function createAttachmentMediaIds(
|
|
2227
2266
|
attachments: PostAttachmentInput[],
|
|
2228
2267
|
deps: PostAttachmentDeps,
|
|
2268
|
+
postId?: string,
|
|
2229
2269
|
) {
|
|
2230
2270
|
if (attachments.length > MAX_MEDIA_ATTACHMENTS) {
|
|
2231
2271
|
throw new ValidationError(
|
|
@@ -2235,11 +2275,7 @@ export function createPostService(
|
|
|
2235
2275
|
|
|
2236
2276
|
const orderedMediaIds: string[] = [];
|
|
2237
2277
|
const createdTextMediaIds: string[] = [];
|
|
2238
|
-
|
|
2239
|
-
.filter(isMediaAttachmentInput)
|
|
2240
|
-
.map((attachment) => attachment.mediaId);
|
|
2241
|
-
|
|
2242
|
-
await deps.media.validateIds(referencedMediaIds);
|
|
2278
|
+
await deps.media.validateIds(referencedMediaIds(attachments), postId);
|
|
2243
2279
|
|
|
2244
2280
|
try {
|
|
2245
2281
|
for (const attachment of attachments) {
|
|
@@ -2388,10 +2424,13 @@ export function createPostService(
|
|
|
2388
2424
|
slug = path.path;
|
|
2389
2425
|
continue;
|
|
2390
2426
|
}
|
|
2391
|
-
// Rows arrive oldest first,
|
|
2392
|
-
//
|
|
2393
|
-
//
|
|
2394
|
-
|
|
2427
|
+
// Rows arrive oldest first, and the oldest alias is the post's
|
|
2428
|
+
// address, as feeds, the sitemap, and the export name it: a second
|
|
2429
|
+
// custom URL is another way in, not a new identity. Ties within a
|
|
2430
|
+
// second fall to the lower id, not to the storage engine's order.
|
|
2431
|
+
if (path.kind === "alias" && canonicalAlias === null) {
|
|
2432
|
+
canonicalAlias = `/${path.path}`;
|
|
2433
|
+
}
|
|
2395
2434
|
}
|
|
2396
2435
|
|
|
2397
2436
|
// A Post with no slug row has no address, which is what `hydratePost`
|
|
@@ -2402,20 +2441,6 @@ export function createPostService(
|
|
|
2402
2441
|
return post ? { post, canonicalAlias } : null;
|
|
2403
2442
|
},
|
|
2404
2443
|
|
|
2405
|
-
async getBodyContent(id) {
|
|
2406
|
-
const post = await this.getById(id);
|
|
2407
|
-
if (!post) return null;
|
|
2408
|
-
|
|
2409
|
-
return {
|
|
2410
|
-
id: post.id,
|
|
2411
|
-
type: "post",
|
|
2412
|
-
format: post.format,
|
|
2413
|
-
contentFormat: "markdown",
|
|
2414
|
-
content: post.body ? tiptapJsonToMarkdown(post.body) : "",
|
|
2415
|
-
chars: post.bodyText?.length ?? 0,
|
|
2416
|
-
};
|
|
2417
|
-
},
|
|
2418
|
-
|
|
2419
2444
|
async getBySlug(slug) {
|
|
2420
2445
|
const resolved = await resolvedPaths.resolve(slug);
|
|
2421
2446
|
if (!resolved || resolved.kind !== "slug" || !resolved.postId) {
|
|
@@ -2480,10 +2505,7 @@ export function createPostService(
|
|
|
2480
2505
|
// `?cursor=` before it has one keeps working.
|
|
2481
2506
|
if (cursor) {
|
|
2482
2507
|
conditions.push(
|
|
2483
|
-
buildListKeysetCondition(
|
|
2484
|
-
keys,
|
|
2485
|
-
await resolveListCursor(cursor, sort, keys, filters),
|
|
2486
|
-
),
|
|
2508
|
+
buildListKeysetCondition(keys, resolveListCursor(cursor, sort, keys)),
|
|
2487
2509
|
);
|
|
2488
2510
|
}
|
|
2489
2511
|
|
|
@@ -2696,20 +2718,19 @@ export function createPostService(
|
|
|
2696
2718
|
return rows.length;
|
|
2697
2719
|
},
|
|
2698
2720
|
|
|
2699
|
-
async countByYearMonth(filters
|
|
2700
|
-
const
|
|
2701
|
-
|
|
2702
|
-
const publishedYearMonthExpr = buildYearMonthExpr(axis);
|
|
2721
|
+
async countByYearMonth(filters, timeZone) {
|
|
2722
|
+
const months = await calendarPeriodsOf(filters, "month", timeZone);
|
|
2723
|
+
if (!months) return [];
|
|
2703
2724
|
|
|
2704
2725
|
return db
|
|
2705
2726
|
.select({
|
|
2706
|
-
yearMonth:
|
|
2727
|
+
yearMonth: months.expr.as("year_month"),
|
|
2707
2728
|
count: sql<number>`CAST(count(*) AS INTEGER)`.as("count"),
|
|
2708
2729
|
})
|
|
2709
2730
|
.from(posts)
|
|
2710
|
-
.where(
|
|
2711
|
-
.groupBy(
|
|
2712
|
-
.orderBy(desc(
|
|
2731
|
+
.where(months.where)
|
|
2732
|
+
.groupBy(months.expr)
|
|
2733
|
+
.orderBy(desc(months.expr));
|
|
2713
2734
|
},
|
|
2714
2735
|
|
|
2715
2736
|
async create(data, summaryConfig) {
|
|
@@ -3325,8 +3346,23 @@ export function createPostService(
|
|
|
3325
3346
|
);
|
|
3326
3347
|
created.push(post);
|
|
3327
3348
|
} catch (error) {
|
|
3328
|
-
//
|
|
3349
|
+
// Roll back the posts created so far, in reverse order. Uploads they
|
|
3350
|
+
// reference by ID are detached first rather than deleted with them:
|
|
3351
|
+
// the composer keeps those in its local draft, and a retry attaches
|
|
3352
|
+
// them again.
|
|
3353
|
+
const uploadIds = new Set(
|
|
3354
|
+
items.flatMap((entry) => referencedMediaIds(entry.attachments)),
|
|
3355
|
+
);
|
|
3329
3356
|
for (const p of [...created].reverse()) {
|
|
3357
|
+
const attached = await deps.media.getByPostId(p.id).catch(() => []);
|
|
3358
|
+
await deps.media
|
|
3359
|
+
.attachToPost(
|
|
3360
|
+
p.id,
|
|
3361
|
+
attached
|
|
3362
|
+
.filter((item) => !uploadIds.has(item.id))
|
|
3363
|
+
.map((item) => item.id),
|
|
3364
|
+
)
|
|
3365
|
+
.catch(() => undefined);
|
|
3330
3366
|
await this.delete(p.id, {
|
|
3331
3367
|
media: deps.media,
|
|
3332
3368
|
storage: deps.storage,
|
|
@@ -3857,7 +3893,7 @@ export function createPostService(
|
|
|
3857
3893
|
]),
|
|
3858
3894
|
);
|
|
3859
3895
|
const { orderedMediaIds, createdTextMediaIds } =
|
|
3860
|
-
await createAttachmentMediaIds(attachments, deps);
|
|
3896
|
+
await createAttachmentMediaIds(attachments, deps, id);
|
|
3861
3897
|
const post = await this.update(id, data, summaryConfig);
|
|
3862
3898
|
|
|
3863
3899
|
if (!post) {
|
|
@@ -3994,8 +4030,41 @@ export function createPostService(
|
|
|
3994
4030
|
return true;
|
|
3995
4031
|
},
|
|
3996
4032
|
|
|
3997
|
-
async
|
|
3998
|
-
|
|
4033
|
+
async replaceThreadDraft(id, items, deps, summaryConfig) {
|
|
4034
|
+
const existing = await this.getById(id);
|
|
4035
|
+
const oldPosts = !existing
|
|
4036
|
+
? []
|
|
4037
|
+
: isThreadReply(existing)
|
|
4038
|
+
? [existing]
|
|
4039
|
+
: await this.getThread(id);
|
|
4040
|
+
const oldMedia = [
|
|
4041
|
+
...(
|
|
4042
|
+
await deps.media.getByPostIds(oldPosts.map((post) => post.id))
|
|
4043
|
+
).values(),
|
|
4044
|
+
].flat();
|
|
4045
|
+
for (const post of oldPosts) {
|
|
4046
|
+
await deps.media.detachFromPost(post.id);
|
|
4047
|
+
}
|
|
4048
|
+
if (existing) {
|
|
4049
|
+
await this.delete(id, { media: deps.media, storage: deps.storage });
|
|
4050
|
+
}
|
|
4051
|
+
|
|
4052
|
+
const created = await this.createThreadWithAttachments(
|
|
4053
|
+
items,
|
|
4054
|
+
deps,
|
|
4055
|
+
summaryConfig,
|
|
4056
|
+
);
|
|
4057
|
+
|
|
4058
|
+
const kept = new Set(
|
|
4059
|
+
items.flatMap((item) => referencedMediaIds(item.attachments)),
|
|
4060
|
+
);
|
|
4061
|
+
await deps.media
|
|
4062
|
+
.deleteByIds(
|
|
4063
|
+
oldMedia.filter((item) => !kept.has(item.id)).map((item) => item.id),
|
|
4064
|
+
deps.storage,
|
|
4065
|
+
)
|
|
4066
|
+
.catch(() => undefined);
|
|
4067
|
+
return created;
|
|
3999
4068
|
},
|
|
4000
4069
|
|
|
4001
4070
|
async getThread(rootId) {
|
|
@@ -4017,27 +4086,10 @@ export function createPostService(
|
|
|
4017
4086
|
];
|
|
4018
4087
|
|
|
4019
4088
|
if (cursor) {
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
// be used to learn anything about a Post elsewhere.
|
|
4025
|
-
const rows = await db
|
|
4026
|
-
.select(listSortKeyFields(keys))
|
|
4027
|
-
.from(posts)
|
|
4028
|
-
.where(and(...conditions, eq(posts.id, cursor)))
|
|
4029
|
-
.limit(1);
|
|
4030
|
-
const row = rows[0];
|
|
4031
|
-
if (!row) {
|
|
4032
|
-
throw new ValidationError(MISSING_LEGACY_CURSOR_MESSAGE);
|
|
4033
|
-
}
|
|
4034
|
-
values = readListSortKeyValues(keys, row);
|
|
4035
|
-
} else {
|
|
4036
|
-
values = decodePostListCursor(cursor, {
|
|
4037
|
-
mode: THREAD_POSTS_SORT_MODE,
|
|
4038
|
-
kinds: keys.map((key) => key.kind),
|
|
4039
|
-
});
|
|
4040
|
-
}
|
|
4089
|
+
const values = decodePostListCursor(cursor, {
|
|
4090
|
+
mode: THREAD_POSTS_SORT_MODE,
|
|
4091
|
+
kinds: keys.map((key) => key.kind),
|
|
4092
|
+
});
|
|
4041
4093
|
conditions.push(buildListKeysetCondition(keys, values));
|
|
4042
4094
|
}
|
|
4043
4095
|
|
|
@@ -4317,8 +4369,8 @@ export function createPostService(
|
|
|
4317
4369
|
.map((row) => ({ language: row.language, count: Number(row.count) }));
|
|
4318
4370
|
},
|
|
4319
4371
|
|
|
4320
|
-
async listTranslations(postId) {
|
|
4321
|
-
const map = await this.getTranslationsMap([postId]);
|
|
4372
|
+
async listTranslations(postId, reader) {
|
|
4373
|
+
const map = await this.getTranslationsMap([postId], reader);
|
|
4322
4374
|
return map.get(postId) ?? [];
|
|
4323
4375
|
},
|
|
4324
4376
|
|
|
@@ -4435,7 +4487,7 @@ export function createPostService(
|
|
|
4435
4487
|
return { status: "ok", post: candidate };
|
|
4436
4488
|
},
|
|
4437
4489
|
|
|
4438
|
-
async getTranslationsMap(postIds) {
|
|
4490
|
+
async getTranslationsMap(postIds, reader) {
|
|
4439
4491
|
const result = new Map<string, Post[]>();
|
|
4440
4492
|
const uniqueIds = [...new Set(postIds)].filter(Boolean);
|
|
4441
4493
|
if (uniqueIds.length === 0) return result;
|
|
@@ -4466,6 +4518,9 @@ export function createPostService(
|
|
|
4466
4518
|
and(
|
|
4467
4519
|
eq(posts.siteId, siteId),
|
|
4468
4520
|
inArray(posts.translationGroupId, groupIds),
|
|
4521
|
+
...(reader
|
|
4522
|
+
? buildReaderVisibilityConditions(posts, siteId, reader)
|
|
4523
|
+
: []),
|
|
4469
4524
|
),
|
|
4470
4525
|
);
|
|
4471
4526
|
const members = await hydratePosts(memberRows);
|
|
@@ -4865,33 +4920,35 @@ export function createPostService(
|
|
|
4865
4920
|
if (rootIds.length === 0) return result;
|
|
4866
4921
|
|
|
4867
4922
|
const uniqueRootIds = [...new Set(rootIds)];
|
|
4868
|
-
const
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4923
|
+
const inThreadOrder = () => sql`
|
|
4924
|
+
PARTITION BY ${posts.threadId}
|
|
4925
|
+
ORDER BY ${sql.join(threadOrder(), sql`, `)}
|
|
4926
|
+
`;
|
|
4927
|
+
const threadPosition = () =>
|
|
4928
|
+
sql<number>`CAST(
|
|
4929
|
+
row_number() OVER (${inThreadOrder()}) - 1 AS INTEGER
|
|
4930
|
+
)`.as("thread_position");
|
|
4931
|
+
const threadPostCount = () =>
|
|
4932
|
+
sql<number>`CAST(
|
|
4933
|
+
count(*) OVER (PARTITION BY ${posts.threadId}) AS INTEGER
|
|
4934
|
+
)`.as("thread_post_count");
|
|
4935
|
+
const inRequestedThreads = and(
|
|
4936
|
+
eq(posts.siteId, siteId),
|
|
4937
|
+
inArray(posts.threadId, uniqueRootIds),
|
|
4938
|
+
eq(posts.status, "published"),
|
|
4939
|
+
);
|
|
4877
4940
|
|
|
4941
|
+
// The Posts shown: the Root, every Featured Post, and the last Post.
|
|
4878
4942
|
const rankedPosts = db
|
|
4879
4943
|
.select({
|
|
4880
4944
|
...getTableColumns(posts),
|
|
4881
|
-
threadPosition,
|
|
4882
|
-
threadPostCount,
|
|
4945
|
+
threadPosition: threadPosition(),
|
|
4946
|
+
threadPostCount: threadPostCount(),
|
|
4883
4947
|
})
|
|
4884
4948
|
.from(posts)
|
|
4885
|
-
.where(
|
|
4886
|
-
and(
|
|
4887
|
-
eq(posts.siteId, siteId),
|
|
4888
|
-
inArray(posts.threadId, uniqueRootIds),
|
|
4889
|
-
eq(posts.status, "published"),
|
|
4890
|
-
),
|
|
4891
|
-
)
|
|
4949
|
+
.where(inRequestedThreads)
|
|
4892
4950
|
.as("ranked_featured_thread_post");
|
|
4893
|
-
|
|
4894
|
-
const rows = await db
|
|
4951
|
+
const shownQuery = db
|
|
4895
4952
|
.select()
|
|
4896
4953
|
.from(rankedPosts)
|
|
4897
4954
|
.where(
|
|
@@ -4903,12 +4960,61 @@ export function createPostService(
|
|
|
4903
4960
|
)
|
|
4904
4961
|
.orderBy(rankedPosts.threadId, sql`${rankedPosts.threadPosition}`);
|
|
4905
4962
|
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4963
|
+
// Where each gap points: the Post right after a shown one, when it is
|
|
4964
|
+
// hidden itself. Read beside the shown Posts rather than with them, and
|
|
4965
|
+
// only as far as its address, since nothing renders it.
|
|
4966
|
+
const gapCandidates = db
|
|
4967
|
+
.select({
|
|
4968
|
+
id: posts.id,
|
|
4969
|
+
threadId: posts.threadId,
|
|
4970
|
+
featuredAt: posts.featuredAt,
|
|
4971
|
+
threadPosition: threadPosition(),
|
|
4972
|
+
threadPostCount: threadPostCount(),
|
|
4973
|
+
previousPostId: sql<
|
|
4974
|
+
string | null
|
|
4975
|
+
>`LAG(${posts.id}) OVER (${inThreadOrder()})`.as("previous_post_id"),
|
|
4976
|
+
previousFeaturedAt: sql<
|
|
4977
|
+
number | null
|
|
4978
|
+
>`LAG(${posts.featuredAt}) OVER (${inThreadOrder()})`.as(
|
|
4979
|
+
"previous_featured_at",
|
|
4980
|
+
),
|
|
4981
|
+
})
|
|
4982
|
+
.from(posts)
|
|
4983
|
+
.where(inRequestedThreads)
|
|
4984
|
+
.as("featured_thread_gap_candidate");
|
|
4985
|
+
const gapQuery = db
|
|
4986
|
+
.select({
|
|
4987
|
+
id: gapCandidates.id,
|
|
4988
|
+
threadId: gapCandidates.threadId,
|
|
4989
|
+
previousPostId: gapCandidates.previousPostId,
|
|
4990
|
+
})
|
|
4991
|
+
.from(gapCandidates)
|
|
4992
|
+
.where(
|
|
4993
|
+
and(
|
|
4994
|
+
// Hidden: not the Root, not Featured, not the last Post...
|
|
4995
|
+
ne(gapCandidates.id, gapCandidates.threadId),
|
|
4996
|
+
isNull(gapCandidates.featuredAt),
|
|
4997
|
+
sql`${gapCandidates.threadPosition} < ${gapCandidates.threadPostCount} - 1`,
|
|
4998
|
+
// ...right after a shown Post. Nothing follows the last one, so
|
|
4999
|
+
// that is the Root or a Featured Post.
|
|
5000
|
+
or(
|
|
5001
|
+
eq(gapCandidates.previousPostId, gapCandidates.threadId),
|
|
5002
|
+
isNotNull(gapCandidates.previousFeaturedAt),
|
|
5003
|
+
),
|
|
5004
|
+
),
|
|
5005
|
+
);
|
|
5006
|
+
|
|
5007
|
+
const [rows, gapRows] = await Promise.all([shownQuery, gapQuery]);
|
|
5008
|
+
|
|
5009
|
+
const [hydratedPosts, gapSlugs] = await Promise.all([
|
|
5010
|
+
hydratePosts(
|
|
5011
|
+
rows.map(
|
|
5012
|
+
({ threadPosition: _position, threadPostCount: _count, ...row }) =>
|
|
5013
|
+
row,
|
|
5014
|
+
),
|
|
4910
5015
|
),
|
|
4911
|
-
|
|
5016
|
+
resolvedPaths.getPostSlugMap(gapRows.map((row) => row.id)),
|
|
5017
|
+
]);
|
|
4912
5018
|
const hydratedById = new Map(
|
|
4913
5019
|
hydratedPosts.map((post) => [post.id, post]),
|
|
4914
5020
|
);
|
|
@@ -4920,6 +5026,7 @@ export function createPostService(
|
|
|
4920
5026
|
const thread = result.get(row.threadId) ?? {
|
|
4921
5027
|
posts: [],
|
|
4922
5028
|
featuredPostIds: [],
|
|
5029
|
+
gapTargets: [],
|
|
4923
5030
|
};
|
|
4924
5031
|
thread.posts.push({ post, position: row.threadPosition });
|
|
4925
5032
|
if (row.featuredAt !== null) {
|
|
@@ -4928,6 +5035,17 @@ export function createPostService(
|
|
|
4928
5035
|
result.set(row.threadId, thread);
|
|
4929
5036
|
}
|
|
4930
5037
|
|
|
5038
|
+
for (const row of gapRows) {
|
|
5039
|
+
const slug = gapSlugs.get(row.id);
|
|
5040
|
+
const thread = result.get(row.threadId);
|
|
5041
|
+
if (!slug || !thread || !row.previousPostId) continue;
|
|
5042
|
+
thread.gapTargets.push({
|
|
5043
|
+
id: row.id,
|
|
5044
|
+
slug,
|
|
5045
|
+
afterPostId: row.previousPostId,
|
|
5046
|
+
});
|
|
5047
|
+
}
|
|
5048
|
+
|
|
4931
5049
|
return result;
|
|
4932
5050
|
},
|
|
4933
5051
|
|
|
@@ -5039,7 +5157,7 @@ export function createPostService(
|
|
|
5039
5157
|
const after = cursor
|
|
5040
5158
|
? buildListKeysetCondition(
|
|
5041
5159
|
keys,
|
|
5042
|
-
|
|
5160
|
+
resolveCollectionThreadCursor(cursor, sort),
|
|
5043
5161
|
)
|
|
5044
5162
|
: undefined;
|
|
5045
5163
|
|
|
@@ -5200,19 +5318,16 @@ export function createPostService(
|
|
|
5200
5318
|
return result;
|
|
5201
5319
|
},
|
|
5202
5320
|
|
|
5203
|
-
async getDistinctYears(filters
|
|
5204
|
-
const
|
|
5205
|
-
|
|
5206
|
-
const publishedYearExpr = buildYearExpr(axis);
|
|
5321
|
+
async getDistinctYears(filters, timeZone) {
|
|
5322
|
+
const years = await calendarPeriodsOf(filters, "year", timeZone);
|
|
5323
|
+
if (!years) return [];
|
|
5207
5324
|
|
|
5208
5325
|
const rows = await db
|
|
5209
|
-
.select({
|
|
5210
|
-
year: publishedYearExpr.as("year"),
|
|
5211
|
-
})
|
|
5326
|
+
.select({ year: years.expr.as("year") })
|
|
5212
5327
|
.from(posts)
|
|
5213
|
-
.where(
|
|
5214
|
-
.groupBy(
|
|
5215
|
-
.orderBy(desc(
|
|
5328
|
+
.where(years.where)
|
|
5329
|
+
.groupBy(years.expr)
|
|
5330
|
+
.orderBy(desc(years.expr));
|
|
5216
5331
|
|
|
5217
5332
|
return rows.map((r) => parseInt(r.year, 10));
|
|
5218
5333
|
},
|