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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/14456-a-wave-s-page-has-a-share-card-title-and → main 4 commits fork

  • Merged. scout/14456-a-wave-s-page-has-a-share-card-title-and was merged into main as 74eea2e.

Review

Sign in to review this change.
3 files changed +44 −3
src/web/layout.ts +13 −3
@@ -131,6 +131,12 @@ export interface PageOptions {
131131 * signed-out unfurler; absent, the forge's own card (`/og/site.png`) stands in.
132132 */
133133 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 };
134140 /** The name a preview gives the place: a repository page passes `owner/name`; absent, "forge". */
135141 siteName?: string;
136142 /** This page's feed, advertised in the head so a reader can find it. */
@@ -799,6 +805,7 @@ export function shareHead(o: {
799805 description: string;
800806 image?: string | undefined;
801807 siteName?: string | undefined;
808 card?: "summary" | "summary_large_image" | undefined;
802809 }): Html {
803810 const title = shareTitle(o.title);
804811 const own = o.image !== undefined && o.image.startsWith("/og/") && o.image !== "/og/site.png";
@@ -818,7 +825,7 @@ export function shareHead(o: {
818825 <meta property="og:image:width" content="1200" />
819826 <meta property="og:image:height" content="630" />
820827 <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"}" />
822829 <meta name="twitter:title" content="${title}" />
823830 <meta name="twitter:description" content="${o.description}" />
824831 <meta name="twitter:image" content="${image}" />
@@ -917,13 +924,16 @@ export function page(options: PageOptions, status = 200): Response {
917924 ? html`<meta name="robots" content="noindex" />`
918925 : null
919926 }
920 ${shareHead({
927 ${options.share === false
928 ? null
929 : shareHead({
930 card: options.share?.card,
921931 origin: ctx.url.origin,
922932 // Only a page that exists has a canonical address. An error page
923933 // never echoes the path that was asked for: two dead links must be
924934 // the same bytes, or the difference tells a guesser something.
925935 url: status === 200 ? `${ctx.url.origin}${ctx.url.pathname}` : undefined,
926 title: options.title,
936 title: options.share?.title ?? options.title,
927937 description: pageDescription(options),
928938 image: options.ogImage,
929939 siteName: options.siteName,
src/web/pages/waves.ts +14
@@ -21,6 +21,7 @@ import { waveDuration } from "../../story/wave_duration.ts";
2121 import { carriedPulls, inLandingOrder, pullPath } from "../../story/wave_pulls.ts";
2222 import { fromWave, pullRefs, readWave, readWaves, sizeWords, waveSize } from "../../story/waves.ts";
2323 import { FIRST_WAVE_BUTTON, FIRST_WAVE_TELL, NO_WAVES, landedSentence, waveSentence } from "../../story/words.ts";
24 import { wordClip } from "../../text/word_clip.ts";
2425 import { loadRepo, notFoundPage, repoBase, scopeHeader } from "../chrome.ts";
2526 import { escapeHtml, html, type Html } from "../html.ts";
2627 import { page } from "../layout.ts";
@@ -295,11 +296,24 @@ export async function wavePage(ctx: Ctx): Promise<Response> {
295296 crumbs: scope.crumbs,
296297 palette: scope.palette,
297298 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 : {}),
298309 });
299310 notePhase(ctx.request, "render", performance.now() - rendering);
300311 return response;
301312 }
302313
314 /** The longest description a wave's card carries. */
315 const WAVE_CARD_MAX = 200;
316
303317 /**
304318 * The wave's progress: the words in a muted line, the bar on its own row below at a fixed width so
305319 * 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", () => {
204204 expect(await (await get("/alice/priv/waves/1.0.0")).text()).toContain("Secret launch");
205205 });
206206
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 &lt;b&gt;links&lt;/b&gt;"');
210 expect(body).toContain('<meta property="og:description" content="why &lt;u&gt;one&lt;/u&gt;"');
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
207224 test("waves.atom is Atom, one entry per wave, newest first", async () => {
208225 const res = await get("/alice/pub/waves.atom");
209226 expect(res.status).toBe(200);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs