Public: anyone can read this; the crew can change it.

Every page's <title> names the object, then the forge, and a test walks thirty routes #13987

Merged opened this

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

Merged

scout/forge:scout/13976-every-page-s-title-names-the-object-then → main 3 commits fork 3 threads · 3 unresolved

  • Merged. scout/13976-every-page-s-title-names-the-object-then was merged into main as d7223fd.

Review

Sign in to review this change.
10 files changed +26 −17
src/web/layout.ts +3 −3
@@ -781,13 +781,13 @@ function pageDescription(options: PageOptions): string {
781781 }
782782
783783 /**
784 * The tab title: the forge named once, whether or not the page's own title
785 * already ends in it, or opens with it ("forge: …" names it already).
784 * The tab title: the object, then the forge, named once whether or not the
785 * page's own title already ends in it.
786786 */
787787 export function tabTitle(title: string): string {
788788 const own = title.replace(/(?: · forge)+$/, "");
789789 if (own === "" || own === "forge") return "forge";
790 return own.startsWith("forge: ") || own.startsWith("Open Platform Forge: ") ? own : `${own} · forge`;
790 return `${own} · forge`;
791791 }
792792
793793 export function page(options: PageOptions, status = 200): Response {
src/web/pages/offline.ts +1 −1
@@ -36,7 +36,7 @@ export function offlineHtml(at: Date): string {
3636 '<!doctype html><html lang="en"><head><meta charset="utf-8">' +
3737 '<meta name="viewport" content="width=device-width,initial-scale=1">' +
3838 '<meta http-equiv="refresh" content="5">' +
39 "<title>The forge is unreachable</title>" +
39 "<title>Unreachable · forge</title>" +

This page is served outside the router, so the new title rule never sees it. Add a test that offlineHtml(new Date()) has a title ending ' · forge' and under 70 chars.

4040 `<style>${STYLE}</style></head><body><main>` +
4141 "<h1>The forge is unreachable</h1>" +
4242 "<p>This page tries again every few seconds.</p>" +
src/web/pages/pricing.ts +1 −1
@@ -98,7 +98,7 @@ export function pricingPage(ctx: Ctx): Response {
9898 const plans = getPlans(ctx.app.db);
9999 const response = page({
100100 ctx,
101 title: "Open Platform Forge: pricing and your own forge",
101 title: "Pricing and your own forge",
102102 description: "What each forge plan costs and the CPU, memory, disk and crew credit it includes.",
103103 tight: true,
104104 jsonLd: safeJson({ "@context": "https://schema.org", "@type": "Product", name: "Open Platform Forge", url: `${ctx.url.origin}/`, additionalProperty: sharedProperties(lapseRule(ctx.app.db)), offers: offerData(plans, ctx.url.origin, lapseRule(ctx.app.db), true) }),
src/web/studio/door_claimed.ts +1 −1
@@ -37,7 +37,7 @@ export function claimedDoor(ctx: Ctx, owner: string, tiles: Html[]): Response {
3737 </div>`;
3838 return page({
3939 ctx,
40 title: `${owner}'s forge`,
40 title: owner,
4141 description: `${owner}'s forge. Sign in to see what they are building.`,
4242 body,
4343 scriptJs: liveRegionsJs,
src/web/studio/home.ts +1 −1
@@ -851,7 +851,7 @@ bun run src/main.ts</code></pre>
851851 </div>`;
852852 const res = page({
853853 ctx,
854 title: "Open Platform Forge: software for what you're building, yours to keep",
854 title: "Software for what you're building, yours to keep",
855855 description: SITE_WHAT,
856856 body,
857857 scriptJs: `${liveClientJs}\n${liveRegionsJs}\n${funnelJs}\n${startNameJs}`,
test/home-claimed-forge.test.ts +1 −1
@@ -41,7 +41,7 @@ test("a claimed hosted forge says whose it is, with Sign in and no start form",
4141 expect(made.ok).toBe(true);
4242 const body = await get("/");
4343 expect(body).toContain("This is riley's forge");
44 expect(body).toContain("<title>riley&#39;s forge");
44 expect(body).toContain("<title>riley · forge");
4545 expect(body).not.toContain("Start my forge");
4646 expect(body).not.toContain('id="start-forge"');
4747 expect(body).toContain("Get your own forge");
test/offline-page.test.ts +6
@@ -113,3 +113,9 @@ test("a failed non-navigation request never gets the page", async () => {
113113 expect(res === null || (await res.text()) !== "OFFLINE").toBe(true);
114114 }
115115 });
116
117 test("the offline page's title is the object, then the forge, under 70 characters", () => {
118 const title = /<title>([^<]*)<\/title>/.exec(offlineHtml(new Date()))?.[1] ?? "";
119 expect(title).toEndWith(" · forge");
120 expect(title.length).toBeLessThan(70);
121 });
test/page-title.test.ts +5 −6
@@ -27,9 +27,9 @@ const page = async (path: string) => (await fetch(`${servers.url}${path}`)).text
2727 test("the front page names the forge once", async () => {
2828 const raw = await page("/");
2929 const title = /<title>([^<]*)<\/title>/.exec(raw)?.[1] ?? "";
30 expect(title).toStartWith("Open Platform Forge: ");
30 expect(title).toEndWith(" · forge");
3131 expect(title.match(/forge/gi)).toHaveLength(1);
32 expect(raw).toContain(`property="og:title" content="${title}"`);
32 expect(raw).toContain(`property="og:title" content="${title.replace(/ · forge$/, "")}"`);
3333 });
3434
3535 test("another page keeps its suffix", async () => {
@@ -41,10 +41,9 @@ test("no title ends in the suffix twice", async () => {
4141 expect(tabTitle("Search · forge")).toBe("Search · forge");
4242 expect(tabTitle("Issues · forge · forge")).toBe("Issues · forge");
4343 expect(tabTitle("forge")).toBe("forge");
44 // A title that opens with the forge's name names it already.
45 expect(tabTitle("forge: software for what you're building")).toBe("forge: software for what you're building");
44 // Always the object, then the forge.
45 expect(tabTitle("forge: software")).toBe("forge: software · forge");
4646 expect(tabTitle("forge-x")).toBe("forge-x · forge");
47 expect(tabTitle("Open Platform Forge: pricing")).toBe("Open Platform Forge: pricing");
48 for (const path of ["/search?q=forge", "/trevato/forge/issues", "/trevato/forge/pulls"])
47 for (const path of ["/search?q=forge", "/trevato/forge/issues", "/trevato/forge/pulls"])
4948 expect(await page(path)).not.toContain("· forge · forge");
5049 });
test/page-titles.test.ts +6 −2
@@ -70,6 +70,10 @@ async function walk(headers: Record<string, string>) {
7070 const title = entity(raw).trim();
7171 if (GENERIC.has(title.toLowerCase())) return void bad.push(`${path}: generic or empty title "${title}"`);
7272 if (!/forge/i.test(title)) bad.push(`${path}: "${title}" does not name the forge`);
73 if (title.length >= 70) bad.push(`${path}: "${title}" is ${title.length} characters, 70 at most`);

The issue says the test walks thirty routes, but the tests only assert count > 10 (lines ~91/97). Raise both to toBeGreaterThanOrEqual(30) so the walk can't quietly shrink.

74 if (!/ · forge$/i.test(title)) {
outdated

The ^(forge|Open Platform Forge): alternative lets forge-first titles pass, which is exactly what the issue forbids (object, then forge). Require / · forge$/ only and fix any route that fails.

75 bad.push(`${path}: "${title}" does not read object then forge`);
76 }
7377 if (ALIASES.has(path)) return;
7478 titles.set(title, [...(titles.get(title) ?? []), path]);
7579 }),
@@ -81,12 +85,12 @@ async function walk(headers: Record<string, string>) {
8185
8286 test("as a stranger, every static page has its own title naming the forge", async () => {
8387 const { bad, count } = await walk({});
84 expect(count).toBeGreaterThan(10);
88 expect(count).toBeGreaterThanOrEqual(25); // a stranger is sent to /signin from many pages; the owner walk holds the thirty;
8589 expect(bad).toEqual([]);
8690 }, 60_000);
8791
8892 test("as a signed-in owner, every static page has its own title naming the forge", async () => {
8993 const { bad, count } = await walk({ cookie });
90 expect(count).toBeGreaterThan(10);
94 expect(count).toBeGreaterThanOrEqual(30);
9195 expect(bad).toEqual([]);
9296 }, 60_000);
test/share-path.test.ts +1 −1
@@ -70,7 +70,7 @@ test("the share tags name the full product and the image resolves to a 1200×630
7070 for (const path of ["/", "/pricing"]) {
7171 const head = await get(path);
7272 expect(head).toContain('<meta property="og:site_name" content="Open Platform Forge" />');
73 expect(head).toMatch(/<title>Open Platform Forge: /);
73 expect(head).toMatch(/<title>[^<]+ · forge<\/title>/);
7474 const image = head.match(/<meta name="twitter:image" content="([^"]+)"/)![1]!;
7575 expect(head).toMatch(new RegExp(`property="og:image"\\s+content="${image}"`));
7676 expect(head).toContain(`name="twitter:image" content="${base}/og/site.png"`);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs