Public: anyone can read this; the crew can change it.
A feed post has a permalink with its replies and a share card, and every post in the timeline links to it #12331
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12325-a-feed-post-has-a-permalink-with-its-rep → main 5 commits fork 4 threads · 4 unresolved
10 files
changed +156
−8
docs/design/areas/feed-permalink.md added +3
| @@ -0,0 +1,3 @@ | ||
| 1 | # Feed permalink | |
| 2 | ||
| 3 | The time stamp on a feed post links to its issue or pull: `.permalink`, padded to a 44px tap target without moving the layout. |
docs/features/README.md +1
| @@ -23,6 +23,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md). | ||
| 23 | 23 | - [](docs-link.md) |
| 24 | 24 | - [](engine-shape.md) |
| 25 | 25 | - [](feed-fold.md) |
| 26 | - [](feed-permalink.md) | |
| 26 | 27 | - [](feed-like-ledger.md) |
| 27 | 28 | - [](packs.md) |
| 28 | 29 | - [](home-frame.md) |
docs/features/feed-permalink.md added +16
| @@ -0,0 +1,16 @@ | ||
| 1 | # A feed post's permalink | |
| 2 | ||
| 3 | Every post in the feed has one stable address: the issue or pull it is about. | |
| 4 | ||
| 5 | ## Where the link is | |
| 6 | ||
| 7 | - **Page:** on `/feed`, the time stamp on each post (`2h ago`) is a link ("Open post"). It goes to the issue or pull page, never to a comment anchor, so the address is the same for every reader. | |
| 8 | - **Terminal:** open Feed from the palette, move to a post with `j`/`k` and press `p`; the permalink path is said in a toast. | |
| 9 | ||
| 10 | A post about something else (a run, a map) links to that page instead. | |
| 11 | ||
| 12 | ## What the page holds | |
| 13 | ||
| 14 | The issue or pull page: its description, its replies (reply there or from the feed) and its share card. A reader who may not read the repository gets a 404, the same as for any private page. | |
| 15 | ||
| 16 | `permalinkOf` (`src/feed/reply.ts`) builds the address for both doors. |
src/feed/reply.ts +9
| @@ -51,3 +51,12 @@ export function replyTarget( | ||
| 51 | 51 | const repo = replyRepo(db, viewer, item.app); |
| 52 | 52 | return repo === undefined ? undefined : { thread, repo }; |
| 53 | 53 | } |
| 54 | ||
| 55 | /** | |
| 56 | * The one stable URL a post has: the issue or pull its link names, without | |
| 57 | * any comment anchor. A post about anything else (a run, a map) keeps its link. | |
| 58 | */ | |
| 59 | export function permalinkOf(link: string): string { | |
| 60 | const thread = threadOf(link); | |
| 61 | return thread === undefined ? link : `/${thread.owner}/${thread.name}/${thread.kind}/${thread.number}`; | |
| 62 | } | |
src/tui/screens/feed.ts +13 −3
| @@ -7,7 +7,8 @@ | ||
| 7 | 7 | * posts to the same people as the page's Reply (`feed/reply.ts`). `enter` on a folded burst |
| 8 | 8 | * lists its members; `l` likes the post under the cursor and a second press takes it back: the page's |
| 9 | 9 | * Like, behind the same `readInteraction` check (`feed/likes.ts`); `h` lists |
| 10 | * who liked or unliked it and when, newest first, behind that check too. Twenty | |
| 10 | * who liked or unliked it and when, newest first, behind that check too. `p` says the | |
| 11 | * post's permalink (`permalinkOf`, the page's time link) in a toast. Twenty | |
| 11 | 12 | * posts at a time; `t` switches to every post, newest first (`readTimeline`); `m` narrows that to only mine (its `mine` option, the page's |
| 12 | 13 | * `?show=mine`); `n` reads the next page from the cursor the last returned. |
| 13 | 14 | */ |
| @@ -19,7 +20,7 @@ import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.t | ||
| 19 | 20 | import type { FeedItem } from "../../feed/rank.ts"; |
| 20 | 21 | import { readInteraction } from "../../feed/interact.ts"; |
| 21 | 22 | import { likeLedger, toggleLike } from "../../feed/likes.ts"; |
| 22 | import { replyTarget } from "../../feed/reply.ts"; | |
| 23 | import { permalinkOf, replyTarget } from "../../feed/reply.ts"; | |
| 23 | 24 | import type { Ctx, Screen } from "../app/app.ts"; |
| 24 | 25 | import { binding } from "../app/keys.ts"; |
| 25 | 26 | import type { Session } from "../session.ts"; |
| @@ -123,6 +124,13 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 123 | 124 | ctx.invalidate(); |
| 124 | 125 | }; |
| 125 | 126 | |
| 127 | /** `p`: the permalink of the post under the cursor, the path the page's time stamp links to. */ | |
| 128 | const permalink = (): void => { | |
| 129 | const item = items[state.index]; | |
| 130 | if (item === undefined) return; | |
| 131 | ctx.toast(`permalink ${permalinkOf(item.link)}`); | |
| 132 | }; | |
| 133 | ||
| 126 | 134 | const submit = (): void => { |
| 127 | 135 | const at = selected(); |
| 128 | 136 | if (at === undefined) return; |
| @@ -149,6 +157,7 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 149 | 157 | ...(items[state.index]?.opens === true ? [binding(["enter"], "open the burst")] : []), |
| 150 | 158 | ...(items.length === 0 ? [] : [binding(["l"], "like")]), |
| 151 | 159 | ...(items.length === 0 ? [] : [binding(["h"], "who liked")]), |
| 160 | ...(items.length === 0 ? [] : [binding(["p"], "permalink")]), | |
| 152 | 161 | ...(next === null ? [] : [binding(["n"], "next page")]), |
| 153 | 162 | binding(["t"], timeline || mine ? "ranked" : "newest first"), |
| 154 | 163 | binding(["m"], mine ? "everyone's" : "only mine"), |
| @@ -213,6 +222,7 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 213 | 222 | } else if (e.key === "enter" && items[state.index]?.opens === true) members = items[state.index]!; |
| 214 | 223 | else if (e.key === "l") like(); |
| 215 | 224 | else if (e.key === "h") showHistory(); |
| 225 | else if (e.key === "p") permalink(); | |
| 216 | 226 | else if (e.key === "t" || e.key === "m") { |
| 217 | 227 | if (e.key === "m") mine = !mine; |
| 218 | 228 | else { |
| @@ -235,7 +245,7 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 235 | 245 | export const entry: PaletteEntry = { |
| 236 | 246 | id: "feed", |
| 237 | 247 | title: "Feed", |
| 238 | hint: "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked", | |
| 248 | hint: "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink", | |
| 239 | 249 | offered: (session) => session.user !== undefined, |
| 240 | 250 | run: (session, ctx) => ctx.push(feedScreen(session, ctx)), |
| 241 | 251 | }; |
src/web/studio/feed.ts +2 −2
| @@ -21,7 +21,7 @@ import { parseCursor, readFeedPage } from "../../feed/feed.ts"; | ||
| 21 | 21 | import { parseShow, type Show } from "../../feed/mine.ts"; |
| 22 | 22 | import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.ts"; |
| 23 | 23 | import type { FeedItem } from "../../feed/rank.ts"; |
| 24 | import { replyPath, replyRepo, threadOf } from "../../feed/reply.ts"; | |
| 24 | import { permalinkOf, replyPath, replyRepo, threadOf } from "../../feed/reply.ts"; | |
| 25 | 25 | import { getAppByRepo } from "../../core/apps.ts"; |
| 26 | 26 | import { getRepo, getRepoById } from "../../core/repos.ts"; |
| 27 | 27 | import { DEFAULT_PAGE, looksForEnv, lookUrl } from "../../core/looks.ts"; |
| @@ -153,7 +153,7 @@ export function feedCard( | ||
| 153 | 153 | const head = html`${avatar(item.actor ?? item.app)} |
| 154 | 154 | <strong class="break">${item.actor ?? item.app}</strong |
| 155 | 155 | >${nameMark(item.actor === null ? undefined : marks.get(item.actor))} |
| 156 | <span class="muted small break">${item.app} · ${time(item.at)}</span> | |
| 156 | <span class="muted small break">${item.app} · <a href="${permalinkOf(item.link)}" class="muted permalink" aria-label="Open post" data-permalink>${time(item.at)}</a></span> | |
Non-blocking: the aria-label drops the visible time from the accessible name (label in name). Include the time text in the label. |
||
| 157 | 157 | ${settledBadge(item.settled)} |
| 158 | 158 | <span class="spacer"></span> |
| 159 | 159 | <span class="badge">${KIND_LABEL[item.kind]}</span>`; |
src/web/style/components.ts +1
| @@ -451,6 +451,7 @@ a.sha:hover { color: var(--accent); } | ||
| 451 | 451 | .look img { display: block; width: 100%; height: auto; } |
| 452 | 452 | .look[data-slot="thumb"] { flex: none; width: 30px; height: 40px; border-radius: 4px; } |
| 453 | 453 | .look[data-slot="thumb"] img { height: 100%; object-fit: cover; object-position: top; } |
| 454 | .permalink { display: inline-block; padding: 12px 6px; margin: -12px -6px; } | |
Non-blocking: this rule sits between the |
||
| 454 | 455 | .look[data-slot="feed"] { width: 160px; height: 100px; margin-top: 6px; } |
| 455 | 456 | .look[data-slot="feed"] img { height: 100%; object-fit: cover; object-position: top; } |
| 456 | 457 | .look[data-slot="now"] { flex: none; width: 168px; } |
test/feed-permalink.test.ts added +99
| @@ -0,0 +1,99 @@ | ||
| 1 | /** | |
| 2 | * A feed post's time is its permalink: the issue or pull page, with the post, | |
| 3 | * its replies and the card. A post the viewer cannot read is a plain 404. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { openIssue } from "../src/actions/issues.ts"; | |
| 10 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { permalinkOf } from "../src/feed/reply.ts"; | |
| 13 | import type { FeedItem } from "../src/feed/rank.ts"; | |
| 14 | import { feedCard } from "../src/web/studio/feed.ts"; | |
| 15 | import { createSession } from "../src/core/sessions.ts"; | |
| 16 | import { createUser } from "../src/core/users.ts"; | |
| 17 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 18 | import { quietLogs } from "./helpers/globals.ts"; | |
| 19 | import { promote } from "./helpers/members.ts"; | |
| 20 | ||
| 21 | quietLogs(); | |
| 22 | ||
| 23 | let root = ""; | |
| 24 | let app: App; | |
| 25 | let servers: Servers; | |
| 26 | let aliceCookie = ""; | |
| 27 | let bobCookie = ""; | |
| 28 | let openN = 0; | |
| 29 | let secretN = 0; | |
| 30 | const TEXT = `Tell <b>x</b> & "y"`; | |
| 31 | ||
| 32 | const must = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => { | |
| 33 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 34 | return r.value; | |
| 35 | }; | |
| 36 | ||
| 37 | beforeAll(async () => { | |
| 38 | root = mkdtempSync(join(tmpdir(), "forge-feed-permalink-")); | |
| 39 | app = createApp({ dataDir: root, port: 0, disk: () => ({ freeBytes: 95, totalBytes: 100 }) }); | |
| 40 | servers = await serve(app); | |
| 41 | const person = async (username: string, first: boolean) => | |
| 42 | must( | |
| 43 | await createUser(app.db, { | |
| 44 | origin: "seed", trusted: true, allowReserved: true, username, | |
| 45 | email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first, | |
| 46 | }), | |
| 47 | ); | |
| 48 | await person("root", true); | |
| 49 | const alice = await person("alice", false); | |
| 50 | const bob = await person("bob", false); | |
| 51 | promote(app.db, alice, bob); | |
| 52 | aliceCookie = `forge_session=${createSession(app.db, alice.id).token}`; | |
| 53 | bobCookie = `forge_session=${createSession(app.db, bob.id).token}`; | |
| 54 | for (const [name, visibility] of [["open", "public"], ["secret", "private"]] as const) { | |
| 55 | const repo = must(await createRepo(app, alice, { name, visibility })); | |
| 56 | must(await commitToBranch(app, alice, repo, { message: "seed", files: [{ path: "README.md", content: "# r\n" }] })); | |
| 57 | const issue = must(openIssue(app, alice, repo, { title: TEXT, body: "why?" })); | |
| 58 | if (name === "open") openN = issue.number; | |
| 59 | else secretN = issue.number; | |
| 60 | } | |
| 61 | }, 30_000); | |
| 62 | ||
| 63 | afterAll(async () => { | |
| 64 | await servers.stop(); | |
| 65 | app.close(); | |
| 66 | rmSync(root, { recursive: true, force: true }); | |
| 67 | }); | |
| 68 | ||
| 69 | const get = (path: string, cookie = "") => fetch(`${servers.url}${path}`, { headers: { cookie } }); | |
| 70 | ||
| 71 | test("a card's time links to the permalink, without a comment anchor", () => { | |
| 72 | const item = { id: "e1", kind: "reply", app: "alice/open", actor: "bob", at: "2026-03-04T05:06:07.000Z", what: "x", reason: "y", link: "/alice/open/issues/3#c-1" } as FeedItem; | |
| 73 | expect(feedCard(item).text).toMatch(/<a href="\/alice\/open\/issues\/3"[^>]*data-permalink>\s*<time/); | |
| 74 | expect(permalinkOf("/alice/open/pulls/4#c")).toBe("/alice/open/pulls/4"); | |
| 75 | expect(permalinkOf("/alice/open/runs/r1")).toBe("/alice/open/runs/r1"); | |
| 76 | }); | |
| 77 | ||
| 78 | test("the timeline's link leads to a page holding the post, escaped, with its card", async () => { | |
| 79 | const feed = await (await get("/feed", aliceCookie)).text(); | |
| 80 | const link = new RegExp(`<a href="(/alice/open/issues/${openN})"[^>]*data-permalink>`).exec(feed); | |
| 81 | expect(link).not.toBeNull(); | |
| 82 | const res = await get(link![1]!, bobCookie); | |
| 83 | expect(res.status).toBe(200); | |
| 84 | const page = await res.text(); | |
| 85 | expect(page).toContain("Tell <b>x</b> & "); | |
| 86 | expect(page).not.toContain("<b>x</b>"); | |
| 87 | expect(page).toContain('property="og:title"'); | |
| 88 | }); | |
| 89 | ||
| 90 | test("a post the viewer cannot read is the same 404 as a missing one", async () => { | |
| 91 | const hidden = await get(`/alice/secret/issues/${secretN}`, bobCookie); | |
| 92 | const missing = await get(`/alice/secret/issues/${secretN + 1}`, bobCookie); | |
| 93 | const none = await get(`/alice/nope/issues/1`, bobCookie); | |
| 94 | expect(hidden.status).toBe(404); | |
| 95 | expect(missing.status).toBe(404); | |
| 96 | expect(none.status).toBe(404); | |
| 97 | const same = (t: string) => t.replaceAll(String(secretN + 1), "N").replaceAll(String(secretN), "N"); | |
| 98 | expect(same(await hidden.text())).toBe(same(await missing.text())); | |
| 99 | }); |
test/palette-roster.test.ts +3 −3
| @@ -197,7 +197,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 197 | 197 | ["bets", "Bets", "back, stop and finish a repository\'s bets"], |
| 198 | 198 | ["origins", "Connected accounts", "the hosts your mirrors come from"], |
| 199 | 199 | ["domains", "Failure domains", "failure domains and their last drill"], |
| 200 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked"], | |
| 200 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink"], | |
| 201 | 201 | ["feature-review", "Menu entries to review", "absorbed apps whose declared name or page changed: accept them"], |
| 202 | 202 | ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"], |
| 203 | 203 | ["features", "Features", "apps that declare a feature: absorb one, change its settings"], |
| @@ -290,7 +290,7 @@ test("a site-admin agent is offered the roster without the person-only entries", | ||
| 290 | 290 | ["plan-row", "Plan", "this forge's plan, and where its owner manages billing"], |
| 291 | 291 | ["cloud", "Cloud accounts", "provider tokens, what they are used for, today's calls"], |
| 292 | 292 | ["pinned", "Pinned forges", "deploy, update and roll back a forge on your cloud"], |
| 293 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked"], | |
| 293 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink"], | |
| 294 | 294 | ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"], |
| 295 | 295 | ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"], |
| 296 | 296 | ["forges", "Forges you sent", "each forge sent, claimed or not, and its apps"], |
| @@ -385,7 +385,7 @@ test("a member person is offered the signed-in roster without the admin entries" | ||
| 385 | 385 | ["bulk", "Bulk actions", "your last bulk actions; u undoes one inside its day"], |
| 386 | 386 | ["bets", "Bets", "back, stop and finish a repository\'s bets"], |
| 387 | 387 | ["origins", "Connected accounts", "the hosts your mirrors come from"], |
| 388 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked"], | |
| 388 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink"], | |
| 389 | 389 | ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"], |
| 390 | 390 | ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"], |
| 391 | 391 | ["origin-ahead", "New commits upstream", "mirrors whose origin has moved on: take them"], |
test/tui-feed-reply.test.ts +9
| @@ -204,3 +204,12 @@ test("t switches the feed to every post, newest first, and back", async () => { | ||
| 204 | 204 | expect(t.text()).toContain("newest first"); |
| 205 | 205 | t.stop(); |
| 206 | 206 | }); |
| 207 | ||
| 208 | test("p says the permalink of the post under the cursor, without a comment anchor", async () => { | |
| 209 | const t = boot("alice"); | |
| 210 | await t.open(); | |
| 211 | await t.press(...downTo("alice", `/alice/open/pulls/${pullNumber}`)); | |
| 212 | await t.press("p"); | |
| 213 | expect(t.text()).toContain(`permalink /alice/open/pulls/${pullNumber}`); | |
| 214 | t.stop(); | |
| 215 | }); |
new above
offline
Both doors: the terminal needs to reach this same permalink; use permalinkOf from the feed screen in src/tui/ and add a test there.