@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/lib/api-posts.ts
CHANGED
|
@@ -5,6 +5,8 @@ import type { AppConfig } from "../types/config.js";
|
|
|
5
5
|
import type { Media, Post, Status } from "../types.js";
|
|
6
6
|
import { getPostDisplayTitle } from "./post-meta.js";
|
|
7
7
|
import { getImageUrl, getMediaUrl, getPublicUrlForProvider } from "./image.js";
|
|
8
|
+
import type { PostContent } from "./schemas.js";
|
|
9
|
+
import { tiptapJsonToMarkdown } from "./tiptap-to-markdown.js";
|
|
8
10
|
import { toPublicPath } from "./url.js";
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -32,9 +34,14 @@ export interface ApiPostResponse {
|
|
|
32
34
|
* a URL, not a name.
|
|
33
35
|
*/
|
|
34
36
|
displayTitle: string;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
/** TipTap JSON. Left out when the read asked for `content: "markdown"`. */
|
|
38
|
+
body?: string | null;
|
|
39
|
+
/** Left out when the read asked for `content: "markdown"`. */
|
|
40
|
+
bodyHtml?: string | null;
|
|
41
|
+
/** Left out when the read asked for `content: "markdown"`. */
|
|
42
|
+
bodyText?: string | null;
|
|
43
|
+
/** Only when the read asked for `content: "markdown"`. */
|
|
44
|
+
bodyMarkdown?: string | null;
|
|
38
45
|
quoteText: string | null;
|
|
39
46
|
summary: string | null;
|
|
40
47
|
rating: number | null;
|
|
@@ -180,6 +187,63 @@ export function toApiAttachment(
|
|
|
180
187
|
};
|
|
181
188
|
}
|
|
182
189
|
|
|
190
|
+
/**
|
|
191
|
+
* A post body as Markdown, or null for a historical body that isn't TipTap
|
|
192
|
+
* JSON. One unreadable row answers null and is logged, rather than failing a
|
|
193
|
+
* whole page of posts.
|
|
194
|
+
*
|
|
195
|
+
* @param postId - The post, named in the log line
|
|
196
|
+
* @param body - The stored TipTap JSON
|
|
197
|
+
* @returns The Markdown, or null
|
|
198
|
+
* @example
|
|
199
|
+
* toBodyMarkdown(post.id, post.body); // "Hello **world**"
|
|
200
|
+
*/
|
|
201
|
+
export function toBodyMarkdown(postId: string, body: string): string | null {
|
|
202
|
+
try {
|
|
203
|
+
return tiptapJsonToMarkdown(body);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
// eslint-disable-next-line no-console -- A skipped body must leave a trace
|
|
206
|
+
console.error(
|
|
207
|
+
`Couldn't convert the body of post ${postId} to Markdown`,
|
|
208
|
+
error,
|
|
209
|
+
);
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The body fields a read returns: the stored and rendered forms, or with
|
|
216
|
+
* `content: "markdown"` the Markdown alone.
|
|
217
|
+
*
|
|
218
|
+
* @param post - The Post
|
|
219
|
+
* @param content - The body format the read asked for
|
|
220
|
+
* @returns The body fields
|
|
221
|
+
* @example
|
|
222
|
+
* toApiPostBody(post, "markdown"); // { bodyMarkdown: "…" }
|
|
223
|
+
*/
|
|
224
|
+
function toApiPostBody(
|
|
225
|
+
post: Post,
|
|
226
|
+
content: PostContent | undefined,
|
|
227
|
+
): Pick<ApiPostResponse, "body" | "bodyHtml" | "bodyText" | "bodyMarkdown"> {
|
|
228
|
+
if (content === "markdown") {
|
|
229
|
+
return {
|
|
230
|
+
bodyMarkdown: post.body ? toBodyMarkdown(post.id, post.body) : null,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
return { body: post.body, bodyHtml: post.bodyHtml, bodyText: post.bodyText };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* One Post's author response, from what was read about it in its page's batch.
|
|
238
|
+
*
|
|
239
|
+
* @param post - The Post
|
|
240
|
+
* @param extras - Its Thread's post count, attachments, and collections
|
|
241
|
+
* @param options - `content: "markdown"` returns `bodyMarkdown` in place of
|
|
242
|
+
* `body`, `bodyHtml`, and `bodyText`
|
|
243
|
+
* @returns The response
|
|
244
|
+
* @example
|
|
245
|
+
* toApiPost(post, { threadPostCount: 1 });
|
|
246
|
+
*/
|
|
183
247
|
export function toApiPost(
|
|
184
248
|
post: Post,
|
|
185
249
|
extras: {
|
|
@@ -187,6 +251,7 @@ export function toApiPost(
|
|
|
187
251
|
attachments?: ReturnType<typeof toApiAttachment>[];
|
|
188
252
|
collectionIds?: string[];
|
|
189
253
|
},
|
|
254
|
+
options: { content?: PostContent } = {},
|
|
190
255
|
): ApiPostResponse {
|
|
191
256
|
// Quotes name their source where other formats carry a title and link.
|
|
192
257
|
const source =
|
|
@@ -206,9 +271,7 @@ export function toApiPost(
|
|
|
206
271
|
// A short name for this Post wherever it is referenced from somewhere
|
|
207
272
|
// else — notes are usually untitled, so the client cannot just read `title`.
|
|
208
273
|
displayTitle: getPostDisplayTitle(post),
|
|
209
|
-
|
|
210
|
-
bodyHtml: post.bodyHtml,
|
|
211
|
-
bodyText: post.bodyText,
|
|
274
|
+
...toApiPostBody(post, options.content),
|
|
212
275
|
quoteText: post.quoteText,
|
|
213
276
|
summary: post.summary,
|
|
214
277
|
rating: post.rating,
|
|
@@ -233,6 +296,14 @@ export interface ApiPostResponseDeps {
|
|
|
233
296
|
appConfig: AppConfig;
|
|
234
297
|
}
|
|
235
298
|
|
|
299
|
+
/** What else {@link loadApiPostResponses} puts on each response. */
|
|
300
|
+
export interface ApiPostResponseOptions {
|
|
301
|
+
/** Add each Post's shared Thread collections. */
|
|
302
|
+
collectionIds?: boolean;
|
|
303
|
+
/** `markdown` returns each body as Markdown. */
|
|
304
|
+
content?: PostContent;
|
|
305
|
+
}
|
|
306
|
+
|
|
236
307
|
/**
|
|
237
308
|
* API responses for Posts already loaded. Attachments, Thread Post counts,
|
|
238
309
|
* and (when asked) Thread collections are each read in one batch for the
|
|
@@ -240,7 +311,8 @@ export interface ApiPostResponseDeps {
|
|
|
240
311
|
*
|
|
241
312
|
* @param deps - Services and app config; a request's `c.var` or an MCP context
|
|
242
313
|
* @param posts - Posts to respond with, in order
|
|
243
|
-
* @param options - `collectionIds` adds each Post's shared Thread collections
|
|
314
|
+
* @param options - `collectionIds` adds each Post's shared Thread collections;
|
|
315
|
+
* `content: "markdown"` returns each body as Markdown
|
|
244
316
|
* @returns One response per Post, in the same order
|
|
245
317
|
* @example
|
|
246
318
|
* const responses = await loadApiPostResponses(c.var, page.posts);
|
|
@@ -248,7 +320,7 @@ export interface ApiPostResponseDeps {
|
|
|
248
320
|
export async function loadApiPostResponses(
|
|
249
321
|
deps: ApiPostResponseDeps,
|
|
250
322
|
posts: Post[],
|
|
251
|
-
options:
|
|
323
|
+
options: ApiPostResponseOptions = {},
|
|
252
324
|
): Promise<ApiPostResponse[]> {
|
|
253
325
|
if (posts.length === 0) return [];
|
|
254
326
|
const { services, appConfig } = deps;
|
|
@@ -262,19 +334,23 @@ export async function loadApiPostResponses(
|
|
|
262
334
|
]);
|
|
263
335
|
|
|
264
336
|
return posts.map((post) =>
|
|
265
|
-
toApiPost(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
337
|
+
toApiPost(
|
|
338
|
+
post,
|
|
339
|
+
{
|
|
340
|
+
threadPostCount: threadPostCounts.get(post.threadId) ?? 0,
|
|
341
|
+
attachments: (mediaMap.get(post.id) ?? []).map((media) =>
|
|
342
|
+
toApiAttachment(media, appConfig),
|
|
343
|
+
),
|
|
344
|
+
...(collectionsMap
|
|
345
|
+
? {
|
|
346
|
+
collectionIds: (collectionsMap.get(post.id) ?? []).map(
|
|
347
|
+
(collection) => collection.id,
|
|
348
|
+
),
|
|
349
|
+
}
|
|
350
|
+
: {}),
|
|
351
|
+
},
|
|
352
|
+
{ content: options.content },
|
|
353
|
+
),
|
|
278
354
|
);
|
|
279
355
|
}
|
|
280
356
|
|
|
@@ -283,7 +359,7 @@ export async function loadApiPostResponses(
|
|
|
283
359
|
*
|
|
284
360
|
* @param deps - Services and app config
|
|
285
361
|
* @param post - The Post
|
|
286
|
-
* @param options -
|
|
362
|
+
* @param options - As for {@link loadApiPostResponses}
|
|
287
363
|
* @returns The Post's response
|
|
288
364
|
* @example
|
|
289
365
|
* return c.json(await loadApiPostResponse(c.var, post));
|
|
@@ -291,9 +367,35 @@ export async function loadApiPostResponses(
|
|
|
291
367
|
export async function loadApiPostResponse(
|
|
292
368
|
deps: ApiPostResponseDeps,
|
|
293
369
|
post: Post,
|
|
294
|
-
options:
|
|
370
|
+
options: ApiPostResponseOptions = {},
|
|
295
371
|
): Promise<ApiPostResponse> {
|
|
296
372
|
const [response] = await loadApiPostResponses(deps, [post], options);
|
|
297
373
|
if (!response) throw new Error(`No response built for post ${post.id}`);
|
|
298
374
|
return response;
|
|
299
375
|
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* One Post as `GET /api/posts/:id` and `jant_posts_get` answer it: the
|
|
379
|
+
* response, its Thread's collections, and its place in the Thread.
|
|
380
|
+
*
|
|
381
|
+
* @param deps - Services and app config
|
|
382
|
+
* @param post - The Post
|
|
383
|
+
* @param options - `content: "markdown"` returns the body as Markdown
|
|
384
|
+
* @returns The Post's response with `collectionIds` and `threadPosition`
|
|
385
|
+
* @example
|
|
386
|
+
* return c.json(await loadApiPostDetail(c.var, post));
|
|
387
|
+
*/
|
|
388
|
+
export async function loadApiPostDetail(
|
|
389
|
+
deps: ApiPostResponseDeps,
|
|
390
|
+
post: Post,
|
|
391
|
+
options: { content?: PostContent } = {},
|
|
392
|
+
): Promise<ApiPostResponse & { threadPosition: number }> {
|
|
393
|
+
const [response, threadPosition] = await Promise.all([
|
|
394
|
+
loadApiPostResponse(deps, post, {
|
|
395
|
+
collectionIds: true,
|
|
396
|
+
content: options.content,
|
|
397
|
+
}),
|
|
398
|
+
deps.services.posts.getThreadPosition(post.id),
|
|
399
|
+
]);
|
|
400
|
+
return { ...response, threadPosition };
|
|
401
|
+
}
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
import type { Services } from "../services/index.js";
|
|
9
9
|
import type { AppConfig } from "../types/config.js";
|
|
10
10
|
import type { Collection, Media, Post } from "../types.js";
|
|
11
|
+
import type { PostContent } from "./schemas.js";
|
|
11
12
|
import { getCollectionPagePath } from "./collection-paths.js";
|
|
12
|
-
import { toApiAttachment } from "./api-posts.js";
|
|
13
|
-
import {
|
|
14
|
-
import { toPublicPath } from "./url.js";
|
|
13
|
+
import { toApiAttachment, toBodyMarkdown } from "./api-posts.js";
|
|
14
|
+
import { getPostPath, toPublicPath } from "./url.js";
|
|
15
15
|
import { getImageUrl, getMediaUrl, getPublicUrlForProvider } from "./image.js";
|
|
16
16
|
|
|
17
17
|
export type PublicPostBaseResponse = {
|
|
@@ -72,33 +72,22 @@ export type PublicPostMarkdownResponse = PublicPostBaseResponse & {
|
|
|
72
72
|
bodyMarkdown: string | null;
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
+
/** What the public API's responses read besides the Posts themselves. */
|
|
76
|
+
export interface PublicResponseDeps {
|
|
77
|
+
services: Pick<Services, "media" | "posts" | "collections" | "paths">;
|
|
78
|
+
appConfig: AppConfig;
|
|
79
|
+
}
|
|
80
|
+
|
|
75
81
|
export type PublicPostResponse =
|
|
76
82
|
PublicPostRenderedResponse | PublicPostMarkdownResponse;
|
|
77
83
|
|
|
78
|
-
/**
|
|
79
|
-
* The public Markdown for a post, or null for a historical body that isn't
|
|
80
|
-
* TipTap JSON. One unreadable row answers null and is logged, rather than
|
|
81
|
-
* failing the whole listing; `bodyHtml` still falls back to stored HTML.
|
|
82
|
-
*/
|
|
83
|
-
function toPublicBodyMarkdown(postId: string, body: string): string | null {
|
|
84
|
-
try {
|
|
85
|
-
return tiptapJsonToMarkdown(body);
|
|
86
|
-
} catch (error) {
|
|
87
|
-
// eslint-disable-next-line no-console -- A skipped body must leave a trace
|
|
88
|
-
console.error(
|
|
89
|
-
`Couldn't convert the body of post ${postId} to Markdown`,
|
|
90
|
-
error,
|
|
91
|
-
);
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
84
|
/**
|
|
97
85
|
* One Post's reading view, from its attachments, its Thread's collections, and
|
|
98
86
|
* its Thread's Post count.
|
|
99
87
|
*
|
|
100
88
|
* @param post - The Post
|
|
101
|
-
* @param related - What was read about it in the same batch as its page
|
|
89
|
+
* @param related - What was read about it in the same batch as its page;
|
|
90
|
+
* `aliasPath` is its oldest custom path, its permalink when it has one
|
|
102
91
|
* @param appConfig - Media URLs and the site path prefix
|
|
103
92
|
* @param options - `content: "markdown"` returns `bodyMarkdown` instead of the
|
|
104
93
|
* rendered body
|
|
@@ -112,9 +101,10 @@ export function toPublicPost(
|
|
|
112
101
|
media: Media[];
|
|
113
102
|
collections: Collection[];
|
|
114
103
|
threadPostCount: number;
|
|
104
|
+
aliasPath?: string | null;
|
|
115
105
|
},
|
|
116
106
|
appConfig: AppConfig,
|
|
117
|
-
options?: { content?:
|
|
107
|
+
options?: { content?: PostContent },
|
|
118
108
|
): PublicPostResponse {
|
|
119
109
|
const {
|
|
120
110
|
r2PublicUrl,
|
|
@@ -149,7 +139,10 @@ export function toPublicPost(
|
|
|
149
139
|
status: "published" as const,
|
|
150
140
|
visibility: post.visibility,
|
|
151
141
|
slug: post.slug,
|
|
152
|
-
permalink: toPublicPath(
|
|
142
|
+
permalink: toPublicPath(
|
|
143
|
+
getPostPath(post.slug, related.aliasPath),
|
|
144
|
+
sitePathPrefix,
|
|
145
|
+
),
|
|
153
146
|
quoteText: post.quoteText,
|
|
154
147
|
summary: post.summary,
|
|
155
148
|
rating: post.rating,
|
|
@@ -181,9 +174,7 @@ export function toPublicPost(
|
|
|
181
174
|
const contentFields =
|
|
182
175
|
options?.content === "markdown"
|
|
183
176
|
? {
|
|
184
|
-
bodyMarkdown: post.body
|
|
185
|
-
? toPublicBodyMarkdown(post.id, post.body)
|
|
186
|
-
: null,
|
|
177
|
+
bodyMarkdown: post.body ? toBodyMarkdown(post.id, post.body) : null,
|
|
187
178
|
}
|
|
188
179
|
: {
|
|
189
180
|
bodyHtml: post.bodyHtml,
|
|
@@ -219,21 +210,20 @@ export function toPublicPost(
|
|
|
219
210
|
* const responses = await loadPublicPostResponses(c.var, page.posts, {});
|
|
220
211
|
*/
|
|
221
212
|
export async function loadPublicPostResponses(
|
|
222
|
-
deps:
|
|
223
|
-
services: Pick<Services, "media" | "posts" | "collections">;
|
|
224
|
-
appConfig: AppConfig;
|
|
225
|
-
},
|
|
213
|
+
deps: PublicResponseDeps,
|
|
226
214
|
posts: Post[],
|
|
227
|
-
options: { content?:
|
|
215
|
+
options: { content?: PostContent } = {},
|
|
228
216
|
): Promise<PublicPostResponse[]> {
|
|
229
217
|
if (posts.length === 0) return [];
|
|
230
218
|
const { services, appConfig } = deps;
|
|
231
219
|
const postIds = posts.map((post) => post.id);
|
|
232
|
-
const [mediaMap, collectionsMap, threadPostCounts] =
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
220
|
+
const [mediaMap, collectionsMap, threadPostCounts, aliases] =
|
|
221
|
+
await Promise.all([
|
|
222
|
+
services.media.getByPostIds(postIds),
|
|
223
|
+
services.collections.getCollectionsByPostIds(postIds),
|
|
224
|
+
services.posts.countThreadPosts(posts.map((post) => post.threadId)),
|
|
225
|
+
services.paths.getPostAliases(postIds),
|
|
226
|
+
]);
|
|
237
227
|
|
|
238
228
|
return posts.map((post) =>
|
|
239
229
|
toPublicPost(
|
|
@@ -242,6 +232,7 @@ export async function loadPublicPostResponses(
|
|
|
242
232
|
media: mediaMap.get(post.id) ?? [],
|
|
243
233
|
collections: collectionsMap.get(post.id) ?? [],
|
|
244
234
|
threadPostCount: threadPostCounts.get(post.threadId) ?? 0,
|
|
235
|
+
aliasPath: aliases.get(post.id)?.[0],
|
|
245
236
|
},
|
|
246
237
|
appConfig,
|
|
247
238
|
options,
|
package/src/lib/api-search.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { Services } from "../services/index.js";
|
|
2
|
+
import type { AppConfig } from "../types/config.js";
|
|
1
3
|
import type { Post } from "../types.js";
|
|
2
|
-
import { toPublicPath } from "./url.js";
|
|
4
|
+
import { getPostPath, toPublicPath } from "./url.js";
|
|
3
5
|
|
|
4
6
|
export type SearchApiResult = {
|
|
5
7
|
id: string;
|
|
@@ -16,12 +18,27 @@ export type SearchApiResult = {
|
|
|
16
18
|
sourceUrl?: string | null;
|
|
17
19
|
};
|
|
18
20
|
|
|
21
|
+
/**
|
|
22
|
+
* One search result as the API and MCP return it.
|
|
23
|
+
*
|
|
24
|
+
* @param post - The matching Post
|
|
25
|
+
* @param snippet - Highlighted excerpt, when the search made one
|
|
26
|
+
* @param sitePathPrefix - The site's path prefix
|
|
27
|
+
* @param aliasPath - The Post's oldest custom path, its permalink when it has one
|
|
28
|
+
* @returns The result object
|
|
29
|
+
* @example
|
|
30
|
+
* toSearchApiResult(post, "a <mark>match</mark>", "", "/blog/hello");
|
|
31
|
+
*/
|
|
19
32
|
export function toSearchApiResult(
|
|
20
33
|
post: Post,
|
|
21
34
|
snippet: string | undefined,
|
|
22
35
|
sitePathPrefix?: string,
|
|
36
|
+
aliasPath?: string | null,
|
|
23
37
|
): SearchApiResult {
|
|
24
|
-
const permalink = toPublicPath(
|
|
38
|
+
const permalink = toPublicPath(
|
|
39
|
+
getPostPath(post.slug, aliasPath),
|
|
40
|
+
sitePathPrefix,
|
|
41
|
+
);
|
|
25
42
|
|
|
26
43
|
if (post.format === "quote") {
|
|
27
44
|
return {
|
|
@@ -49,3 +66,33 @@ export function toSearchApiResult(
|
|
|
49
66
|
visibility: post.visibility,
|
|
50
67
|
};
|
|
51
68
|
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Search results as the API and MCP return them, with each Post's custom path
|
|
72
|
+
* read in one batch.
|
|
73
|
+
*
|
|
74
|
+
* @param deps - Services and app config; a request's `c.var`
|
|
75
|
+
* @param results - What the search service found, in order
|
|
76
|
+
* @returns One result object per match, in the same order
|
|
77
|
+
* @example
|
|
78
|
+
* const results = await loadSearchApiResults(c.var, await search.search(q));
|
|
79
|
+
*/
|
|
80
|
+
export async function loadSearchApiResults(
|
|
81
|
+
deps: {
|
|
82
|
+
services: Pick<Services, "paths">;
|
|
83
|
+
appConfig: Pick<AppConfig, "sitePathPrefix">;
|
|
84
|
+
},
|
|
85
|
+
results: readonly { post: Post; snippet?: string }[],
|
|
86
|
+
): Promise<SearchApiResult[]> {
|
|
87
|
+
const aliases = await deps.services.paths.getPostAliases(
|
|
88
|
+
results.map((result) => result.post.id),
|
|
89
|
+
);
|
|
90
|
+
return results.map((result) =>
|
|
91
|
+
toSearchApiResult(
|
|
92
|
+
result.post,
|
|
93
|
+
result.snippet,
|
|
94
|
+
deps.appConfig.sitePathPrefix,
|
|
95
|
+
aliases.get(result.post.id)?.[0],
|
|
96
|
+
),
|
|
97
|
+
);
|
|
98
|
+
}
|