Public: anyone can read this; the crew can change it.
A crew member's look appears in the feed with its picture's alt text and a link one step deeper #12448
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/12422-a-crew-member-s-look-appears-in-the-feed → main 5 commits fork 5 threads · 5 unresolved
docs/features/feed-look.md added +7
| @@ -0,0 +1,7 @@ | ||
| 1 | # A look in the feed | |
| 2 | ||
| 3 | A crew member's look (the picture taken of a pull or of production) appears in the feed as a card | |
| 4 | with its picture. The picture's alt text says what it shows ("b at 390 px after pull #7"), the | |
| 5 | picture links to the full-size image, and "Pull #7" (or "The app") links to the thing it came from. | |
| 6 | Until the picture is ready the card holds its 160×100 place. In the terminal the same alt text is | |
| 7 | the note under the post. |
src/feed/items.ts +11 −1
| @@ -90,9 +90,17 @@ export interface Candidate { | ||
| 90 | 90 | readonly look?: FeedLook; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | /** "<app> at 390 px after pull #N", or "... in production": what a look shows. */ | |
| 94 | export function lookAlt(app: string, env: EnvName): string { | |
| 95 | const name = app.split("/").pop() ?? app; | |
| 96 | return env === "production" ? `${name} at 390 px in production` : `${name} at 390 px after pull #${env.slice("pull-".length)}`; | |
| 97 | } | |
| 98 | ||
| 93 | 99 | export interface FeedLook { |
| 94 | 100 | readonly env: EnvName; |
| 95 | 101 | readonly commitOid: string; |
| 102 | /** What the picture shows, in words: the alt text and the terminal's line. */ | |
| 103 | readonly alt: string; | |
| 96 | 104 | } |
| 97 | 105 | |
| 98 | 106 | export interface FeedAsk { |
| @@ -715,7 +723,9 @@ function fromEvent( | ||
| 715 | 723 | kind: "look", |
| 716 | 724 | link: env === "production" ? base(repo) : `${base(repo)}/pulls/${env.slice("pull-".length)}`, |
| 717 | 725 | what: `a new picture of ${of}`, |
| 718 | ...(typeof oid === "string" && /^[0-9a-f]{40}$/.test(oid) ? { look: { env, commitOid: oid } } : {}), | |
| 726 | ...(typeof oid === "string" && /^[0-9a-f]{40}$/.test(oid) | |
| 727 | ? { look: { env, commitOid: oid, alt: lookAlt(common.app, env) } } | |
| 728 | : {}), | |
| 719 | 729 | }; |
| 720 | 730 | } |
| 721 | 731 | case "app.serving": { |
src/tui/screens/feed.ts +10 −1
| @@ -40,6 +40,15 @@ const oneLine = (text: string): string => text.replace(/[\p{Cc}\p{Cf}\u2028\u202 | ||
| 40 | 40 | const likeMark = (item: FeedItem): string => |
| 41 | 41 | item.liked === true ? `♥ ${item.likes ?? 1}` : (item.likes ?? 0) > 0 ? `♡ ${item.likes}` : ""; |
| 42 | 42 | |
| 43 | /** | |
| 44 | * The quiet second line under a post: a look's alt text (what the page's picture says), | |
| 45 | * else its step. | |
| 46 | */ | |
| 47 | export function feedNote(item: FeedItem): { note?: string } { | |
| 48 | if (item.look !== undefined) return { note: item.look.alt }; | |
| 49 | return item.step === undefined ? {} : { note: stepLine(item.step) }; | |
| 50 | } | |
| 51 | ||
| 43 | 52 | export function feedScreen(f: Session, ctx: Ctx): Screen { |
| 44 | 53 | const state = new ListState(); |
| 45 | 54 | const composer = new Composer(); |
| @@ -168,7 +177,7 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 168 | 177 | title: oneLine(`${item.actor ?? item.app} ${item.what}`), |
| 169 | 178 | secondary: item.app, |
| 170 | 179 | meta: [likeMark(item), ago(item.at)].filter((m) => m !== "").join(" "), |
| 171 | ...(item.step === undefined ? {} : { note: stepLine(item.step) }), | |
| 180 | ...feedNote(item), | |
| 172 | 181 | })); |
| 173 | 182 | drawList(s, list!, c, state, rows); |
| 174 | 183 | if (composer.open) composer.render(s, box!, c, ctx); |
src/web/studio/feed.ts +13 −4
| @@ -126,6 +126,12 @@ function likeBar(item: FeedItem): Html { | ||
| 126 | 126 | </form>`; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | /** The link text that goes with a look: the pull it came from ("Pull #7"), or the app itself. */ | |
| 130 | function lookTarget(item: FeedItem): string { | |
| 131 | const pull = /^pull-(\d+)$/.exec(item.look?.env ?? ""); | |
| 132 | return pull === null ? "The app" : `Pull #${pull[1]}`; | |
| 133 | } | |
| 134 | ||
| 129 | 135 | /** |
| 130 | 136 | * One post: who, where and when; what it says, as a link into the thing; |
| 131 | 137 | * why, when that is news; and one quiet control for the rest — say |
| @@ -157,11 +163,14 @@ export function feedCard( | ||
| 157 | 163 | ? html`<details class="feed-fold"><summary class="break">${item.what}</summary>${lineList}</details>` |
| 158 | 164 | : html`<p class="break"><a href="${item.link}" data-feed-open>${item.what}</a></p>`} |
outdated
The image link now goes to the png and is focusable, duplicating 'The look' below: two tab stops, same target, one announced twice by a screen reader. Restore tabindex="-1" aria-hidden="true" with alt="" on this decorative link, or make the image the only link. The alt text on a hidden link is also not what a reader hears. |
||
| 159 | 165 | ${item.opens === true ? null : lineList} |
| 160 | ${picture === undefined | |
| 166 | ${item.look === undefined | |
| 161 | 167 | ? null |
outdated
'The look' links to a raw thumb.png, not a page: 'a link one step deeper' is met only loosely, and 'The pull'/'The look' are bare, non-descriptive link texts (use e.g. 'Pull #7' and 'Picture at full size'). Principle 1/8: the line also repeats what the first link already says. Either build the look page (open an issue and link it) or name the target honestly. |
||
| 162 | : html`<a class="look" data-slot="feed" href="${item.link}" tabindex="-1" aria-hidden="true" | |
| 163 | ><img src="${picture.src}" width="${picture.width}" height="${picture.height}" alt="" loading="lazy" decoding="async" | |
| 164 | /></a>`} | |
| 168 | : picture === undefined | |
| 169 | ? html`<span class="look" data-slot="feed" data-pending role="img" aria-label="${item.look.alt}"></span>` | |
| 170 | : html`<a class="look" data-slot="feed" href="${picture.src}" | |
| 171 | ><img src="${picture.src}" width="${picture.width}" height="${picture.height}" alt="${item.look.alt}" loading="lazy" decoding="async" | |
| 172 | /></a>`} | |
| 173 | ${item.look === undefined ? null : html`<p class="small muted break"><a href="${item.link}">${lookTarget(item)}</a></p>`} | |
| 165 | 174 | ${item.step === undefined ? null : html`<p class="break">${stepLink(item.step)}</p>`} |
| 166 | 175 | ${saysMore(item) ? html`<p class="small muted break">${item.reason}</p>` : null} |
| 167 | 176 | ${likeBar(item)}`; |
test/feed-look-card.test.ts added +51
| @@ -0,0 +1,51 @@ | ||
| 1 | /** | |
| 2 | * A look card says what it shows, links to the pull and the look, | |
| 3 | * and holds its size while the picture is not ready. | |
| 4 | */ | |
| 5 | import { expect, test } from "bun:test"; | |
| 6 | import { feedCard, FEED_PICTURE } from "../src/web/studio/feed.ts"; | |
| 7 | import { lookAlt } from "../src/feed/items.ts"; | |
| 8 | import type { FeedItem } from "../src/feed/rank.ts"; | |
| 9 | ||
| 10 | const item = (app: string, env: "production" | `pull-${number}`): FeedItem => | |
| 11 | ({ | |
| 12 | id: "i1", kind: "look", app, actor: null, at: new Date().toISOString(), link: "/a/b/pulls/7", | |
| 13 | what: "a new picture of #7", reason: "a new picture of #7", | |
| 14 | look: { env, commitOid: "d".repeat(40), alt: lookAlt(app, env) }, | |
| 15 | }) as unknown as FeedItem; | |
| 16 | ||
| 17 | test("alt says what the picture shows; links go to the pull and the look", () => { | |
| 18 | const src = "/a/b/looks/pull-7/x/thumb.png?v=1"; | |
| 19 | const t = feedCard(item("a/b", "pull-7"), new Map(), { src, ...FEED_PICTURE }).text; | |
| 20 | expect(t).toContain('alt="b at 390 px after pull #7"'); | |
| 21 | expect(t).toContain('href="/a/b/pulls/7"'); | |
| 22 | expect(t).toContain(`href="${src}"`); | |
| 23 | }); | |
| 24 | ||
| 25 | test("the picture is the one link to the png; the text link names the pull or the app", () => { | |
| 26 | const src = "/a/b/looks/pull-7/x/thumb.png?v=1"; | |
| 27 | const t = feedCard(item("a/b", "pull-7"), new Map(), { src, ...FEED_PICTURE }).text; | |
| 28 | expect(t.split(`href="${src}"`).length - 1).toBe(1); | |
| 29 | expect(t).toContain(">Pull #7</a>"); | |
| 30 | const prod = feedCard(item("a/b", "production"), new Map(), { src, ...FEED_PICTURE }).text; | |
| 31 | expect(prod).toContain(">The app</a>"); | |
| 32 | }); | |
| 33 | ||
| 34 | test("a look not ready holds its place by class, with its alt as the label", () => { | |
| 35 | const t = feedCard(item("a/b", "pull-7"), new Map(), undefined).text; | |
outdated
Escaping test only uses the not-ready branch and asserts the string is absent, not that the escaped form is present; also assert the ready branch escapes the alt (e.g. contains <script>). Add the missing production-link case (link text 'The app'). |
||
| 36 | expect(t).toContain("data-pending"); | |
| 37 | expect(t).toContain('aria-label="b at 390 px after pull #7"'); | |
| 38 | expect(t).not.toContain("style="); | |
| 39 | expect(t).not.toContain("<img"); | |
| 40 | }); | |
| 41 | ||
| 42 | test("the words are escaped, ready or not", () => { | |
| 43 | const src = "/a/b/looks/production/x/thumb.png?v=1"; | |
| 44 | const pending = feedCard(item(`a/<script>x`, "production"), new Map(), undefined).text; | |
| 45 | const ready = feedCard(item(`a/<script>x`, "production"), new Map(), { src, ...FEED_PICTURE }).text; | |
| 46 | for (const t of [pending, ready]) { | |
| 47 | expect(t).not.toContain("<script>"); | |
| 48 | expect(t).toContain("<script>"); | |
| 49 | } | |
| 50 | expect(lookAlt("a/b", "production")).toBe("b at 390 px in production"); | |
| 51 | }); |
test/tui-feed-note.test.ts added +12
| @@ -0,0 +1,12 @@ | ||
| 1 | /** In the terminal a look's note is the same words as the page's picture alt text. */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { lookAlt } from "../src/feed/items.ts"; | |
| 4 | import type { FeedItem } from "../src/feed/rank.ts"; | |
| 5 | import { feedNote } from "../src/tui/screens/feed.ts"; | |
| 6 | ||
| 7 | test("a look's note is its alt text; a post with neither has no note", () => { | |
| 8 | const alt = lookAlt("a/b", "pull-7"); | |
| 9 | const look = { id: "i", kind: "look", look: { env: "pull-7", commitOid: "d".repeat(40), alt } } as unknown as FeedItem; | |
| 10 | expect(feedNote(look)).toEqual({ note: alt }); | |
| 11 | expect(feedNote({ id: "j", kind: "run" } as unknown as FeedItem)).toEqual({}); | |
| 12 | }); |
Principle 8/design: inline style duplicates
.look[data-slot="feed"](160x100) already in components.ts, and a hand-rolled span is not a named component. Drop the inline style and rely on the class; thedata-pendinghook can carry a muted background. Also aria-label 'picture not ready' is fine, but keep the label short.