diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f09cac..87e626c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,3 @@ -# Runs the same gate as `pnpm check` on every pull request. name: CI on: @@ -26,5 +25,29 @@ jobs: test-results/ playwright-report/ retention-days: 7 - - name: Lighthouse + + lighthouse: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + - run: corepack enable + - run: pnpm install --frozen-lockfile + - name: Build the production site + run: pnpm build + env: + SHOW_SAMPLE_CONTENT: "false" + NEXT_PUBLIC_SITE_URL: https://flutter.ph + NEXT_PUBLIC_GA_MEASUREMENT_ID: ${{ vars.GA_MEASUREMENT_ID }} + - name: Audit the production export run: pnpm lighthouse + - uses: actions/upload-artifact@v4 + if: always() + with: + name: lighthouse-production + path: .lighthouseci/ + include-hidden-files: true + retention-days: 7 diff --git a/.lighthouserc.json b/.lighthouserc.json index 7eb235e..656419f 100644 --- a/.lighthouserc.json +++ b/.lighthouserc.json @@ -3,14 +3,12 @@ "collect": { "startServerCommand": "pnpm start", "startServerReadyPattern": "Accepting connections", - "url": ["http://localhost:3000/"], + "url": ["http://localhost:3000/", "http://localhost:3000/events/shipaton-manila-2026"], "numberOfRuns": 3, "settings": { - "preset": "perf", "formFactor": "mobile", "throttlingMethod": "simulate", - "onlyCategories": ["performance", "accessibility", "best-practices", "seo"], - "skipAudits": ["is-crawlable"] + "onlyCategories": ["performance", "accessibility", "best-practices", "seo"] } }, "assert": { @@ -22,6 +20,7 @@ "categories:accessibility": ["error", { "minScore": 0.95 }], "categories:best-practices": ["error", { "minScore": 0.95 }], "categories:seo": ["error", { "minScore": 0.95 }], + "is-crawlable": ["error", { "minScore": 1 }], "largest-contentful-paint": [ "error", { "maxNumericValue": 2000, "aggregationMethod": "median-run" } diff --git a/README.md b/README.md index 6b0fb2f..8428366 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,14 @@ To try it on your phone, run `pnpm dev -H 0.0.0.0` and open `http://.yaml`) diff --git a/docs/search-performance.md b/docs/search-performance.md new file mode 100644 index 0000000..e889ba1 --- /dev/null +++ b/docs/search-performance.md @@ -0,0 +1,18 @@ +# Check search visibility after deployment + +A green Lighthouse report tests the build. It does not mean Google indexed the pages or that anyone found them in search. + +1. After the GitHub Pages deployment, open [the production sitemap](https://flutter.ph/sitemap.xml). Check that the homepage and published event URLs appear and sample entries do not. +2. In [Search Console](https://search.google.com/search-console), select the verified flutter.ph property. Submit the sitemap under **Sitemaps**. Use **URL inspection** on the homepage and one event: record the indexing verdict, last crawl and Google-selected canonical. A newly published event may not be indexed yet. +3. Under **Performance → Search results**, use Web search and a completed 28-day period. Export clicks, impressions, CTR and average position for the exact queries “flutter philippines” and “flutter meetup manila”. Keep the dates with the export. Compare against the next complete 28-day period. A missing query is not proof of zero searches. +4. Use the event page filter to see which queries actually surface event pages. Look for relevant impressions and clicks, not just changes in average position. + +## Repeatable export + +As an alternative to using the UI, use a short-lived OAuth access token for a Google account with access to the verified property and the Search Console API enabled. Set `SEARCH_CONSOLE_ACCESS_TOKEN` in the shell, not in the repository. For a URL-prefix property, also set `SEARCH_CONSOLE_PROPERTY=https://flutter.ph/` (default: `sc-domain:flutter.ph`). + +```sh +node scripts/search-baseline.mjs --submit-sitemap > ~/flutter-ph-search-baseline.json +``` + +Omit `--submit-sitemap` for read-only checks. Submission requires the `webmasters` scope; reporting also works with `webmasters.readonly`. The script checks that the event sitemap is live before contacting Google. It reports the index status of the homepage and one published event, plus the two exact queries over 28 days ending four days ago. A null metrics row means Google did not return data. Save dated copies outside the repo. See the [Search Console API reference](https://developers.google.com/webmaster-tools/v1/api_reference_index). diff --git a/e2e/legacy-redirects.spec.ts b/e2e/legacy-redirects.spec.ts index 688147a..eb9e417 100644 --- a/e2e/legacy-redirects.spec.ts +++ b/e2e/legacy-redirects.spec.ts @@ -18,6 +18,7 @@ test.describe("legacy flutter.ph URLs keep working", () => { expect(html).toContain(`content="0; url=${target.to}"`); expect(html).toContain(`href="${target.to}"`); expect(html).toContain('name="robots" content="noindex'); + expect(html).not.toContain('rel="canonical"'); }); } } diff --git a/e2e/routes.ts b/e2e/routes.ts index 7634cd0..ca512a3 100644 --- a/e2e/routes.ts +++ b/e2e/routes.ts @@ -1,2 +1,5 @@ /** Key routes checked for accessibility and captured as screenshots. Grows each phase. */ -export const keyRoutes = [{ path: "/", name: "home" }] as const; +export const keyRoutes = [ + { path: "/", name: "home" }, + { path: "/events/shipaton-manila-2026", name: "event" }, +] as const; diff --git a/e2e/search-discovery.spec.ts b/e2e/search-discovery.spec.ts new file mode 100644 index 0000000..36735f4 --- /dev/null +++ b/e2e/search-discovery.spec.ts @@ -0,0 +1,129 @@ +import { existsSync } from "node:fs"; +import { expect, test } from "@playwright/test"; +import { allEvents } from "../.content-collections/generated/index.js"; +import { formatEventRange } from "../src/lib/dates"; +import { site, social } from "../src/lib/site"; + +const home = new URL("/", site.url).href; +const eventPath = (slug: string) => `/events/${encodeURIComponent(slug)}`; +const events = allEvents.filter( + (event) => !event.sample || existsSync(`out${eventPath(event.slug)}.html`), +); + +test.use({ javaScriptEnabled: false }); +test.beforeEach(({}, testInfo) => { + test.skip(testInfo.project.name !== "desktop-1280", "Static output is viewport-independent."); +}); + +test("robots and sitemap expose the homepage and published event details", async ({ request }) => { + const robots = await request.get("/robots.txt"); + expect(robots.ok()).toBe(true); + const rules = await robots.text(); + expect(rules).toMatch(/^User-agent:\s*\*\s*$/im); + expect(rules).toMatch(/^Allow:\s*\/\s*$/im); + expect(rules.split(/\r?\n/)).toContain(`Sitemap: ${home}sitemap.xml`); + + const sitemap = await request.get("/sitemap.xml"); + expect(sitemap.ok()).toBe(true); + const xml = await sitemap.text(); + const urls = Array.from(xml.matchAll(/(.*?)<\/loc>/g), ([, url]) => url); + const published = [home, ...events.map((event) => new URL(eventPath(event.slug), home).href)]; + expect(urls.toSorted()).toEqual(published.toSorted()); +}); + +test("homepage metadata, linked entities and answers are available without JavaScript", async ({ + page, +}) => { + await page.goto("/"); + const canonical = page.locator('link[rel="canonical"]'); + await expect(canonical).toHaveCount(1); + expect(new URL((await canonical.getAttribute("href"))!).href).toBe(home); + expect(await page.locator('meta[name="robots"][content*="noindex" i]').count()).toBe(0); + const title = await page.title(); + expect(title).toContain(site.name); + expect(title).not.toBe(site.name); + + const description = await page.locator('meta[name="description"]').getAttribute("content"); + expect(description).toBeTruthy(); + for (const tag of ['meta[property="og:description"]', 'meta[name="twitter:description"]']) { + await expect(page.locator(tag)).toHaveAttribute("content", description!); + } + const ogUrl = await page.locator('meta[property="og:url"]').getAttribute("content"); + expect(new URL(ogUrl!).href).toBe(home); + + const graphs = await page.locator('script[type="application/ld+json"]').allTextContents(); + const nodes = graphs.flatMap((text) => JSON.parse(text)["@graph"] ?? []); + const organization = nodes.find((node) => node["@type"] === "Organization"); + const website = nodes.find((node) => node["@type"] === "WebSite"); + expect(organization).toMatchObject({ name: site.name }); + expect(organization["@id"]).toBeTruthy(); + expect(organization.sameAs).toEqual(expect.arrayContaining([social.github.href])); + expect(website).toMatchObject({ publisher: { "@id": organization["@id"] } }); + + await expect(page.locator("#get-involved h2")).toHaveText(/\?/); + await expect(page.locator("#get-involved")).toContainText(/Metro Manila/); + await expect(page.locator("#learn h2")).toHaveText(/\?/); + await expect(page.locator("#learn")).toContainText(/codelab/i); + const join = page.locator("#join-community"); + await expect(join.locator("h2")).toHaveText(/join Flutter Philippines/i); + await expect(join.getByRole("link", { name: /Facebook/i })).toHaveAttribute("href", site.joinUrl); + await expect(join.getByRole("link", { name: /Luma/i })).toHaveAttribute("href", social.luma.href); +}); + +test("homepage links to every published community event without JavaScript", async ({ page }) => { + await page.goto("/"); + const hrefs = await page + .locator("main a[href]") + .evaluateAll((links) => links.map((link) => link.getAttribute("href"))); + for (const event of events) { + expect(hrefs, event.title).toContain(eventPath(event.slug)); + } +}); + +for (const event of events) { + test(`event detail: ${event.slug}`, async ({ page }) => { + const path = eventPath(event.slug); + const url = new URL(path, home).href; + expect((await page.goto(path))?.status()).toBe(200); + await expect(page.locator("h1")).toHaveText(event.title); + await expect(page.locator("main")).toContainText(event.summary); + await expect(page.locator("main")).toContainText( + formatEventRange(event.startsAt, event.endsAt), + ); + if (event.registered) { + await expect(page.locator("main")).toContainText(`${event.registered} registered`); + } + await expect(page).toHaveTitle(`${event.title} | ${site.name}`); + await expect(page.locator('meta[name="description"]')).toHaveAttribute( + "content", + event.summary, + ); + await expect(page.locator('link[rel="canonical"]')).toHaveAttribute("href", url); + await expect(page.locator('meta[property="og:url"]')).toHaveAttribute("content", url); + await expect(page.locator('meta[name="robots"][content*="noindex" i]')).toHaveCount(0); + if (event.rsvpUrl) { + expect( + await page + .locator("main a") + .evaluateAll((links) => links.map((a) => a.getAttribute("href"))), + ).toContain(event.rsvpUrl); + } + + const scripts = await page.locator('script[type="application/ld+json"]').allTextContents(); + const item = scripts.map((text) => JSON.parse(text)).find((doc) => doc["@type"] === "Event"); + expect(item).toMatchObject({ + name: event.title, + url, + description: event.summary, + startDate: event.startsAt, + endDate: event.endsAt, + organizer: { "@type": "Organization", name: site.name }, + }); + if (event.format === "in-person" && event.venue) { + expect(item.location).toMatchObject({ "@type": "Place", name: event.venue.name }); + await expect(page.locator("main")).toContainText(event.venue.name); + } else if (event.format === "online") { + expect(item.location).toMatchObject({ "@type": "VirtualLocation" }); + } + }); +} diff --git a/scripts/search-baseline.mjs b/scripts/search-baseline.mjs new file mode 100644 index 0000000..1ddb00a --- /dev/null +++ b/scripts/search-baseline.mjs @@ -0,0 +1,57 @@ +const origin = "https://flutter.ph/"; +const sitemap = new URL("sitemap.xml", origin).href; +const property = process.env.SEARCH_CONSOLE_PROPERTY || "sc-domain:flutter.ph"; +const token = process.env.SEARCH_CONSOLE_ACCESS_TOKEN; +const submit = process.argv.includes("--submit-sitemap"); + +if (!token) { + throw new Error("Set SEARCH_CONSOLE_ACCESS_TOKEN for a verified flutter.ph property."); +} + +async function google(url, method, data) { + const response = await fetch(url, { + method, + redirect: "error", + headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }, + body: data && JSON.stringify(data), + }); + if (!response.ok) throw new Error(`Search Console: ${response.status} ${await response.text()}`); + return method === "PUT" ? null : response.json(); +} + +const api = `https://www.googleapis.com/webmasters/v3/sites/${encodeURIComponent(property)}`; +const response = await fetch(sitemap); +if (!response.ok) throw new Error(`Deploy the event sitemap first (HTTP ${response.status}).`); +const urls = [...(await response.text()).matchAll(/([^<]+)<\/loc>/g)].map((m) => m[1]); +const event = urls.find((url) => url.startsWith(origin + "events/")); +if (!urls.includes(origin) || !event) throw new Error("The event sitemap is not live yet."); +if (submit) await google(`${api}/sitemaps/${encodeURIComponent(sitemap)}`, "PUT"); + +const date = (offset) => new Date(Date.now() - offset * 86400000).toISOString().slice(0, 10); +const period = { startDate: date(31), endDate: date(4) }; +const inspections = []; +for (const inspectionUrl of [origin, event]) { + const { inspectionResult } = await google( + "https://searchconsole.googleapis.com/v1/urlInspection/index:inspect", + "POST", + { inspectionUrl, siteUrl: property, languageCode: "en-US" }, + ); + inspections.push({ url: inspectionUrl, ...inspectionResult.indexStatusResult }); +} + +const queries = []; +for (const query of ["flutter philippines", "flutter meetup manila"]) { + const { rows = [] } = await google(`${api}/searchAnalytics/query`, "POST", { + ...period, + type: "web", + dimensions: ["query"], + dimensionFilterGroups: [ + { filters: [{ dimension: "query", operator: "equals", expression: query }] }, + ], + }); + queries.push({ query, metrics: rows[0] ?? null }); +} + +console.log( + JSON.stringify({ property, period, sitemapSubmitted: submit, inspections, queries }, null, 2), +); diff --git a/src/app/events/[slug]/page.tsx b/src/app/events/[slug]/page.tsx new file mode 100644 index 0000000..05a9d1c --- /dev/null +++ b/src/app/events/[slug]/page.tsx @@ -0,0 +1,179 @@ +import { MDXContent } from "@content-collections/mdx/react"; +import type { Metadata } from "next"; +import Link from "next/link"; +import { notFound } from "next/navigation"; +import { PillLink } from "@/components/ui/PillLink"; +import { getEvents, type SiteEvent } from "@/lib/content"; +import { eventPhase, formatEventRange } from "@/lib/dates"; +import { eventPath } from "@/lib/event-path"; +import { site } from "@/lib/site"; + +type Props = { params: Promise<{ slug: string }> }; + +export const dynamicParams = false; + +export function generateStaticParams() { + return getEvents().map(({ slug }) => ({ slug })); +} + +async function readEvent(params: Props["params"]) { + const { slug } = await params; + return getEvents().find((event) => event.slug === slug) ?? notFound(); +} + +export async function generateMetadata({ params }: Props): Promise { + const event = await readEvent(params); + const url = new URL(eventPath(event.slug), site.url).href; + const title = `${event.title} | ${site.name}`; + const image = { url: event.coverImage ?? "/og.jpg", alt: event.coverAlt ?? site.name }; + return { + title: event.title, + description: event.summary, + alternates: { canonical: url }, + openGraph: { + title, + description: event.summary, + url, + type: "website", + siteName: site.name, + locale: site.locale, + images: [image], + }, + twitter: { + card: "summary_large_image", + site: "@flutter_ph", + title, + description: event.summary, + images: [image], + }, + }; +} + +const formats = { online: "Online", "in-person": "In person", hybrid: "Hybrid" }; +const modes = { + online: "OnlineEventAttendanceMode", + "in-person": "OfflineEventAttendanceMode", + hybrid: "MixedEventAttendanceMode", +}; +const resourceLabels = { + slides: "Presentation slides", + recording: "Event recording", + photos: "Event photos", +} as const; + +function eventSchema(event: SiteEvent) { + const url = new URL(eventPath(event.slug), site.url).href; + const venue = event.venue && { + "@type": "Place", + name: event.venue.name, + address: event.venue.address, + }; + const online = { "@type": "VirtualLocation", name: "Online" }; + return { + "@context": "https://schema.org", + "@type": "Event", + "@id": url + "#event", + url, + name: event.title, + description: event.summary, + startDate: event.startsAt, + endDate: event.endsAt, + eventStatus: event.cancelled ? "https://schema.org/EventCancelled" : undefined, + eventAttendanceMode: `https://schema.org/${modes[event.format]}`, + location: + event.format === "online" ? online : event.format === "hybrid" ? [venue, online] : venue, + organizer: { + "@type": "Organization", + "@id": new URL("/#organization", site.url).href, + name: site.name, + url: new URL("/", site.url).href, + }, + image: event.coverImage ? new URL(event.coverImage, site.url).href : undefined, + sameAs: event.rsvpUrl, + }; +} + +export default async function EventPage({ params }: Props) { + const event = await readEvent(params); + const past = eventPhase(event) === "past"; + const resources = (Object.keys(resourceLabels) as (keyof typeof resourceLabels)[]).filter( + (key) => event.resources[key], + ); + return ( +
+