@jant/core 1.1.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.
- package/bin/commands/site/import.js +2 -1
- package/bin/lib/site-snapshot.js +10 -0
- package/dist/{app-CKQ9PqAr.js → app-C8dETvgL.js} +9267 -5697
- package/dist/client/.vite/manifest.json +82 -93
- package/dist/client/_assets/chunks/{confirm-CMe01lne.js → confirm-BQebcuNB.js} +1 -1
- package/dist/client/_assets/chunks/{create-editor-BQkrw8Ax.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-B0bNUaih.js → settings-paths-_fry4yWW.js} +1 -1
- package/dist/client/_assets/chunks/{slug-format-CYmQE5ln.js → slug-format-bcJ2ozr4.js} +1 -1
- package/dist/client/_assets/chunks/sortable-list-Bz2Na2E9.js +2 -0
- package/dist/client/_assets/chunks/types-DrYFqJH2.js +1 -0
- 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-CoNHvipV.css +2 -0
- package/dist/client/_assets/{client-auth-CG55rWb5.js → client-auth-CbnZkLJ6.js} +99 -129
- package/dist/client/_assets/{client-author-CGVvrNZ8.css → client-author-2WYBkgni.css} +1 -1
- package/dist/client/_assets/client-compose-DYtDlYm-.js +2008 -0
- package/dist/client/_assets/{client-manage-DnYdQAhf.js → client-manage-BODyYP5Z.js} +157 -157
- package/dist/client/_assets/client-pq6sVS7y.js +354 -0
- package/dist/client/_assets/{client-settings-CHgsIqXJ.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 +3 -2
- package/package.json +2 -1
- package/src/app.tsx +9 -0
- package/src/client/components/compose-types.ts +6 -1
- package/src/client/components/jant-compose-dialog.ts +26 -4
- package/src/client/components/jant-compose-editor.ts +30 -0
- package/src/client/components/jant-compose-fullscreen.ts +1 -0
- 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/compose-bridge.ts +61 -1
- package/src/client/feed-video-player.ts +6 -0
- 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/bubble-menu.ts +25 -2
- package/src/client/tiptap/create-editor.ts +6 -0
- package/src/client/tiptap/embed-node.ts +3 -1
- package/src/client/tiptap/extensions.ts +4 -0
- package/src/client/tiptap/html-block-node.ts +3 -1
- package/src/client/tiptap/image-node.ts +3 -1
- package/src/client/video-processor.ts +106 -52
- package/src/client/view-confirm.ts +136 -0
- package/src/client.ts +2 -0
- package/src/db/migrations/0035_brainy_next_avengers.sql +9 -0
- package/src/db/migrations/0036_gorgeous_smasher.sql +7 -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/0035_snapshot.json +2877 -0
- package/src/db/migrations/meta/0036_snapshot.json +2924 -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 +35 -0
- package/src/db/migrations/pg/0033_cute_magdalene.sql +10 -0
- package/src/db/migrations/pg/0034_material_agent_brand.sql +8 -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/0033_snapshot.json +3719 -0
- package/src/db/migrations/pg/meta/0034_snapshot.json +3766 -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 +35 -0
- package/src/db/pg/schema.ts +41 -0
- package/src/db/post-visibility.ts +37 -6
- package/src/db/schema.ts +64 -0
- 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 +26 -7
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +25 -6
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +25 -6
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +159 -0
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +159 -0
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +159 -0
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/lib/api-public-posts.ts +10 -0
- package/src/lib/env.ts +20 -0
- package/src/lib/feed-policy.ts +2 -2
- package/src/lib/filter-dimensions.ts +11 -4
- package/src/lib/github-app-state.ts +1 -1
- package/src/lib/github-app.ts +183 -1
- 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 +169 -2
- package/src/lib/navigation.ts +1 -1
- package/src/lib/post-meta.ts +13 -3
- package/src/lib/referrer-aliases.ts +311 -0
- package/src/lib/render.tsx +10 -0
- package/src/lib/resolve-config.ts +14 -0
- package/src/lib/share-card.ts +4 -3
- package/src/lib/summary.ts +152 -54
- package/src/lib/thread-query.ts +6 -2
- package/src/lib/timeline.ts +12 -11
- package/src/lib/tiptap-render.ts +1 -0
- package/src/lib/upload.ts +21 -1
- package/src/lib/url-fetch.ts +291 -74
- package/src/lib/video-playback.ts +55 -0
- package/src/lib/view-buffer.ts +201 -0
- package/src/lib/view-counting.ts +540 -0
- package/src/lib/view-token.ts +199 -0
- package/src/lib/view.ts +30 -1
- package/src/middleware/view-counter.ts +145 -0
- package/src/node/runtime.ts +4 -0
- package/src/preset.css +36 -17
- package/src/routes/api/media.ts +21 -3
- package/src/routes/api/search.ts +1 -1
- package/src/routes/dash/settings.tsx +434 -169
- package/src/routes/feed/sitemap.ts +1 -1
- package/src/routes/pages/archive.tsx +26 -19
- package/src/routes/pages/collection.tsx +9 -3
- package/src/routes/pages/collections.tsx +1 -0
- package/src/routes/pages/featured.tsx +1 -0
- package/src/routes/pages/home.tsx +1 -0
- package/src/routes/pages/page.tsx +18 -3
- package/src/routes/pages/search.tsx +3 -3
- package/src/routes/pages/smart-collection.tsx +2 -0
- package/src/routes/pages/subscribe.tsx +1 -0
- package/src/routes/view-confirm.ts +71 -0
- 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 +41 -47
- package/src/services/export.ts +12 -3
- package/src/services/index.ts +17 -0
- package/src/services/mcp.ts +36 -6
- package/src/services/media.ts +63 -0
- 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 +1137 -0
- package/src/services/thread.ts +6 -2
- package/src/styles/components-author.css +242 -3
- package/src/styles/components.css +11 -3
- package/src/styles/tokens.css +89 -55
- package/src/styles/ui-author.css +140 -353
- package/src/styles/ui.css +90 -45
- package/src/types/app-context.ts +9 -0
- package/src/types/bindings.ts +5 -0
- package/src/types/config.ts +54 -0
- package/src/types/constants.ts +68 -4
- package/src/types/entities.ts +1 -0
- package/src/types/views.ts +8 -0
- package/src/ui/compose/ComposeDialog.tsx +26 -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/SettingsRootContent.tsx +24 -6
- package/src/ui/dash/settings/StatsContent.tsx +855 -0
- 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 +56 -6
- package/src/ui/layouts/BaseLayout.tsx +4 -2
- package/src/ui/layouts/SiteLayout.tsx +8 -3
- package/src/ui/pages/ArchivePage.tsx +1 -0
- package/src/ui/shared/MediaGallery.tsx +19 -3
- package/src/ui/shared/PostFooter.tsx +1 -22
- package/src/ui/shared/custom-icons.ts +5 -5
- package/dist/client/_assets/chunks/footnote-rail-B08scyhW.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/sortable-list-t11Ma1Ek.js +0 -2
- package/dist/client/_assets/chunks/types-D5iF3H1a.js +0 -1
- package/dist/client/_assets/chunks/unsafe-svg-DZl-yjas.js +0 -1
- package/dist/client/_assets/client-B0-s9sqx.css +0 -2
- package/dist/client/_assets/client-Dp46QSht.js +0 -354
- package/dist/client/_assets/client-compose-DkUTuavR.js +0 -2004
- package/dist/client/_assets/client-share-C59mOLJ1.js +0 -149
|
@@ -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;
|
|
@@ -416,6 +422,7 @@ export async function renderArchivePage(
|
|
|
416
422
|
c: Context<Env>,
|
|
417
423
|
queryOverrides?: Record<string, string>,
|
|
418
424
|
): Promise<Response> {
|
|
425
|
+
c.set("viewTarget", { kind: "path" });
|
|
419
426
|
const { services, appConfig } = c.var;
|
|
420
427
|
const pageSize = appConfig.archivePageSize;
|
|
421
428
|
const { params, collections: preloadedCollections } =
|
|
@@ -526,7 +533,7 @@ export async function renderArchivePage(
|
|
|
526
533
|
{
|
|
527
534
|
status: "published",
|
|
528
535
|
excludeReplies: true,
|
|
529
|
-
|
|
536
|
+
listedForReader: !isAuthenticated,
|
|
530
537
|
lang: filters.lang,
|
|
531
538
|
sortBy: filters.sortBy,
|
|
532
539
|
},
|
|
@@ -819,7 +826,7 @@ async function buildArchiveFeedData(
|
|
|
819
826
|
lang: getViewLang(c) ?? undefined,
|
|
820
827
|
status: "published",
|
|
821
828
|
excludeReplies: true,
|
|
822
|
-
|
|
829
|
+
listedForReader: true,
|
|
823
830
|
excludeLatestHidden: false,
|
|
824
831
|
...selectionFilters,
|
|
825
832
|
sortBy: sortsByActivity ? "thread_updated" : "published",
|
|
@@ -85,6 +85,7 @@ export async function renderCollectionPage(
|
|
|
85
85
|
slugExpressionOrSelection: string | ResolvedCollectionSelection,
|
|
86
86
|
pagePathOverride?: string,
|
|
87
87
|
): Promise<Response | null> {
|
|
88
|
+
c.set("viewTarget", { kind: "path" });
|
|
88
89
|
const page = parsePageNumber(c.req.query("page"));
|
|
89
90
|
const paginatedPageTitle = formatPageLabel(page);
|
|
90
91
|
const isAuthenticated = c.var.isAuthenticated;
|
|
@@ -122,6 +123,11 @@ export async function renderCollectionPage(
|
|
|
122
123
|
(collection) => collection.id,
|
|
123
124
|
);
|
|
124
125
|
const isAggregate = selection.collections.length > 1;
|
|
126
|
+
// One collection is counted by id, whatever address it was opened at; an
|
|
127
|
+
// aggregate selection is a page of its own, counted by its path.
|
|
128
|
+
if (!isAggregate) {
|
|
129
|
+
c.set("viewTarget", { kind: "collection", id: primaryCollection.id });
|
|
130
|
+
}
|
|
125
131
|
const requestedDefaultSort = isAggregate
|
|
126
132
|
? "newest"
|
|
127
133
|
: primaryCollection.sortOrder;
|
|
@@ -157,7 +163,7 @@ export async function renderCollectionPage(
|
|
|
157
163
|
collectionIds,
|
|
158
164
|
{
|
|
159
165
|
status: "published",
|
|
160
|
-
|
|
166
|
+
listedForReader: !isAuthenticated,
|
|
161
167
|
hasRating: true,
|
|
162
168
|
},
|
|
163
169
|
2,
|
|
@@ -195,7 +201,7 @@ export async function renderCollectionPage(
|
|
|
195
201
|
const acrossLanguages =
|
|
196
202
|
await c.var.services.posts.countCollectionThreadRootsForCollections(
|
|
197
203
|
collectionIds,
|
|
198
|
-
{ status: "published",
|
|
204
|
+
{ status: "published", listedForReader: !navData.isAuthenticated },
|
|
199
205
|
);
|
|
200
206
|
if (acrossLanguages > 0) {
|
|
201
207
|
const alternatives = buildLanguageSwitcher(c, {
|
|
@@ -303,7 +309,7 @@ export async function renderCollectionFeed(
|
|
|
303
309
|
selection.collections.map((collection) => collection.id),
|
|
304
310
|
{
|
|
305
311
|
status: "published",
|
|
306
|
-
|
|
312
|
+
listedForReader: true,
|
|
307
313
|
lang: getViewLang(c) ?? undefined,
|
|
308
314
|
ignoreCollectionPinnedSort: true,
|
|
309
315
|
publishedBefore,
|
|
@@ -37,6 +37,7 @@ export const collectionsPageRoutes = new Hono<Env>();
|
|
|
37
37
|
export async function renderCollectionsDirectory(
|
|
38
38
|
c: Context<Env>,
|
|
39
39
|
): Promise<Response> {
|
|
40
|
+
c.set("viewTarget", { kind: "path" });
|
|
40
41
|
// The numbers have to match the collection pages these rows link to, so they
|
|
41
42
|
// carry this reader's visibility and this view's language. Both come from the
|
|
42
43
|
// request rather than from `navData` — `navData.isAuthenticated` is
|
|
@@ -32,6 +32,7 @@ export const featuredRoutes = new Hono<Env>();
|
|
|
32
32
|
* @returns Featured page response
|
|
33
33
|
*/
|
|
34
34
|
export async function renderFeaturedPage(c: Context<Env>): Promise<Response> {
|
|
35
|
+
c.set("viewTarget", { kind: "path" });
|
|
35
36
|
// The chrome and the timeline are independent, so they load together. The
|
|
36
37
|
// timeline only ever wanted `navData.isAuthenticated`, which is
|
|
37
38
|
// `c.var.isAuthenticated` verbatim.
|
|
@@ -36,6 +36,7 @@ export const homeRoutes = new Hono<Env>();
|
|
|
36
36
|
* @returns Home page response
|
|
37
37
|
*/
|
|
38
38
|
export async function renderHomePage(c: Context<Env>): Promise<Response> {
|
|
39
|
+
c.set("viewTarget", { kind: "path" });
|
|
39
40
|
const i18n = getI18n(c);
|
|
40
41
|
const page = parsePageNumber(c.req.query("page"));
|
|
41
42
|
const paginatedPageTitle = formatPageLabel(page);
|
|
@@ -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(
|
|
@@ -310,6 +315,13 @@ async function renderPost(
|
|
|
310
315
|
canonicalAlias?: string | null;
|
|
311
316
|
} = {},
|
|
312
317
|
) {
|
|
318
|
+
// A preview is the author looking at their own draft, not a page read.
|
|
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
|
+
}
|
|
324
|
+
|
|
313
325
|
// The chrome, the thread, and the translation links each need only the
|
|
314
326
|
// post, so they load together. The chrome is scoped to the post's
|
|
315
327
|
// language: a Japanese post's logo and nav lead into /ja, since the post
|
|
@@ -422,6 +434,9 @@ async function renderPost(
|
|
|
422
434
|
: {}),
|
|
423
435
|
navData,
|
|
424
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 } : {}),
|
|
425
440
|
...(options.isPreview
|
|
426
441
|
? {
|
|
427
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
|
|
|
@@ -79,6 +79,7 @@ export async function renderSmartCollectionPage(
|
|
|
79
79
|
c: Context<Env>,
|
|
80
80
|
slug: string,
|
|
81
81
|
): Promise<Response | null> {
|
|
82
|
+
c.set("viewTarget", { kind: "path" });
|
|
82
83
|
const page = parsePageNumber(c.req.query("page"));
|
|
83
84
|
const paginatedPageTitle = formatPageLabel(page);
|
|
84
85
|
|
|
@@ -87,6 +88,7 @@ export async function renderSmartCollectionPage(
|
|
|
87
88
|
getNavigationData(c),
|
|
88
89
|
]);
|
|
89
90
|
if (!smartCollection) return null;
|
|
91
|
+
c.set("viewTarget", { kind: "smartCollection", id: smartCollection.id });
|
|
90
92
|
|
|
91
93
|
const canonicalPagePath = getCollectionPagePath(smartCollection.slug);
|
|
92
94
|
const viewer = {
|
|
@@ -50,6 +50,7 @@ export async function renderSubscribePage(c: Context<Env>): Promise<Response> {
|
|
|
50
50
|
// With feeds off there is nothing to subscribe to, and the nav entry is
|
|
51
51
|
// filtered out too — so the page 404s rather than listing dead addresses.
|
|
52
52
|
if (!appConfig.rssFeedsEnabled) return c.notFound();
|
|
53
|
+
c.set("viewTarget", { kind: "path" });
|
|
53
54
|
|
|
54
55
|
const navData = await getNavigationData(c);
|
|
55
56
|
const i18n = getI18n(c);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* View Confirmation Route
|
|
3
|
+
*
|
|
4
|
+
* `POST /_/seen` takes the view token a page carried (`lib/view-token.ts`)
|
|
5
|
+
* back from the browser that kept the page in view, and counts the view.
|
|
6
|
+
* The token says which page and where the reader came from; this route
|
|
7
|
+
* adds when. It answers 204 whatever it thinks of the token: a forger
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Hono } from "hono";
|
|
18
|
+
import type { Bindings } from "../types.js";
|
|
19
|
+
import type { AppVariables } from "../types/app-context.js";
|
|
20
|
+
import { getEnvString } from "../lib/env.js";
|
|
21
|
+
import { now } from "../lib/time.js";
|
|
22
|
+
import { viewBuffer, type ViewBuffer } from "../lib/view-buffer.js";
|
|
23
|
+
import { formatDayKey, formatHourKey } from "../lib/view-counting.js";
|
|
24
|
+
import { verifyViewToken } from "../lib/view-token.js";
|
|
25
|
+
import { viewSinkFor } from "../middleware/view-counter.js";
|
|
26
|
+
|
|
27
|
+
type Env = { Bindings: Bindings; Variables: AppVariables };
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The confirmation route, mounted under `/_`.
|
|
31
|
+
*
|
|
32
|
+
* @param buffer - The buffer confirmed hits go to; tests pass their own
|
|
33
|
+
* @returns A Hono app with `POST /seen`
|
|
34
|
+
* @example
|
|
35
|
+
* app.route("/_", createViewConfirmRoutes());
|
|
36
|
+
*/
|
|
37
|
+
export function createViewConfirmRoutes(buffer: ViewBuffer = viewBuffer) {
|
|
38
|
+
const routes = new Hono<Env>();
|
|
39
|
+
|
|
40
|
+
routes.post("/seen", async (c) => {
|
|
41
|
+
const { appConfig } = c.var;
|
|
42
|
+
const secret = getEnvString(c.env, "AUTH_SECRET");
|
|
43
|
+
if (appConfig.stats.enabled && !c.var.isAuthenticated && secret) {
|
|
44
|
+
const at = now();
|
|
45
|
+
const [token = "", ...rest] = (await c.req.text()).trim().split(/\s+/);
|
|
46
|
+
const claims = await verifyViewToken(secret, token, at);
|
|
47
|
+
if (claims && claims.siteId === c.var.currentSite.id) {
|
|
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
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return c.body(null, 204);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return routes;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const viewConfirmRoutes = createViewConfirmRoutes();
|
|
@@ -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
|
|