@jant/core 1.2.0 → 1.4.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/site/import.js +2 -1
- package/dist/{app-CbOZ2Irh.js → app-BuzORSgm.js} +1441 -686
- package/dist/client/.vite/manifest.json +72 -83
- package/dist/client/_assets/chunks/{confirm-CMe01lne.js → confirm-BQebcuNB.js} +1 -1
- package/dist/client/_assets/chunks/{create-editor-hWapNE40.js → create-editor-B8KuszlS.js} +38 -38
- package/dist/client/_assets/chunks/footnote-rail-DUrqz0Py.js +2 -0
- package/dist/client/_assets/chunks/{jant-locale-picker-2L4rkDaz.js → jant-locale-picker-CLq0iKDH.js} +1 -1
- package/dist/client/_assets/chunks/lit-BN4mrI3j.js +2 -0
- package/dist/client/_assets/chunks/{settings-paths-BBVT8zKj.js → settings-paths-_fry4yWW.js} +1 -1
- package/dist/client/_assets/chunks/{slug-format-BuCPjSrB.js → slug-format-bcJ2ozr4.js} +1 -1
- package/dist/client/_assets/chunks/{sortable-list-DJXwkaOv.js → sortable-list-Bz2Na2E9.js} +2 -2
- package/dist/client/_assets/chunks/{unsafe-html-CWos3v6N.js → unsafe-html-OJ9m154w.js} +1 -1
- package/dist/client/_assets/chunks/unsafe-svg-DVJ4NPcb.js +1 -0
- package/dist/client/_assets/client-CStDm2xD.js +354 -0
- package/dist/client/_assets/{client-D8Rrsd73.css → client-CoNHvipV.css} +1 -1
- package/dist/client/_assets/{client-auth-CsUGM718.js → client-auth-D53R-Wby.js} +99 -129
- package/dist/client/_assets/client-author-2WYBkgni.css +2 -0
- package/dist/client/_assets/{client-compose-BB4U7Wz0.js → client-compose-DYtDlYm-.js} +248 -244
- package/dist/client/_assets/{client-manage-CI9-eh-8.js → client-manage-BODyYP5Z.js} +157 -157
- package/dist/client/_assets/{client-settings-BnGPuqwc.js → client-settings-DDpe_tXJ.js} +166 -166
- package/dist/client/_assets/client-share-B9OsXx9p.js +149 -0
- package/dist/{constants-DEgyqWDl.js → constants-C2CdWAqt.js} +55 -5
- package/dist/index.js +1 -1
- package/dist/node.js +2 -2
- package/package.json +2 -1
- package/src/client/components/compose-types.ts +5 -1
- package/src/client/components/jant-compose-dialog.ts +25 -4
- package/src/client/components/jant-media-lightbox.ts +18 -3
- package/src/client/components/jant-nav-manager.ts +2 -0
- package/src/client/components/jant-post-menu.ts +42 -89
- package/src/client/components/nav-manager-types.ts +2 -0
- package/src/client/components/settings-types.ts +1 -1
- package/src/client/list-views.ts +382 -0
- package/src/client/media-lightbox-events.ts +12 -0
- package/src/client/runtime-paths.ts +12 -0
- package/src/client/share-capture.ts +63 -0
- package/src/client/share-launch.ts +36 -9
- package/src/client/tiptap/create-editor.ts +4 -0
- package/src/client/tiptap/embed-node.ts +3 -1
- package/src/client/tiptap/html-block-node.ts +3 -1
- package/src/client/tiptap/image-node.ts +3 -1
- package/src/client/view-confirm.ts +32 -4
- package/src/client.ts +1 -0
- package/src/db/migrations/0037_round_post.sql +16 -0
- package/src/db/migrations/0038_flashy_changeling.sql +15 -0
- package/src/db/migrations/0039_mixed_sister_grimm.sql +1 -0
- package/src/db/migrations/meta/0037_snapshot.json +2932 -0
- package/src/db/migrations/meta/0038_snapshot.json +2924 -0
- package/src/db/migrations/meta/0039_snapshot.json +2931 -0
- package/src/db/migrations/meta/_journal.json +21 -0
- package/src/db/migrations/pg/0035_flimsy_outlaw_kid.sql +3 -0
- package/src/db/migrations/pg/0036_milky_wolverine.sql +5 -0
- package/src/db/migrations/pg/0037_fuzzy_hammerhead.sql +1 -0
- package/src/db/migrations/pg/meta/0035_snapshot.json +3773 -0
- package/src/db/migrations/pg/meta/0036_snapshot.json +3766 -0
- package/src/db/migrations/pg/meta/0037_snapshot.json +3772 -0
- package/src/db/migrations/pg/meta/_journal.json +21 -0
- package/src/db/pg/schema.ts +1 -0
- package/src/db/post-visibility.ts +37 -6
- package/src/db/schema.ts +5 -2
- package/src/i18n/locales/glossary.zh-Hans.yml +4 -0
- package/src/i18n/locales/glossary.zh-Hant.yml +4 -0
- package/src/i18n/locales/public/en.po +21 -90
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +20 -89
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +20 -89
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +84 -0
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +130 -46
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +124 -40
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/lib/api-public-posts.ts +10 -0
- package/src/lib/feed-policy.ts +2 -2
- package/src/lib/feed.ts +17 -1
- package/src/lib/filter-dimensions.ts +11 -4
- package/src/lib/hugo-markdown.ts +7 -0
- package/src/lib/icons.ts +2 -0
- package/src/lib/link-preview.ts +499 -0
- package/src/lib/list-views.ts +117 -0
- package/src/lib/markdown-manager.ts +40 -1
- package/src/lib/navigation.ts +1 -1
- package/src/lib/share-card.ts +4 -3
- package/src/lib/thread-query.ts +6 -2
- package/src/lib/timeline.ts +12 -11
- package/src/lib/url-fetch.ts +291 -74
- package/src/lib/view-buffer.ts +2 -2
- package/src/lib/view-counting.ts +7 -6
- package/src/lib/view-token.ts +29 -7
- package/src/lib/view.ts +17 -0
- package/src/middleware/view-counter.ts +10 -5
- package/src/preset.css +5 -3
- package/src/routes/api/search.ts +1 -1
- package/src/routes/dash/settings.tsx +1 -1
- package/src/routes/feed/sitemap.ts +1 -1
- package/src/routes/pages/archive.tsx +25 -19
- package/src/routes/pages/collection.tsx +3 -3
- package/src/routes/pages/page.tsx +16 -4
- package/src/routes/pages/search.tsx +3 -3
- package/src/routes/pages/subscribe.tsx +19 -3
- package/src/routes/view-confirm.ts +23 -15
- package/src/services/collection.ts +1 -1
- package/src/services/export-theme/assets/client-site.js +19 -19
- package/src/services/export-theme/layouts/archive/list.html +4 -2
- package/src/services/export-theme/layouts/partials/collection-members.html +4 -3
- package/src/services/export-theme/layouts/partials/featured-members.html +3 -3
- package/src/services/export-theme/layouts/partials/head.html +2 -0
- package/src/services/export-theme/layouts/partials/latest-members.html +4 -4
- package/src/services/export-theme/layouts/partials/post-card.html +1 -9
- package/src/services/export-theme/layouts/partials/reply.html +1 -9
- package/src/services/export-theme/layouts/partials/smart-collection-members.html +4 -3
- package/src/services/export-theme/layouts/post/list.html +1 -9
- package/src/services/export-theme/styles/main.css +2 -26
- package/src/services/export.ts +10 -3
- package/src/services/mcp.ts +5 -5
- package/src/services/navigation.ts +9 -4
- package/src/services/post.ts +102 -112
- package/src/services/search.ts +22 -7
- package/src/services/smart-collection.ts +3 -3
- package/src/services/stats.ts +12 -5
- package/src/services/thread.ts +6 -2
- package/src/styles/components-author.css +69 -7
- package/src/styles/tokens.css +28 -29
- package/src/styles/ui-author.css +140 -353
- package/src/styles/ui.css +34 -32
- package/src/types/constants.ts +68 -4
- package/src/types/entities.ts +1 -0
- package/src/types/views.ts +2 -0
- package/src/ui/compose/ComposeDialog.tsx +20 -1
- package/src/ui/dash/StatusBadge.tsx +11 -0
- package/src/ui/dash/appearance/FontThemeContent.tsx +1 -1
- package/src/ui/dash/appearance/NavigationContent.tsx +8 -0
- package/src/ui/dash/settings/StatsContent.tsx +29 -29
- package/src/ui/feed/LinkCard.tsx +19 -2
- package/src/ui/feed/PostStatusBadges.tsx +19 -3
- package/src/ui/feed/TimelineFeed.tsx +3 -0
- package/src/ui/font-themes.ts +32 -15
- package/src/ui/pages/ArchivePage.tsx +1 -0
- package/src/ui/pages/SubscribePage.tsx +9 -1
- package/src/ui/shared/PostFooter.tsx +1 -22
- package/src/ui/shared/custom-icons.ts +5 -5
- package/dist/client/_assets/chunks/footnote-rail-9zwl6jtV.js +0 -2
- package/dist/client/_assets/chunks/lit-Bw_voPoW.js +0 -2
- package/dist/client/_assets/chunks/runtime-paths-y0_gHowM.js +0 -1
- package/dist/client/_assets/chunks/unsafe-svg-CUrgo4Xg.js +0 -1
- package/dist/client/_assets/client-BO8GOFfT.js +0 -354
- package/dist/client/_assets/client-author-QPm1whbO.css +0 -2
- package/dist/client/_assets/client-share-C59mOLJ1.js +0 -149
package/src/lib/view-counting.ts
CHANGED
|
@@ -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
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* page
|
|
27
|
-
*
|
|
28
|
-
*
|
|
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 }
|
package/src/lib/view-token.ts
CHANGED
|
@@ -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
|
-
/**
|
|
46
|
-
|
|
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,
|
|
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(
|
|
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>`.
|
|
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
|
|
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
|
-
/*
|
|
609
|
-
|
|
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;
|
package/src/routes/api/search.ts
CHANGED
|
@@ -606,7 +606,7 @@ settingsRoutes.get("/general", async (c) => {
|
|
|
606
606
|
status: "published" as const,
|
|
607
607
|
excludeReplies: true,
|
|
608
608
|
excludeLatestHidden: true,
|
|
609
|
-
|
|
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",
|
|
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
|
|
203
|
-
* site keep anything
|
|
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
|
|
270
|
-
// the time it reaches here (see
|
|
271
|
-
// dropping the clause instead would
|
|
272
|
-
// name. `
|
|
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
|
-
|
|
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**
|
|
320
|
-
* for *this* reader, *now*, and has to keep working
|
|
321
|
-
* in, so it is a 302. When both apply, the weaker
|
|
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
|
|
369
|
-
// never right is to drop the clause and render a different
|
|
370
|
-
// same URL. Strip it here so the address bar and the page
|
|
371
|
-
// reader is looking at. The decision reads the param and
|
|
372
|
-
// so it is identical whether or not this site holds a
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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",
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
69
|
+
asAuthor: c.var.isAuthenticated,
|
|
70
70
|
lang: getViewLang(c) ?? undefined,
|
|
71
71
|
});
|
|
72
72
|
|
|
@@ -22,7 +22,12 @@ import type { Context } from "hono";
|
|
|
22
22
|
import { msg } from "@lingui/core/macro";
|
|
23
23
|
import type { Bindings } from "../../types.js";
|
|
24
24
|
import type { AppVariables } from "../../types/app-context.js";
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
baseLocale,
|
|
27
|
+
createI18n,
|
|
28
|
+
isValidContentLanguage,
|
|
29
|
+
resolveCatalogLocale,
|
|
30
|
+
} from "../../i18n/i18n.js";
|
|
26
31
|
import { getNavigationData } from "../../lib/navigation.js";
|
|
27
32
|
import { buildPageTitle } from "../../lib/page-title.js";
|
|
28
33
|
import { renderPublicPage } from "../../lib/render.js";
|
|
@@ -53,7 +58,14 @@ export async function renderSubscribePage(c: Context<Env>): Promise<Response> {
|
|
|
53
58
|
c.set("viewTarget", { kind: "path" });
|
|
54
59
|
|
|
55
60
|
const navData = await getNavigationData(c);
|
|
56
|
-
|
|
61
|
+
// Scope translation to this page's own copy (title, descriptions, reader
|
|
62
|
+
// explainer) without flipping the request-wide `c.get("i18n")`, which keeps
|
|
63
|
+
// the public header and footer consistent with every other reader page.
|
|
64
|
+
const pageLang = c.var.viewLang ?? appConfig.siteLanguage;
|
|
65
|
+
const pageLocale = isValidContentLanguage(pageLang)
|
|
66
|
+
? resolveCatalogLocale(pageLang)
|
|
67
|
+
: baseLocale;
|
|
68
|
+
const i18n = createI18n(pageLocale);
|
|
57
69
|
|
|
58
70
|
// Readers paste these into a reader, so they have to be whole addresses, and
|
|
59
71
|
// they have to stay inside the language view they were read from.
|
|
@@ -176,7 +188,11 @@ export async function renderSubscribePage(c: Context<Env>): Promise<Response> {
|
|
|
176
188
|
alternateLanguages: buildSurfaceAlternates(c),
|
|
177
189
|
navData,
|
|
178
190
|
content: (
|
|
179
|
-
<SubscribePage
|
|
191
|
+
<SubscribePage
|
|
192
|
+
mainFeed={mainFeed}
|
|
193
|
+
otherFeeds={[otherEnd, archiveFeed]}
|
|
194
|
+
i18n={i18n}
|
|
195
|
+
/>
|
|
180
196
|
),
|
|
181
197
|
});
|
|
182
198
|
}
|
|
@@ -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
|
|
40
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
700
|
+
listedForReader: !viewer.isAuthenticated,
|
|
701
701
|
lang: viewer.lang,
|
|
702
702
|
});
|
|
703
703
|
|