@jant/core 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/bin/commands/site/import.js +2 -1
  2. package/dist/{app-CbOZ2Irh.js → app-C8dETvgL.js} +1429 -681
  3. package/dist/client/.vite/manifest.json +72 -83
  4. package/dist/client/_assets/chunks/{confirm-CMe01lne.js → confirm-BQebcuNB.js} +1 -1
  5. package/dist/client/_assets/chunks/{create-editor-hWapNE40.js → create-editor-B8KuszlS.js} +38 -38
  6. package/dist/client/_assets/chunks/footnote-rail-DUrqz0Py.js +2 -0
  7. package/dist/client/_assets/chunks/{jant-locale-picker-2L4rkDaz.js → jant-locale-picker-CLq0iKDH.js} +1 -1
  8. package/dist/client/_assets/chunks/lit-BN4mrI3j.js +2 -0
  9. package/dist/client/_assets/chunks/{settings-paths-BBVT8zKj.js → settings-paths-_fry4yWW.js} +1 -1
  10. package/dist/client/_assets/chunks/{slug-format-BuCPjSrB.js → slug-format-bcJ2ozr4.js} +1 -1
  11. package/dist/client/_assets/chunks/{sortable-list-DJXwkaOv.js → sortable-list-Bz2Na2E9.js} +2 -2
  12. package/dist/client/_assets/chunks/{unsafe-html-CWos3v6N.js → unsafe-html-OJ9m154w.js} +1 -1
  13. package/dist/client/_assets/chunks/unsafe-svg-DVJ4NPcb.js +1 -0
  14. package/dist/client/_assets/{client-D8Rrsd73.css → client-CoNHvipV.css} +1 -1
  15. package/dist/client/_assets/{client-auth-CsUGM718.js → client-auth-CbnZkLJ6.js} +99 -129
  16. package/dist/client/_assets/client-author-2WYBkgni.css +2 -0
  17. package/dist/client/_assets/{client-compose-BB4U7Wz0.js → client-compose-DYtDlYm-.js} +248 -244
  18. package/dist/client/_assets/{client-manage-CI9-eh-8.js → client-manage-BODyYP5Z.js} +157 -157
  19. package/dist/client/_assets/client-pq6sVS7y.js +354 -0
  20. package/dist/client/_assets/{client-settings-BnGPuqwc.js → client-settings-DDpe_tXJ.js} +166 -166
  21. package/dist/client/_assets/client-share-B9OsXx9p.js +149 -0
  22. package/dist/{constants-DEgyqWDl.js → constants-C2CdWAqt.js} +55 -5
  23. package/dist/index.js +1 -1
  24. package/dist/node.js +2 -2
  25. package/package.json +2 -1
  26. package/src/client/components/compose-types.ts +5 -1
  27. package/src/client/components/jant-compose-dialog.ts +25 -4
  28. package/src/client/components/jant-media-lightbox.ts +18 -3
  29. package/src/client/components/jant-nav-manager.ts +2 -0
  30. package/src/client/components/jant-post-menu.ts +42 -89
  31. package/src/client/components/nav-manager-types.ts +2 -0
  32. package/src/client/components/settings-types.ts +1 -1
  33. package/src/client/list-views.ts +382 -0
  34. package/src/client/media-lightbox-events.ts +12 -0
  35. package/src/client/runtime-paths.ts +12 -0
  36. package/src/client/share-capture.ts +63 -0
  37. package/src/client/share-launch.ts +36 -9
  38. package/src/client/tiptap/create-editor.ts +4 -0
  39. package/src/client/tiptap/embed-node.ts +3 -1
  40. package/src/client/tiptap/html-block-node.ts +3 -1
  41. package/src/client/tiptap/image-node.ts +3 -1
  42. package/src/client/view-confirm.ts +32 -4
  43. package/src/client.ts +1 -0
  44. package/src/db/migrations/0037_round_post.sql +16 -0
  45. package/src/db/migrations/0038_flashy_changeling.sql +15 -0
  46. package/src/db/migrations/0039_mixed_sister_grimm.sql +1 -0
  47. package/src/db/migrations/meta/0037_snapshot.json +2932 -0
  48. package/src/db/migrations/meta/0038_snapshot.json +2924 -0
  49. package/src/db/migrations/meta/0039_snapshot.json +2931 -0
  50. package/src/db/migrations/meta/_journal.json +21 -0
  51. package/src/db/migrations/pg/0035_flimsy_outlaw_kid.sql +3 -0
  52. package/src/db/migrations/pg/0036_milky_wolverine.sql +5 -0
  53. package/src/db/migrations/pg/0037_fuzzy_hammerhead.sql +1 -0
  54. package/src/db/migrations/pg/meta/0035_snapshot.json +3773 -0
  55. package/src/db/migrations/pg/meta/0036_snapshot.json +3766 -0
  56. package/src/db/migrations/pg/meta/0037_snapshot.json +3772 -0
  57. package/src/db/migrations/pg/meta/_journal.json +21 -0
  58. package/src/db/pg/schema.ts +1 -0
  59. package/src/db/post-visibility.ts +37 -6
  60. package/src/db/schema.ts +5 -2
  61. package/src/i18n/locales/glossary.zh-Hans.yml +4 -0
  62. package/src/i18n/locales/glossary.zh-Hant.yml +4 -0
  63. package/src/i18n/locales/public/en.po +21 -7
  64. package/src/i18n/locales/public/en.ts +1 -1
  65. package/src/i18n/locales/public/zh-Hans.po +20 -6
  66. package/src/i18n/locales/public/zh-Hans.ts +1 -1
  67. package/src/i18n/locales/public/zh-Hant.po +20 -6
  68. package/src/i18n/locales/public/zh-Hant.ts +1 -1
  69. package/src/i18n/locales/settings/en.po +10 -0
  70. package/src/i18n/locales/settings/en.ts +1 -1
  71. package/src/i18n/locales/settings/zh-Hans.po +10 -0
  72. package/src/i18n/locales/settings/zh-Hans.ts +1 -1
  73. package/src/i18n/locales/settings/zh-Hant.po +10 -0
  74. package/src/i18n/locales/settings/zh-Hant.ts +1 -1
  75. package/src/lib/api-public-posts.ts +10 -0
  76. package/src/lib/feed-policy.ts +2 -2
  77. package/src/lib/filter-dimensions.ts +11 -4
  78. package/src/lib/hugo-markdown.ts +7 -0
  79. package/src/lib/icons.ts +2 -0
  80. package/src/lib/link-preview.ts +499 -0
  81. package/src/lib/list-views.ts +117 -0
  82. package/src/lib/markdown-manager.ts +40 -1
  83. package/src/lib/navigation.ts +1 -1
  84. package/src/lib/share-card.ts +4 -3
  85. package/src/lib/thread-query.ts +6 -2
  86. package/src/lib/timeline.ts +12 -11
  87. package/src/lib/url-fetch.ts +291 -74
  88. package/src/lib/view-buffer.ts +2 -2
  89. package/src/lib/view-counting.ts +7 -6
  90. package/src/lib/view-token.ts +29 -7
  91. package/src/lib/view.ts +17 -0
  92. package/src/middleware/view-counter.ts +10 -5
  93. package/src/preset.css +5 -3
  94. package/src/routes/api/search.ts +1 -1
  95. package/src/routes/dash/settings.tsx +1 -1
  96. package/src/routes/feed/sitemap.ts +1 -1
  97. package/src/routes/pages/archive.tsx +25 -19
  98. package/src/routes/pages/collection.tsx +3 -3
  99. package/src/routes/pages/page.tsx +16 -4
  100. package/src/routes/pages/search.tsx +3 -3
  101. package/src/routes/view-confirm.ts +23 -15
  102. package/src/services/collection.ts +1 -1
  103. package/src/services/export-theme/assets/client-site.js +19 -19
  104. package/src/services/export-theme/layouts/archive/list.html +4 -2
  105. package/src/services/export-theme/layouts/partials/collection-members.html +4 -3
  106. package/src/services/export-theme/layouts/partials/featured-members.html +3 -3
  107. package/src/services/export-theme/layouts/partials/head.html +2 -0
  108. package/src/services/export-theme/layouts/partials/latest-members.html +4 -4
  109. package/src/services/export-theme/layouts/partials/post-card.html +1 -9
  110. package/src/services/export-theme/layouts/partials/reply.html +1 -9
  111. package/src/services/export-theme/layouts/partials/smart-collection-members.html +4 -3
  112. package/src/services/export-theme/layouts/post/list.html +1 -9
  113. package/src/services/export-theme/styles/main.css +2 -26
  114. package/src/services/export.ts +10 -3
  115. package/src/services/mcp.ts +5 -5
  116. package/src/services/navigation.ts +9 -4
  117. package/src/services/post.ts +102 -112
  118. package/src/services/search.ts +22 -7
  119. package/src/services/smart-collection.ts +3 -3
  120. package/src/services/stats.ts +12 -5
  121. package/src/services/thread.ts +6 -2
  122. package/src/styles/components-author.css +69 -7
  123. package/src/styles/tokens.css +28 -29
  124. package/src/styles/ui-author.css +140 -353
  125. package/src/styles/ui.css +34 -32
  126. package/src/types/constants.ts +68 -4
  127. package/src/types/entities.ts +1 -0
  128. package/src/types/views.ts +2 -0
  129. package/src/ui/compose/ComposeDialog.tsx +20 -1
  130. package/src/ui/dash/StatusBadge.tsx +11 -0
  131. package/src/ui/dash/appearance/FontThemeContent.tsx +1 -1
  132. package/src/ui/dash/appearance/NavigationContent.tsx +8 -0
  133. package/src/ui/dash/settings/StatsContent.tsx +29 -29
  134. package/src/ui/feed/LinkCard.tsx +19 -2
  135. package/src/ui/feed/PostStatusBadges.tsx +19 -3
  136. package/src/ui/feed/TimelineFeed.tsx +3 -0
  137. package/src/ui/font-themes.ts +32 -15
  138. package/src/ui/pages/ArchivePage.tsx +1 -0
  139. package/src/ui/shared/PostFooter.tsx +1 -22
  140. package/src/ui/shared/custom-icons.ts +5 -5
  141. package/dist/client/_assets/chunks/footnote-rail-9zwl6jtV.js +0 -2
  142. package/dist/client/_assets/chunks/lit-Bw_voPoW.js +0 -2
  143. package/dist/client/_assets/chunks/runtime-paths-y0_gHowM.js +0 -1
  144. package/dist/client/_assets/chunks/unsafe-svg-CUrgo4Xg.js +0 -1
  145. package/dist/client/_assets/client-BO8GOFfT.js +0 -354
  146. package/dist/client/_assets/client-author-QPm1whbO.css +0 -2
  147. package/dist/client/_assets/client-share-C59mOLJ1.js +0 -149
@@ -20,12 +20,13 @@ import { ID_PREFIX, isTypeId } from "./ids.js";
20
20
  import { canonicalSource } from "./referrer-aliases.js";
21
21
 
22
22
  /**
23
- * What the page a route rendered counts as: a post, a collection or a smart
24
- * collection, by id, so a count survives a change of address and an alias
25
- * and its canonical path are one page; or any other public page — the home
26
- * page, the archive, an aggregate selection — by its path. Routes set it on
27
- * the context (`viewTarget`) and `middleware/view-counter.ts` reads it after
28
- * the response.
23
+ * What the page a route rendered counts as: a Thread (by its root's id — a
24
+ * lone post is a Thread of one), a collection or a smart collection, by id,
25
+ * so a count survives a change of address and an alias and its canonical
26
+ * path are one page; or any other public page — the home page, the archive,
27
+ * an aggregate selection — by its path. Routes set it on the context
28
+ * (`viewTarget`) and `middleware/view-counter.ts` reads it after the
29
+ * response.
29
30
  */
30
31
  export type ViewTarget =
31
32
  | { kind: "post" | "collection" | "smartCollection"; id: string }
@@ -17,6 +17,12 @@
17
17
  * fresh and is this site's, and counts the view with the day and hour of
18
18
  * that moment.
19
19
  *
20
+ * A list page's token also names the Threads the page shows whole
21
+ * (`data-view-unit`, `lib/list-views.ts`). The browser posts the token again,
22
+ * followed by the ones a reader read there in full, and only those the token
23
+ * names are counted: a token for the home page cannot count a post that was
24
+ * never on it.
25
+ *
20
26
  * The time in the token is a ten-minute slot, not a timestamp, so every
21
27
  * response for the same page and source within a slot carries the same
22
28
  * token: the HTML stays byte-identical across readers, as it was. A token is
@@ -42,8 +48,11 @@ export const VIEW_TOKEN_SLOTS_ACCEPTED = 4;
42
48
  /** Hex characters of the HMAC kept: 128 bits. */
43
49
  const SIGNATURE_LENGTH = 32;
44
50
 
45
- /** Longer than any token this module writes; a longer one is not ours. */
46
- const TOKEN_MAX_LENGTH = 2048;
51
+ /**
52
+ * Longer than any token this module writes, a list page's hundred Threads
53
+ * included; a longer one is not ours.
54
+ */
55
+ const TOKEN_MAX_LENGTH = 8192;
47
56
 
48
57
  /** What a token says about the view. */
49
58
  export interface ViewTokenClaims {
@@ -52,6 +61,11 @@ export interface ViewTokenClaims {
52
61
  page: string;
53
62
  /** The referrer key: a host or tag, the site itself, or `""`. */
54
63
  referrer: string;
64
+ /**
65
+ * The Threads, by root id, the page shows whole in its lists: the ones a
66
+ * report of Threads read may name. Empty for any other page.
67
+ */
68
+ units: string[];
55
69
  }
56
70
 
57
71
  function toBase64Url(text: string): string {
@@ -100,12 +114,17 @@ async function signature(secret: string, payload: string): Promise<string> {
100
114
  * The token for a view, to be written into the page.
101
115
  *
102
116
  * @param secret - The deployment's `AUTH_SECRET`
103
- * @param claims - Which page, and where the reader came from
117
+ * @param claims - Which page, where the reader came from, and the Threads
118
+ * it shows whole
104
119
  * @param timestamp - Unix timestamp in seconds, now
105
120
  * @returns `payload.signature`, both URL-safe
106
121
  * @example
107
122
  * ```ts
108
- * const token = await signViewToken(secret, { siteId, page: post.id, referrer: "" }, now());
123
+ * const token = await signViewToken(
124
+ * secret,
125
+ * { siteId, page: post.threadId, referrer: "", units: [] },
126
+ * now(),
127
+ * );
109
128
  * ```
110
129
  */
111
130
  export async function signViewToken(
@@ -119,6 +138,7 @@ export async function signViewToken(
119
138
  p: claims.page,
120
139
  r: claims.referrer,
121
140
  t: viewTokenSlot(timestamp),
141
+ ...(claims.units.length > 0 ? { l: claims.units } : {}),
122
142
  }),
123
143
  );
124
144
  return `${payload}.${await signature(secret, payload)}`;
@@ -162,16 +182,18 @@ export async function verifyViewToken(
162
182
  return null;
163
183
  }
164
184
  if (typeof parsed !== "object" || parsed === null) return null;
165
- const { s, p, r, t } = parsed as Record<string, unknown>;
185
+ const { s, p, r, t, l = [] } = parsed as Record<string, unknown>;
166
186
  if (
167
187
  typeof s !== "string" ||
168
188
  typeof p !== "string" ||
169
189
  typeof r !== "string" ||
170
- typeof t !== "number"
190
+ typeof t !== "number" ||
191
+ !Array.isArray(l) ||
192
+ !l.every((unit) => typeof unit === "string")
171
193
  ) {
172
194
  return null;
173
195
  }
174
196
  const age = viewTokenSlot(timestamp) - t;
175
197
  if (age < 0 || age >= VIEW_TOKEN_SLOTS_ACCEPTED) return null;
176
- return { siteId: s, page: p, referrer: r };
198
+ return { siteId: s, page: p, referrer: r, units: l as string[] };
177
199
  }
package/src/lib/view.ts CHANGED
@@ -36,6 +36,7 @@ import {
36
36
  } from "./time.js";
37
37
  import { getCollectionPagePath } from "./collection-paths.js";
38
38
  import { getMediaUrl, getImageUrl, getPublicUrlForProvider } from "./image.js";
39
+ import { getLinkPreviewIconImageOptions } from "./link-preview.js";
39
40
  import {
40
41
  extractSummaryHtml,
41
42
  extractBodyText,
@@ -404,6 +405,22 @@ export function toPostView(
404
405
  { width: 1280, quality: 80, format: "auto", fit: "scale-down" },
405
406
  )
406
407
  : undefined,
408
+ previewIconUrl: post.previewIconKey
409
+ ? getImageUrl(
410
+ getMediaUrl(
411
+ post.previewIconKey,
412
+ getPublicUrlForProvider(
413
+ ctx.storageDriver ?? "r2",
414
+ ctx.r2PublicUrl,
415
+ ctx.s3PublicUrl,
416
+ ctx.localPublicUrl,
417
+ ),
418
+ ctx.sitePathPrefix,
419
+ ),
420
+ ctx.imageTransformUrl,
421
+ getLinkPreviewIconImageOptions(post.previewIconKey),
422
+ )
423
+ : undefined,
407
424
  publishedAt: toISOString(publishedAt),
408
425
  publishedAtFormatted: formatDate(publishedAt, timeZone),
409
426
  publishedAtTime: formatTime(publishedAt, timeZone),
@@ -3,7 +3,9 @@
3
3
  *
4
4
  * Runs after the route and, when the route named what it rendered
5
5
  * (`c.var.viewTarget`) and the request was one reader opening that page,
6
- * writes a signed view token into the page's `<head>`. The view is counted
6
+ * writes a signed view token into the page's `<head>`. On a list page the
7
+ * token also names the Threads the page shows whole, read from the marks the
8
+ * feed left on them (`lib/list-views.ts`). The view is counted
7
9
  * only when the browser posts that token back (`routes/view-confirm.ts`),
8
10
  * which the reader bundle does once the page has been in front of the reader
9
11
  * for a few seconds or on the first interaction: a request can look exactly
@@ -29,6 +31,7 @@ import {
29
31
  viewPathKey,
30
32
  viewReferrer,
31
33
  } from "../lib/view-counting.js";
34
+ import { viewUnitsInHtml } from "../lib/list-views.js";
32
35
  import { signViewToken, VIEW_TOKEN_META_NAME } from "../lib/view-token.js";
33
36
  import { viewBasePath } from "../lib/view-language.js";
34
37
 
@@ -105,6 +108,10 @@ export function viewCounter(): MiddlewareHandler<Env> {
105
108
  target.kind === "path"
106
109
  ? viewPathKey(c.req.path, viewBasePath(c))
107
110
  : target.id;
111
+
112
+ // The body is a rendered string; reading it consumes it, so the response
113
+ // is rebuilt either way.
114
+ const html = await c.res.text();
108
115
  const token = await signViewToken(
109
116
  secret,
110
117
  {
@@ -116,14 +123,12 @@ export function viewCounter(): MiddlewareHandler<Env> {
116
123
  ownHost: new URL(c.var.publicRequestUrl).hostname,
117
124
  fetchSite: c.req.header("sec-fetch-site"),
118
125
  }),
126
+ units: viewUnitsInHtml(html),
119
127
  },
120
128
  now(),
121
129
  );
122
130
 
123
- // The body is a rendered string; reading it consumes it, so the response
124
- // is rebuilt either way. The token is base64url and hex: safe as-is in
125
- // an attribute.
126
- const html = await c.res.text();
131
+ // The token is base64url and hex: safe as-is in an attribute.
127
132
  const head = html.indexOf("</head>");
128
133
  const body =
129
134
  head === -1
package/src/preset.css CHANGED
@@ -605,10 +605,12 @@ html {
605
605
  overflow-wrap: break-word;
606
606
  }
607
607
 
608
- /* Attribution and domain lay their parts out with flex, so each part is a flex
609
- item that refuses to shrink below its min-content width. `break-word` leaves
608
+ /* The attribution lays its parts out with flex, so each part is a flex item
609
+ that refuses to shrink below its min-content width. `break-word` leaves
610
610
  min-content at the longest word and the item still overflows; `anywhere` also
611
- shrinks min-content, which is what lets the row wrap. */
611
+ shrinks min-content, which is what lets the row wrap. The domain row is
612
+ inline text, where either value would do; it keeps `anywhere` so a long
613
+ domain breaks the same way in both rows. */
612
614
  .feed-quote-attribution,
613
615
  .feed-link-domain {
614
616
  overflow-wrap: anywhere;
@@ -30,7 +30,7 @@ searchApiRoutes.get(
30
30
  const results = await c.var.services.search.search(query, {
31
31
  limit,
32
32
  status: ["published"],
33
- includePrivate: true,
33
+ asAuthor: true,
34
34
  });
35
35
 
36
36
  return c.json({
@@ -606,7 +606,7 @@ settingsRoutes.get("/general", async (c) => {
606
606
  status: "published" as const,
607
607
  excludeReplies: true,
608
608
  excludeLatestHidden: true,
609
- excludePrivate: true,
609
+ listedForReader: true,
610
610
  };
611
611
  const [navData, aboutPage, announceState, publicPostCount] =
612
612
  await Promise.all([
@@ -145,7 +145,7 @@ sitemapRoutes.get("/:file{sitemap-posts-[0-9]+\\.xml}", async (c) => {
145
145
  translated.map((entry) => entry.id),
146
146
  // A sitemap is public: a draft or private translation must not
147
147
  // show up here, not even as an address.
148
- { status: "published", excludePrivate: true },
148
+ { status: "published", listedForReader: true },
149
149
  )
150
150
  : new Map<string, Post[]>();
151
151
  const siblingIds = [...translationsMap.values()]
@@ -199,8 +199,8 @@ async function parseArchiveParams(
199
199
  * Whether an archive query names a result set only a signed-in reader can see.
200
200
  *
201
201
  * Answered from the query alone, never from what the database happens to hold.
202
- * A check that fired only when private posts existed would answer "does this
203
- * site keep anything private?" to whoever asked.
202
+ * A check that fired only when private or unlisted posts existed would answer
203
+ * "does this site keep anything back?" to whoever asked.
204
204
  *
205
205
  * @param params - Parsed query params
206
206
  * @returns `true` when rendering this query requires an authenticated reader
@@ -266,15 +266,16 @@ function buildArchivePostFilters(
266
266
  const sortsByActivity = params.sort === "updated";
267
267
 
268
268
  // The visibility clause is applied as selected, with no auth-dependent
269
- // degrade: a query naming `private` has already been redirected or 404'd by
270
- // the time it reaches here (see `archiveQueryRequiresAuth`). Silently
271
- // dropping the clause instead would render a different set under the same
272
- // name. `excludePrivate` below stays the unconditional floor regardless.
269
+ // degrade: a query naming `unlisted` or `private` has already been
270
+ // redirected or 404'd by the time it reaches here (see
271
+ // `archiveQueryRequiresAuth`). Silently dropping the clause instead would
272
+ // render a different set under the same name. `listedForReader` below stays
273
+ // the unconditional floor regardless.
273
274
  return {
274
275
  lang,
275
276
  status: "published",
276
277
  excludeReplies: true,
277
- excludePrivate: !isAuthenticated,
278
+ listedForReader: !isAuthenticated,
278
279
  excludeLatestHidden: false,
279
280
  // The year filter follows the active axis, so every month bucket shown
280
281
  // under `year=N` really belongs to that year.
@@ -316,10 +317,10 @@ export const archiveRoutes = new Hono<Env>();
316
317
  * - **Legacy spellings** (`hasMedia`/`hasTitle`/`hasReplies=1/0`,
317
318
  * `visibility=latest_hidden`, `visibility=all`, `view=`) are unconditional —
318
319
  * the old spelling is gone for everyone, so 308.
319
- * - **`visibility=private` for a signed-out reader** is not. That URL moved
320
- * for *this* reader, *now*, and has to keep working once the author signs
321
- * in, so it is a 302. When both apply, the weaker claim wins and everything
322
- * is still resolved in a single hop.
320
+ * - **`visibility=unlisted` or `visibility=private` for a signed-out reader**
321
+ * is not. That URL moved for *this* reader, *now*, and has to keep working
322
+ * once the author signs in, so it is a 302. When both apply, the weaker
323
+ * claim wins and everything is still resolved in a single hop.
323
324
  *
324
325
  * Only these params are touched; everything else, including unknown params, is
325
326
  * preserved. Returns null when the URL is already canonical for this reader.
@@ -365,13 +366,18 @@ function archiveParamsRedirect(
365
366
  changed = true;
366
367
  }
367
368
 
368
- // A signed-out reader cannot select `private`, and the one answer that is
369
- // never right is to drop the clause and render a different set under the
370
- // same URL. Strip it here so the address bar and the page agree on what the
371
- // reader is looking at. The decision reads the param and the session only,
372
- // so it is identical whether or not this site holds a single private post.
369
+ // A signed-out reader cannot select `unlisted` or `private`, and the one
370
+ // answer that is never right is to drop the clause and render a different
371
+ // set under the same URL. Strip it here so the address bar and the page
372
+ // agree on what the reader is looking at. The decision reads the param and
373
+ // the session only, so it is identical whether or not this site holds a
374
+ // single such post.
375
+ const visibilityParam = params.get("visibility");
373
376
  let authStripped = false;
374
- if (params.get("visibility") === "private" && !c.var.isAuthenticated) {
377
+ if (
378
+ (visibilityParam === "unlisted" || visibilityParam === "private") &&
379
+ !c.var.isAuthenticated
380
+ ) {
375
381
  params.delete("visibility");
376
382
  authStripped = true;
377
383
  changed = true;
@@ -527,7 +533,7 @@ export async function renderArchivePage(
527
533
  {
528
534
  status: "published",
529
535
  excludeReplies: true,
530
- excludePrivate: !isAuthenticated,
536
+ listedForReader: !isAuthenticated,
531
537
  lang: filters.lang,
532
538
  sortBy: filters.sortBy,
533
539
  },
@@ -820,7 +826,7 @@ async function buildArchiveFeedData(
820
826
  lang: getViewLang(c) ?? undefined,
821
827
  status: "published",
822
828
  excludeReplies: true,
823
- excludePrivate: true,
829
+ listedForReader: true,
824
830
  excludeLatestHidden: false,
825
831
  ...selectionFilters,
826
832
  sortBy: sortsByActivity ? "thread_updated" : "published",
@@ -163,7 +163,7 @@ export async function renderCollectionPage(
163
163
  collectionIds,
164
164
  {
165
165
  status: "published",
166
- excludePrivate: !isAuthenticated,
166
+ listedForReader: !isAuthenticated,
167
167
  hasRating: true,
168
168
  },
169
169
  2,
@@ -201,7 +201,7 @@ export async function renderCollectionPage(
201
201
  const acrossLanguages =
202
202
  await c.var.services.posts.countCollectionThreadRootsForCollections(
203
203
  collectionIds,
204
- { status: "published", excludePrivate: !navData.isAuthenticated },
204
+ { status: "published", listedForReader: !navData.isAuthenticated },
205
205
  );
206
206
  if (acrossLanguages > 0) {
207
207
  const alternatives = buildLanguageSwitcher(c, {
@@ -309,7 +309,7 @@ export async function renderCollectionFeed(
309
309
  selection.collections.map((collection) => collection.id),
310
310
  {
311
311
  status: "published",
312
- excludePrivate: true,
312
+ listedForReader: true,
313
313
  lang: getViewLang(c) ?? undefined,
314
314
  ignoreCollectionPinnedSort: true,
315
315
  publishedBefore,
@@ -166,6 +166,9 @@ async function renderPostWithTextPreview(
166
166
  articlePublishedTime: display.articlePublishedTime,
167
167
  articleModifiedTime: display.articleModifiedTime,
168
168
  jsonLd: buildPostJsonLd(c, display, meta, canonicalHref, navData.siteName),
169
+ // An Unlisted post opens for anyone with its link, and stays out of
170
+ // search engines even after someone posts that link in public.
171
+ ...(post.visibility === "unlisted" ? { noindex: true } : {}),
169
172
  navData,
170
173
  composeContextLanguage: post.language,
171
174
  content: (
@@ -255,14 +258,16 @@ async function buildTranslationLinks(
255
258
  const pathByLanguage = new Map<string, string>();
256
259
  if (!post.language) return { alternates: [], pathByLanguage };
257
260
 
258
- // Only the versions a reader can actually open. A draft or private
261
+ // Only the versions a reader may find listed. A draft or private
259
262
  // translation answers the same URL with a 404, and an `hreflang` pointing
260
263
  // at a 404 is worse than no `hreflang` at all — the switcher then falls
261
- // back to that language's home, which is always somewhere real (§5).
264
+ // back to that language's home, which is always somewhere real (§5). An
265
+ // Unlisted translation opens, but linking it from every page of its group
266
+ // would list it.
262
267
  const translations = post.translationGroupId
263
268
  ? await c.var.services.posts.listTranslations(post.threadId, {
264
269
  status: "published",
265
- excludePrivate: true,
270
+ listedForReader: true,
266
271
  })
267
272
  : [];
268
273
  const siblings = translations.filter(
@@ -311,7 +316,11 @@ async function renderPost(
311
316
  } = {},
312
317
  ) {
313
318
  // A preview is the author looking at their own draft, not a page read.
314
- if (!options.isPreview) c.set("viewTarget", { kind: "post", id: post.id });
319
+ // Every post of a Thread renders the whole Thread, so each counts toward
320
+ // the Thread, by its root's id, as its canonical URL points to the root.
321
+ if (!options.isPreview) {
322
+ c.set("viewTarget", { kind: "post", id: post.threadId });
323
+ }
315
324
 
316
325
  // The chrome, the thread, and the translation links each need only the
317
326
  // post, so they load together. The chrome is scoped to the post's
@@ -425,6 +434,9 @@ async function renderPost(
425
434
  : {}),
426
435
  navData,
427
436
  composeContextLanguage: post.language,
437
+ // An Unlisted post opens for anyone with its link, and stays out of
438
+ // search engines even after someone posts that link in public.
439
+ ...(post.visibility === "unlisted" ? { noindex: true } : {}),
428
440
  ...(options.isPreview
429
441
  ? {
430
442
  pageChrome: <DraftPreviewBar editHref={draftEditHref} />,
@@ -60,13 +60,13 @@ export async function renderSearchPage(c: Context<Env>): Promise<Response> {
60
60
  c.header("Retry-After", String(rateLimit.retryAfterSec));
61
61
  } else if (query.trim()) {
62
62
  try {
63
- // Fetch one extra to check for more. Private posts match for the
64
- // signed-in author only, as on the archive and collection pages.
63
+ // Fetch one extra to check for more. Unlisted and Private posts match
64
+ // for the signed-in author only, as on the archive and collection pages.
65
65
  results = await c.var.services.search.search(query, {
66
66
  limit: pageSize + 1,
67
67
  offset: (page - 1) * pageSize,
68
68
  status: ["published"],
69
- includePrivate: c.var.isAuthenticated,
69
+ asAuthor: c.var.isAuthenticated,
70
70
  lang: getViewLang(c) ?? undefined,
71
71
  });
72
72
 
@@ -6,6 +6,12 @@
6
6
  * The token says which page and where the reader came from; this route
7
7
  * adds when. It answers 204 whatever it thinks of the token: a forger
8
8
  * learns nothing, and a reader's browser has already moved on.
9
+ *
10
+ * The body is the token alone to confirm the page, or the token followed by
11
+ * the root ids, space-separated, of the Threads a reader read in full in the
12
+ * page's lists
13
+ * (`client/list-views.ts`). Those count toward the Threads, each once, and
14
+ * only the ones the token names; the page itself is not counted again.
9
15
  */
10
16
 
11
17
  import { Hono } from "hono";
@@ -36,22 +42,24 @@ export function createViewConfirmRoutes(buffer: ViewBuffer = viewBuffer) {
36
42
  const secret = getEnvString(c.env, "AUTH_SECRET");
37
43
  if (appConfig.stats.enabled && !c.var.isAuthenticated && secret) {
38
44
  const at = now();
39
- const claims = await verifyViewToken(
40
- secret,
41
- (await c.req.text()).trim(),
42
- at,
43
- );
45
+ const [token = "", ...rest] = (await c.req.text()).trim().split(/\s+/);
46
+ const claims = await verifyViewToken(secret, token, at);
44
47
  if (claims && claims.siteId === c.var.currentSite.id) {
45
- buffer.add(
46
- {
47
- siteId: claims.siteId,
48
- day: formatDayKey(at, appConfig.timeZone),
49
- hour: formatHourKey(at, appConfig.timeZone),
50
- page: claims.page,
51
- referrer: claims.referrer,
52
- },
53
- viewSinkFor(c),
54
- );
48
+ const hit = {
49
+ siteId: claims.siteId,
50
+ day: formatDayKey(at, appConfig.timeZone),
51
+ hour: formatHourKey(at, appConfig.timeZone),
52
+ referrer: claims.referrer,
53
+ };
54
+ const sink = viewSinkFor(c);
55
+ if (rest.length === 0) {
56
+ buffer.add({ ...hit, page: claims.page }, sink);
57
+ } else {
58
+ const listed = new Set(claims.units);
59
+ for (const thread of new Set(rest.filter((id) => listed.has(id)))) {
60
+ buffer.add({ ...hit, page: thread }, sink);
61
+ }
62
+ }
55
63
  }
56
64
  }
57
65
  return c.body(null, 204);
@@ -697,7 +697,7 @@ export function createCollectionService(
697
697
  // page. The two numbers are shown one click apart and have to agree.
698
698
  const readerConditions = buildReaderVisibilityConditions(posts, siteId, {
699
699
  status: "published",
700
- excludePrivate: !viewer.isAuthenticated,
700
+ listedForReader: !viewer.isAuthenticated,
701
701
  lang: viewer.lang,
702
702
  });
703
703