@jant/core 0.8.0 → 0.9.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/dist/{app-CFsmRVJN.js → app-BzH8jmh3.js} +1619 -500
- package/dist/client/.vite/manifest.json +2 -2
- package/dist/client/_assets/{client-DTLBOHqD.js → client-S8oryJ0m.js} +1 -1
- package/dist/client/_assets/{client-auth-D6Ix6SmE.js → client-auth-Ds9G0IgR.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/node.js +2 -2
- package/package.json +1 -1
- package/src/__tests__/fixtures/releases/0.8.0/site-export/README.md +130 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/2thjq/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/2u5e5/_index.md +35 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/0x4nv/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/faqyt/index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/5kayp/_index.md +23 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/5ynfs/_index.md +31 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/5ynfs/hu597/index.md +21 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/_index.md +5 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +31 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +36 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/archive/_index.md +8 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/are-na-is-the-only-bookmark-pile-i-still-revisit/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/bought-too-many-lemons-again/_index.md +37 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/city-walks/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/cleanshot-for-screenshots-ocr-and-screen-recording-on-the-mac/_index.md +33 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/cleanshotmac-shang-de-jie-tu-ocr-lu-ping-gong-ju/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/co344/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/collections/_index.md +5 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/current-tea-rotation/_index.md +34 -0
- package/src/__tests__/fixtures/releases/0.8.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.8.0/site-export/content/desk-but-better/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/e0kcg/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/egi3c/_index.md +24 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/evf9j/_index.md +152 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/featured/_index.md +8 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-basho/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-epictetus/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-marcus-aurelius/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-seneca/_index.md +26 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/from-thoreau/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/2cl6d/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/3zqv7/index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/5oxsv/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gkbvv/_index.md +39 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/gwob9/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/home-cooking/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/hz729/_index.md +24 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/inaturalist-ai-zi-ran-she-qu/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/j4v0q/_index.md +35 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k278t/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k4eee/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/a83qu/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/k5vh8/from-seneca-5hibo/index.md +21 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/kan-qi-lai-bi-jiao-ku-de-gong-si-men/_index.md +41 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/l2m7y/_index.md +29 -0
- package/src/__tests__/fixtures/releases/0.8.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.8.0/site-export/content/mynoise-for-rainy-afternoons/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/n09le/_index.md +23 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/ni-fu-jin-de-wei-ji-bai-ke-tiao-mu/_index.md +42 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/nts-archives-are-good-cleaning-music/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/c91j0/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/qyucy/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/qgfcu/wsgck/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +46 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/reading-notes/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/s4r3e/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/cxiu6/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/t77ms/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/te812/the-soup-trick-i-always-forget/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/telk3/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/telk3/from-thoreau-pawt2/index.md +21 -0
- package/src/__tests__/fixtures/releases/0.8.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.8.0/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/tiny-projects/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/tong-wang-xing-fu-zhi-lu/_index.md +68 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/tou-ma-yan-jiang-ju-le-bu-chu-ti-yan/_index.md +62 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/useful-links/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/weekend-notes/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/content/what-i-actually-use-my-notebook-for/_index.md +52 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/data/jant.toml +124 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/hugo.toml +45 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/_redirects +25 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/15d51730a4f7-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q1hme4e8cmby77dn66yy.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q2w7e4e8cmc20036yh66.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q7d2e4e8cmdeqjmyafby.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m313q887e4e8cmdjssych7yh.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167sm0f6ct88qw5brtsgcw.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167tf8f6ct88r169s51j49.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167vaaf6ct88rbx5ztenwb.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167w51f6ct88rp19pybkw1.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167x0nf6ct88rzajb84tw3.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167xxbf6ct88s5t2300bjk.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167yq5f6ct88s9pjwt5fxg.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/static/media/med_01m3167zg4f6ct88sge8jp28ja.webp +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/themes/jant/static/apple-touch-icon.png +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/themes/jant/static/custom.css +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/themes/jant/static/favicon.ico +0 -0
- package/src/__tests__/fixtures/releases/0.8.0/site-export/wrangler.jsonc +24 -0
- package/src/__tests__/fixtures/releases/0.8.0/snapshot/db.sql +322 -0
- package/src/__tests__/fixtures/releases/0.8.0/snapshot/meta.json +11 -0
- package/src/__tests__/helpers/cursor-walk.ts +82 -0
- package/src/__tests__/release-fixtures.test.ts +6 -2
- package/src/app.tsx +4 -0
- package/src/lib/__tests__/post-list-cursor.test.ts +105 -0
- package/src/lib/__tests__/thread-fold.test.ts +43 -0
- package/src/lib/__tests__/timeline.test.ts +14 -14
- package/src/lib/api-posts.ts +110 -2
- package/src/lib/api-public-posts.ts +263 -0
- package/src/lib/api-threads.ts +207 -0
- package/src/lib/post-list-cursor.ts +211 -0
- package/src/lib/thread-fold.ts +83 -41
- package/src/lib/thread-query.ts +143 -0
- package/src/middleware/cors.ts +8 -1
- package/src/middleware/deprecation.ts +48 -0
- package/src/routes/api/__tests__/mcp.test.ts +147 -0
- package/src/routes/api/__tests__/posts.test.ts +157 -0
- package/src/routes/api/__tests__/public-access.test.ts +5 -0
- package/src/routes/api/__tests__/threads.test.ts +115 -0
- package/src/routes/api/posts.ts +19 -112
- package/src/routes/api/public/__tests__/archive.test.ts +261 -0
- package/src/routes/api/public/__tests__/posts.test.ts +344 -19
- package/src/routes/api/public/__tests__/threads.test.ts +363 -0
- package/src/routes/api/public/archive.ts +82 -79
- package/src/routes/api/public/posts.ts +97 -299
- package/src/routes/api/public/threads.ts +141 -0
- package/src/routes/api/threads.ts +128 -0
- package/src/services/__tests__/post.test.ts +342 -36
- package/src/services/__tests__/thread.test.ts +495 -0
- package/src/services/index.ts +4 -0
- package/src/services/mcp.ts +213 -63
- package/src/services/post.ts +734 -361
- package/src/services/thread.ts +392 -0
- package/src/types/constants.ts +25 -0
- package/src/ui/feed/ThreadPreview.tsx +9 -14
- package/src/ui/feed/__tests__/thread-preview.test.ts +18 -22
- package/src/ui/feed/thread-preview-state.ts +0 -35
- package/src/ui/shared/Pagination.tsx +1 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import type { Bindings,
|
|
3
|
+
import type { Bindings, Post } from "../../../types.js";
|
|
4
4
|
import type { AppVariables } from "../../../types/app-context.js";
|
|
5
|
-
import { getCollectionPagePath } from "../../../lib/collection-paths.js";
|
|
6
5
|
import {
|
|
7
6
|
CollectionSortOrderSchema,
|
|
8
7
|
ContentLanguageSchema,
|
|
@@ -10,19 +9,16 @@ import {
|
|
|
10
9
|
parseValidated,
|
|
11
10
|
} from "../../../lib/schemas.js";
|
|
12
11
|
import { NotFoundError } from "../../../lib/errors.js";
|
|
13
|
-
import {
|
|
14
|
-
import { tiptapJsonToMarkdown } from "../../../lib/tiptap-to-markdown.js";
|
|
15
|
-
import { toPublicPath } from "../../../lib/url.js";
|
|
16
|
-
import {
|
|
17
|
-
getImageUrl,
|
|
18
|
-
getMediaUrl,
|
|
19
|
-
getPublicUrlForProvider,
|
|
20
|
-
} from "../../../lib/image.js";
|
|
12
|
+
import { loadPublicPostResponses } from "../../../lib/api-public-posts.js";
|
|
21
13
|
import {
|
|
22
14
|
resolveCollectionSortOrder,
|
|
23
15
|
supportsCollectionRatingSort,
|
|
24
16
|
} from "../../../lib/collection-sort.js";
|
|
25
17
|
import { requirePublicApiEnabled } from "../../../middleware/public-content-access.js";
|
|
18
|
+
import {
|
|
19
|
+
deprecated,
|
|
20
|
+
THREAD_LIST_DEPRECATED_AT,
|
|
21
|
+
} from "../../../middleware/deprecation.js";
|
|
26
22
|
|
|
27
23
|
type Env = { Bindings: Bindings; Variables: AppVariables };
|
|
28
24
|
|
|
@@ -48,85 +44,6 @@ const PublicPostContentQuerySchema = z.object({
|
|
|
48
44
|
content: z.enum(["markdown"]).optional(),
|
|
49
45
|
});
|
|
50
46
|
|
|
51
|
-
export type PublicPostBaseResponse = {
|
|
52
|
-
id: string;
|
|
53
|
-
format: Post["format"];
|
|
54
|
-
status: "published";
|
|
55
|
-
visibility: Post["visibility"];
|
|
56
|
-
slug: string;
|
|
57
|
-
permalink: string;
|
|
58
|
-
title?: string | null;
|
|
59
|
-
url?: string | null;
|
|
60
|
-
sourceName?: string | null;
|
|
61
|
-
sourceUrl?: string | null;
|
|
62
|
-
quoteText: string | null;
|
|
63
|
-
summary: string | null;
|
|
64
|
-
rating: number | null;
|
|
65
|
-
previewKind: string | null;
|
|
66
|
-
previewProvider: string | null;
|
|
67
|
-
previewImageUrl: string | null;
|
|
68
|
-
replyToId: string | null;
|
|
69
|
-
threadId: string;
|
|
70
|
-
/**
|
|
71
|
-
* BCP 47 content language, or null on a post written before the site
|
|
72
|
-
* enabled multilingual content.
|
|
73
|
-
*/
|
|
74
|
-
language: string | null;
|
|
75
|
-
/**
|
|
76
|
-
* Shared by every translation of this Thread. Null when the Thread has no
|
|
77
|
-
* translations.
|
|
78
|
-
*/
|
|
79
|
-
translationGroupId: string | null;
|
|
80
|
-
/** Reply published without announcing its Thread. Always false on roots. */
|
|
81
|
-
quietReply: boolean;
|
|
82
|
-
pinnedAt: number | null;
|
|
83
|
-
featuredAt: number | null;
|
|
84
|
-
publishedAt: number | null;
|
|
85
|
-
/** Root only: newest post in the Thread, quiet replies excluded. */
|
|
86
|
-
lastActivityAt: number;
|
|
87
|
-
/** Root only: newest post in the Thread, quiet replies included. */
|
|
88
|
-
threadUpdatedAt: number;
|
|
89
|
-
createdAt: number;
|
|
90
|
-
updatedAt: number;
|
|
91
|
-
attachments: ReturnType<typeof toApiAttachment>[];
|
|
92
|
-
collections: {
|
|
93
|
-
id: string;
|
|
94
|
-
slug: string;
|
|
95
|
-
title: string;
|
|
96
|
-
url: string;
|
|
97
|
-
}[];
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export type PublicPostRenderedResponse = PublicPostBaseResponse & {
|
|
101
|
-
bodyHtml: string | null;
|
|
102
|
-
bodyText: string | null;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export type PublicPostMarkdownResponse = PublicPostBaseResponse & {
|
|
106
|
-
bodyMarkdown: string | null;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export type PublicPostResponse =
|
|
110
|
-
PublicPostRenderedResponse | PublicPostMarkdownResponse;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* The public Markdown for a post, or null for a historical body that isn't
|
|
114
|
-
* TipTap JSON. One unreadable row answers null and is logged, rather than
|
|
115
|
-
* failing the whole listing; `bodyHtml` still falls back to stored HTML.
|
|
116
|
-
*/
|
|
117
|
-
function toPublicBodyMarkdown(postId: string, body: string): string | null {
|
|
118
|
-
try {
|
|
119
|
-
return tiptapJsonToMarkdown(body);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
// eslint-disable-next-line no-console -- A skipped body must leave a trace
|
|
122
|
-
console.error(
|
|
123
|
-
`Couldn't convert the body of post ${postId} to Markdown`,
|
|
124
|
-
error,
|
|
125
|
-
);
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
47
|
function isPublicDetailVisible(post: Post | null): post is Post {
|
|
131
48
|
return (
|
|
132
49
|
post !== null &&
|
|
@@ -135,208 +52,97 @@ function isPublicDetailVisible(post: Post | null): post is Post {
|
|
|
135
52
|
);
|
|
136
53
|
}
|
|
137
54
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
threadUpdatedAt: post.threadUpdatedAt,
|
|
195
|
-
createdAt: post.createdAt,
|
|
196
|
-
updatedAt: post.updatedAt,
|
|
197
|
-
attachments: mediaList.map((media) =>
|
|
198
|
-
toApiAttachment(
|
|
199
|
-
media,
|
|
200
|
-
r2PublicUrl,
|
|
201
|
-
imageTransformUrl,
|
|
202
|
-
s3PublicUrl,
|
|
203
|
-
localPublicUrl,
|
|
204
|
-
sitePathPrefix,
|
|
205
|
-
),
|
|
206
|
-
),
|
|
207
|
-
collections: threadCollections.map((collection) => ({
|
|
208
|
-
id: collection.id,
|
|
209
|
-
slug: collection.slug,
|
|
210
|
-
title: collection.title,
|
|
211
|
-
url: toPublicPath(getCollectionPagePath(collection.slug), sitePathPrefix),
|
|
212
|
-
})),
|
|
213
|
-
};
|
|
214
|
-
const contentFields =
|
|
215
|
-
options?.content === "markdown"
|
|
216
|
-
? {
|
|
217
|
-
bodyMarkdown: post.body
|
|
218
|
-
? toPublicBodyMarkdown(post.id, post.body)
|
|
219
|
-
: null,
|
|
220
|
-
}
|
|
221
|
-
: {
|
|
222
|
-
bodyHtml: post.bodyHtml,
|
|
223
|
-
bodyText: post.bodyText,
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
if (post.format === "quote") {
|
|
227
|
-
return {
|
|
228
|
-
...base,
|
|
229
|
-
...contentFields,
|
|
230
|
-
sourceName: post.title,
|
|
231
|
-
sourceUrl: post.url,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return {
|
|
236
|
-
...base,
|
|
237
|
-
...contentFields,
|
|
238
|
-
title: post.title,
|
|
239
|
-
url: post.url,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
publicPostsApiRoutes.get("/", async (c) => {
|
|
244
|
-
const { format, lang, collection, sort, cursor, limit, content } =
|
|
245
|
-
parseValidated(ListPublicPostsQuerySchema, c.req.query());
|
|
246
|
-
|
|
247
|
-
// Resolve collection slug(s) — accepts comma-separated (e.g. "tech,art")
|
|
248
|
-
// or "+" separated (e.g. "tech+art"), matching the page URL convention.
|
|
249
|
-
let collectionIds: string[] | undefined;
|
|
250
|
-
let sortOrder: "newest" | "oldest" | "rating_desc" | undefined;
|
|
251
|
-
|
|
252
|
-
if (collection) {
|
|
253
|
-
// Normalize: commas → "+" so resolveSelection handles both forms
|
|
254
|
-
const slugExpression = collection.replace(/,/g, "+");
|
|
255
|
-
const selection =
|
|
256
|
-
await c.var.services.collections.resolveSelection(slugExpression);
|
|
257
|
-
if (!selection) {
|
|
258
|
-
return c.json({ posts: [], nextCursor: null });
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
collectionIds = selection.collections.map((col) => col.id);
|
|
262
|
-
|
|
263
|
-
// Determine sort order: single collection uses its configured default,
|
|
264
|
-
// aggregate selections default to "newest"
|
|
265
|
-
const isAggregate = selection.collections.length > 1;
|
|
266
|
-
const primaryCollection = selection.collections[0];
|
|
267
|
-
if (!primaryCollection) {
|
|
268
|
-
return c.json({ posts: [], nextCursor: null });
|
|
269
|
-
}
|
|
270
|
-
const requestedDefaultSort = isAggregate
|
|
271
|
-
? "newest"
|
|
272
|
-
: primaryCollection.sortOrder;
|
|
273
|
-
|
|
274
|
-
const ratedThreadCount =
|
|
275
|
-
await c.var.services.posts.countCollectionThreadRootsUpToForCollections(
|
|
276
|
-
collectionIds,
|
|
277
|
-
{
|
|
278
|
-
status: "published",
|
|
279
|
-
excludePrivate: true,
|
|
280
|
-
excludeLatestHidden: true,
|
|
281
|
-
rootFormat: format,
|
|
282
|
-
hasRating: true,
|
|
283
|
-
},
|
|
284
|
-
2,
|
|
55
|
+
/**
|
|
56
|
+
* Deprecated in 0.9 for `GET /api/public/threads`, which lists the same Thread
|
|
57
|
+
* roots with the archive's filters and the homepage's defaults. Answers as it
|
|
58
|
+
* always has until 1.0.1 removes it.
|
|
59
|
+
*/
|
|
60
|
+
publicPostsApiRoutes.get(
|
|
61
|
+
"/",
|
|
62
|
+
deprecated(THREAD_LIST_DEPRECATED_AT, "/api/public/threads"),
|
|
63
|
+
async (c) => {
|
|
64
|
+
const { format, lang, collection, sort, cursor, limit, content } =
|
|
65
|
+
parseValidated(ListPublicPostsQuerySchema, c.req.query());
|
|
66
|
+
|
|
67
|
+
// Resolve collection slug(s) — accepts comma-separated (e.g. "tech,art")
|
|
68
|
+
// or "+" separated (e.g. "tech+art"), matching the page URL convention.
|
|
69
|
+
let collectionIds: string[] | undefined;
|
|
70
|
+
let sortOrder: "newest" | "oldest" | "rating_desc" | undefined;
|
|
71
|
+
|
|
72
|
+
if (collection) {
|
|
73
|
+
// Normalize: commas → "+" so resolveSelection handles both forms
|
|
74
|
+
const slugExpression = collection.replace(/,/g, "+");
|
|
75
|
+
const selection =
|
|
76
|
+
await c.var.services.collections.resolveSelection(slugExpression);
|
|
77
|
+
if (!selection) {
|
|
78
|
+
return c.json({ posts: [], nextCursor: null });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
collectionIds = selection.collections.map((col) => col.id);
|
|
82
|
+
|
|
83
|
+
// Determine sort order: single collection uses its configured default,
|
|
84
|
+
// aggregate selections default to "newest"
|
|
85
|
+
const isAggregate = selection.collections.length > 1;
|
|
86
|
+
const primaryCollection = selection.collections[0];
|
|
87
|
+
if (!primaryCollection) {
|
|
88
|
+
return c.json({ posts: [], nextCursor: null });
|
|
89
|
+
}
|
|
90
|
+
const requestedDefaultSort = isAggregate
|
|
91
|
+
? "newest"
|
|
92
|
+
: primaryCollection.sortOrder;
|
|
93
|
+
|
|
94
|
+
const ratedThreadCount =
|
|
95
|
+
await c.var.services.posts.countCollectionThreadRootsUpToForCollections(
|
|
96
|
+
collectionIds,
|
|
97
|
+
{
|
|
98
|
+
status: "published",
|
|
99
|
+
excludePrivate: true,
|
|
100
|
+
excludeLatestHidden: true,
|
|
101
|
+
rootFormat: format,
|
|
102
|
+
hasRating: true,
|
|
103
|
+
},
|
|
104
|
+
2,
|
|
105
|
+
);
|
|
106
|
+
const showRatingSort = supportsCollectionRatingSort(ratedThreadCount);
|
|
107
|
+
const defaultSort = resolveCollectionSortOrder(
|
|
108
|
+
undefined,
|
|
109
|
+
requestedDefaultSort,
|
|
110
|
+
showRatingSort,
|
|
285
111
|
);
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
undefined,
|
|
289
|
-
requestedDefaultSort,
|
|
290
|
-
showRatingSort,
|
|
291
|
-
);
|
|
292
|
-
sortOrder = resolveCollectionSortOrder(sort, defaultSort, showRatingSort);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const posts = collectionIds
|
|
296
|
-
? await c.var.services.posts.listCollectionThreadRootsForCollections(
|
|
297
|
-
collectionIds,
|
|
298
|
-
{
|
|
299
|
-
status: "published",
|
|
300
|
-
excludePrivate: true,
|
|
301
|
-
excludeLatestHidden: true,
|
|
302
|
-
rootFormat: format,
|
|
303
|
-
lang,
|
|
304
|
-
sortOrder,
|
|
305
|
-
cursor: cursor ?? undefined,
|
|
306
|
-
limit,
|
|
307
|
-
},
|
|
308
|
-
)
|
|
309
|
-
: await c.var.services.posts.list({
|
|
310
|
-
format,
|
|
311
|
-
lang,
|
|
312
|
-
status: "published",
|
|
313
|
-
cursor: cursor ?? undefined,
|
|
314
|
-
limit,
|
|
315
|
-
excludePrivate: true,
|
|
316
|
-
excludeLatestHidden: true,
|
|
317
|
-
excludeReplies: true,
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
const postIds = posts.map((post) => post.id);
|
|
321
|
-
const [mediaMap, collectionsMap] = await Promise.all([
|
|
322
|
-
c.var.services.media.getByPostIds(postIds),
|
|
323
|
-
c.var.services.collections.getCollectionsByPostIds(postIds),
|
|
324
|
-
]);
|
|
112
|
+
sortOrder = resolveCollectionSortOrder(sort, defaultSort, showRatingSort);
|
|
113
|
+
}
|
|
325
114
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
115
|
+
const { posts, nextCursor } = collectionIds
|
|
116
|
+
? await c.var.services.posts.listCollectionThreadRootPage(
|
|
117
|
+
collectionIds,
|
|
118
|
+
{
|
|
119
|
+
status: "published",
|
|
120
|
+
excludePrivate: true,
|
|
121
|
+
excludeLatestHidden: true,
|
|
122
|
+
rootFormat: format,
|
|
123
|
+
lang,
|
|
124
|
+
sortOrder,
|
|
125
|
+
},
|
|
126
|
+
{ cursor, limit },
|
|
127
|
+
)
|
|
128
|
+
: await c.var.services.posts.listPage(
|
|
129
|
+
{
|
|
130
|
+
format,
|
|
131
|
+
lang,
|
|
132
|
+
status: "published",
|
|
133
|
+
excludePrivate: true,
|
|
134
|
+
excludeLatestHidden: true,
|
|
135
|
+
excludeReplies: true,
|
|
136
|
+
},
|
|
137
|
+
{ cursor, limit },
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return c.json({
|
|
141
|
+
posts: await loadPublicPostResponses(c.var, posts, { content }),
|
|
142
|
+
nextCursor,
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
);
|
|
340
146
|
|
|
341
147
|
publicPostsApiRoutes.get("/:slug", async (c) => {
|
|
342
148
|
const { content } = parseValidated(
|
|
@@ -350,14 +156,6 @@ publicPostsApiRoutes.get("/:slug", async (c) => {
|
|
|
350
156
|
throw new NotFoundError("Post");
|
|
351
157
|
}
|
|
352
158
|
|
|
353
|
-
const [
|
|
354
|
-
|
|
355
|
-
c.var.services.collections.getCollectionsByPostId(post.id),
|
|
356
|
-
]);
|
|
357
|
-
|
|
358
|
-
return c.json(
|
|
359
|
-
toPublicPost(post, mediaList, threadCollections, c.var.appConfig, {
|
|
360
|
-
content,
|
|
361
|
-
}),
|
|
362
|
-
);
|
|
159
|
+
const [response] = await loadPublicPostResponses(c.var, [post], { content });
|
|
160
|
+
return c.json(response);
|
|
363
161
|
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public Threads API Routes
|
|
3
|
+
*
|
|
4
|
+
* The reader's view of Threads: what the site shows anyone, in the reading
|
|
5
|
+
* view. A list left unfiltered is the homepage's — Threads hidden from Latest
|
|
6
|
+
* left out, newest activity first, pins on top — and takes the archive's
|
|
7
|
+
* filters to narrow or widen it.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Hono } from "hono";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import type { Bindings } from "../../../types.js";
|
|
13
|
+
import { THREAD_SORTS } from "../../../types.js";
|
|
14
|
+
import type { AppVariables } from "../../../types/app-context.js";
|
|
15
|
+
import { ContentLanguageSchema, parseValidated } from "../../../lib/schemas.js";
|
|
16
|
+
import { NotFoundError } from "../../../lib/errors.js";
|
|
17
|
+
import { loadPublicPostResponses } from "../../../lib/api-public-posts.js";
|
|
18
|
+
import { loadPublicThreadResponses } from "../../../lib/api-threads.js";
|
|
19
|
+
import {
|
|
20
|
+
parseThreadInclude,
|
|
21
|
+
parseThreadSelection,
|
|
22
|
+
} from "../../../lib/thread-query.js";
|
|
23
|
+
import { requirePublicApiEnabled } from "../../../middleware/public-content-access.js";
|
|
24
|
+
|
|
25
|
+
type Env = { Bindings: Bindings; Variables: AppVariables };
|
|
26
|
+
|
|
27
|
+
export const publicThreadsApiRoutes = new Hono<Env>();
|
|
28
|
+
|
|
29
|
+
publicThreadsApiRoutes.use("*", requirePublicApiEnabled());
|
|
30
|
+
|
|
31
|
+
const ContentSchema = z.enum(["markdown"]).optional();
|
|
32
|
+
|
|
33
|
+
/** The list's own parameters; everything else is a filter dimension. */
|
|
34
|
+
const ListThreadsQuerySchema = z.object({
|
|
35
|
+
lang: ContentLanguageSchema.optional(),
|
|
36
|
+
sort: z.enum(THREAD_SORTS).optional(),
|
|
37
|
+
include: z.string().optional(),
|
|
38
|
+
cursor: z.string().optional(),
|
|
39
|
+
limit: z.coerce.number().int().min(1).max(100).optional().default(20),
|
|
40
|
+
content: ContentSchema,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const LIST_PARAMS = [
|
|
44
|
+
"lang",
|
|
45
|
+
"sort",
|
|
46
|
+
"include",
|
|
47
|
+
"cursor",
|
|
48
|
+
"limit",
|
|
49
|
+
"content",
|
|
50
|
+
] as const;
|
|
51
|
+
|
|
52
|
+
const GetThreadQuerySchema = z.object({
|
|
53
|
+
include: z.string().optional(),
|
|
54
|
+
content: ContentSchema,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const ListThreadPostsQuerySchema = z.object({
|
|
58
|
+
cursor: z.string().optional(),
|
|
59
|
+
limit: z.coerce.number().int().min(1).max(100).optional().default(100),
|
|
60
|
+
content: ContentSchema,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
publicThreadsApiRoutes.get("/", async (c) => {
|
|
64
|
+
const query = parseValidated(ListThreadsQuerySchema, c.req.query());
|
|
65
|
+
const { fold } = parseThreadInclude(query.include);
|
|
66
|
+
const parsed = await parseThreadSelection(
|
|
67
|
+
(key) => c.req.query(key),
|
|
68
|
+
Object.keys(c.req.query()),
|
|
69
|
+
{
|
|
70
|
+
allow: LIST_PARAMS,
|
|
71
|
+
audience: "reader",
|
|
72
|
+
loadCollections: () => c.var.services.collections.list(),
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
if (parsed.kind === "empty") {
|
|
76
|
+
return c.json({ threads: [], nextCursor: null });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const { threads, nextCursor } = await c.var.services.threads.listThreads(
|
|
80
|
+
{
|
|
81
|
+
audience: "reader",
|
|
82
|
+
selection: parsed.selection,
|
|
83
|
+
includeHidden: parsed.includeHidden,
|
|
84
|
+
lang: query.lang,
|
|
85
|
+
sort: query.sort,
|
|
86
|
+
fold,
|
|
87
|
+
},
|
|
88
|
+
{ cursor: query.cursor, limit: query.limit },
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
return c.json({
|
|
92
|
+
threads: await loadPublicThreadResponses(c.var, threads, {
|
|
93
|
+
content: query.content,
|
|
94
|
+
}),
|
|
95
|
+
nextCursor,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
publicThreadsApiRoutes.get("/:slug", async (c) => {
|
|
100
|
+
const { include, content } = parseValidated(
|
|
101
|
+
GetThreadQuerySchema,
|
|
102
|
+
c.req.query(),
|
|
103
|
+
);
|
|
104
|
+
const root = await c.var.services.threads.findRoot(
|
|
105
|
+
{ slug: c.req.param("slug") },
|
|
106
|
+
"reader",
|
|
107
|
+
);
|
|
108
|
+
if (!root) throw new NotFoundError("Thread");
|
|
109
|
+
|
|
110
|
+
const summaries = await c.var.services.threads.summarize(
|
|
111
|
+
[root],
|
|
112
|
+
parseThreadInclude(include),
|
|
113
|
+
);
|
|
114
|
+
const [thread] = await loadPublicThreadResponses(c.var, summaries, {
|
|
115
|
+
content,
|
|
116
|
+
});
|
|
117
|
+
if (!thread) throw new NotFoundError("Thread");
|
|
118
|
+
return c.json(thread);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
publicThreadsApiRoutes.get("/:slug/posts", async (c) => {
|
|
122
|
+
const { cursor, limit, content } = parseValidated(
|
|
123
|
+
ListThreadPostsQuerySchema,
|
|
124
|
+
c.req.query(),
|
|
125
|
+
);
|
|
126
|
+
const root = await c.var.services.threads.findRoot(
|
|
127
|
+
{ slug: c.req.param("slug") },
|
|
128
|
+
"reader",
|
|
129
|
+
);
|
|
130
|
+
if (!root) throw new NotFoundError("Thread");
|
|
131
|
+
|
|
132
|
+
const { posts, nextCursor } = await c.var.services.threads.listPosts(
|
|
133
|
+
root.id,
|
|
134
|
+
{ audience: "reader" },
|
|
135
|
+
{ cursor, limit },
|
|
136
|
+
);
|
|
137
|
+
return c.json({
|
|
138
|
+
posts: await loadPublicPostResponses(c.var, posts, { content }),
|
|
139
|
+
nextCursor,
|
|
140
|
+
});
|
|
141
|
+
});
|