Public: anyone can read this; the crew can change it.
A wave's page has a share card: title and description tags drawn from its milestone, so the link unfurls #14473
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14456-a-wave-s-page-has-a-share-card-title-and → main 4 commits fork
3 files
changed +44
−3
src/web/layout.ts +13 −3
| @@ -131,6 +131,12 @@ export interface PageOptions { | ||
| 131 | 131 | * signed-out unfurler; absent, the forge's own card (`/og/site.png`) stands in. |
| 132 | 132 | */ |
| 133 | 133 | ogImage?: string | undefined; |
| 134 | /** | |
| 135 | * Share-card control for a page whose card is its own: `false` sets no description, Open Graph, | |
| 136 | * Twitter or canonical tags (a private page tells an unfurler nothing); `card` names the | |
| 137 | * Twitter card, and `title` the card's title where the tab's would not read well. | |
| 138 | */ | |
| 139 | share?: false | { card?: "summary" | "summary_large_image"; title?: string }; | |
| 134 | 140 | /** The name a preview gives the place: a repository page passes `owner/name`; absent, "forge". */ |
| 135 | 141 | siteName?: string; |
| 136 | 142 | /** This page's feed, advertised in the head so a reader can find it. */ |
| @@ -799,6 +805,7 @@ export function shareHead(o: { | ||
| 799 | 805 | description: string; |
| 800 | 806 | image?: string | undefined; |
| 801 | 807 | siteName?: string | undefined; |
| 808 | card?: "summary" | "summary_large_image" | undefined; | |
| 802 | 809 | }): Html { |
| 803 | 810 | const title = shareTitle(o.title); |
| 804 | 811 | const own = o.image !== undefined && o.image.startsWith("/og/") && o.image !== "/og/site.png"; |
| @@ -818,7 +825,7 @@ export function shareHead(o: { | ||
| 818 | 825 | <meta property="og:image:width" content="1200" /> |
| 819 | 826 | <meta property="og:image:height" content="630" /> |
| 820 | 827 | <meta property="og:image:alt" content="${alt}" /> |
| 821 | <meta name="twitter:card" content="summary_large_image" /> | |
| 828 | <meta name="twitter:card" content="${o.card ?? "summary_large_image"}" /> | |
| 822 | 829 | <meta name="twitter:title" content="${title}" /> |
| 823 | 830 | <meta name="twitter:description" content="${o.description}" /> |
| 824 | 831 | <meta name="twitter:image" content="${image}" /> |
| @@ -917,13 +924,16 @@ export function page(options: PageOptions, status = 200): Response { | ||
| 917 | 924 | ? html`<meta name="robots" content="noindex" />` |
| 918 | 925 | : null |
| 919 | 926 | } |
| 920 | ${shareHead({ | |
| 927 | ${options.share === false | |
| 928 | ? null | |
| 929 | : shareHead({ | |
| 930 | card: options.share?.card, | |
| 921 | 931 | origin: ctx.url.origin, |
| 922 | 932 | // Only a page that exists has a canonical address. An error page |
| 923 | 933 | // never echoes the path that was asked for: two dead links must be |
| 924 | 934 | // the same bytes, or the difference tells a guesser something. |
| 925 | 935 | url: status === 200 ? `${ctx.url.origin}${ctx.url.pathname}` : undefined, |
| 926 | title: options.title, | |
| 936 | title: options.share?.title ?? options.title, | |
| 927 | 937 | description: pageDescription(options), |
| 928 | 938 | image: options.ogImage, |
| 929 | 939 | siteName: options.siteName, |
src/web/pages/waves.ts +14
| @@ -21,6 +21,7 @@ import { waveDuration } from "../../story/wave_duration.ts"; | ||
| 21 | 21 | import { carriedPulls, inLandingOrder, pullPath } from "../../story/wave_pulls.ts"; |
| 22 | 22 | import { fromWave, pullRefs, readWave, readWaves, sizeWords, waveSize } from "../../story/waves.ts"; |
| 23 | 23 | import { FIRST_WAVE_BUTTON, FIRST_WAVE_TELL, NO_WAVES, landedSentence, waveSentence } from "../../story/words.ts"; |
| 24 | import { wordClip } from "../../text/word_clip.ts"; | |
| 24 | 25 | import { loadRepo, notFoundPage, repoBase, scopeHeader } from "../chrome.ts"; |
| 25 | 26 | import { escapeHtml, html, type Html } from "../html.ts"; |
| 26 | 27 | import { page } from "../layout.ts"; |
| @@ -295,11 +296,24 @@ export async function wavePage(ctx: Ctx): Promise<Response> { | ||
| 295 | 296 | crumbs: scope.crumbs, |
| 296 | 297 | palette: scope.palette, |
| 297 | 298 | body, |
| 299 | // The card reads as the milestone: its headline, its first why (else the headline again). A | |
| 300 | // private repository's wave sets none, so a pasted link tells an unfurler nothing. | |
| 301 | ...(repo.visibility !== "public" | |
| 302 | ? { share: false as const } | |
| 303 | : entry.ok | |
| 304 | ? { | |
| 305 | share: { card: "summary" as const, title: entry.wave.headline }, | |
| 306 | description: wordClip(entry.wave.highlights[0]?.why?.trim() || entry.wave.headline, WAVE_CARD_MAX), | |
| 307 | } | |
| 308 | : {}), | |
| 298 | 309 | }); |
| 299 | 310 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 300 | 311 | return response; |
| 301 | 312 | } |
| 302 | 313 | |
| 314 | /** The longest description a wave's card carries. */ | |
| 315 | const WAVE_CARD_MAX = 200; | |
| 316 | ||
| 303 | 317 | /** |
| 304 | 318 | * The wave's progress: the words in a muted line, the bar on its own row below at a fixed width so |
| 305 | 319 | * nothing shifts at 360px. Nothing when no milestone moved; words only (no bar) at zero issues. |
test/waves-page.test.ts +17
| @@ -204,6 +204,23 @@ describe("waves page", () => { | ||
| 204 | 204 | expect(await (await get("/alice/priv/waves/1.0.0")).text()).toContain("Secret launch"); |
| 205 | 205 | }); |
| 206 | 206 | |
| 207 | test("a public wave's page carries a share card, escaped; a private one carries none", async () => { | |
| 208 | const body = await (await get("/alice/pub/waves/0.3.0")).text(); | |
| 209 | expect(body).toContain('<meta property="og:title" content="Evil <b>links</b>"'); | |
| 210 | expect(body).toContain('<meta property="og:description" content="why <u>one</u>"'); | |
| 211 | expect(body).toContain('<meta name="twitter:card" content="summary"'); | |
| 212 | expect(body).toContain('<link rel="canonical" href="http://'); | |
| 213 | expect(body).not.toContain("<b>links"); | |
| 214 | const plain = await (await get("/alice/pub/waves/0.10.0")).text(); | |
| 215 | expect(plain).toContain('<meta property="og:title" content="Tenth"'); | |
| 216 | const priv1 = await (await get("/alice/priv/waves/1.0.0")).text(); | |
| 217 | expect(priv1).toContain("Secret launch"); | |
| 218 | expect(priv1).not.toContain("og:title"); | |
| 219 | expect(priv1).not.toContain("og:description"); | |
| 220 | expect(priv1).not.toContain("twitter:card"); | |
| 221 | expect(priv1).not.toContain('rel="canonical"'); | |
| 222 | }); | |
| 223 | ||
| 207 | 224 | test("waves.atom is Atom, one entry per wave, newest first", async () => { |
| 208 | 225 | const res = await get("/alice/pub/waves.atom"); |
| 209 | 226 | expect(res.status).toBe(200); |
new above
offline