diff --git a/README.md b/README.md index 4ebd742..6b0fb2f 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,12 @@ Run `pnpm build` (or `pnpm build:preview`) before `pnpm test:e2e` and `pnpm test - Motion is CSS scroll-driven animation, transform-only, and switches off with reduced motion - About 3 KB of our own JavaScript on top of the framework +## Share card + +Links to flutter.ph show this preview on Facebook, X, LinkedIn and chat apps. It is rendered in Chromium with the site's own fonts by `pnpm og` into `public/og.jpg` (1200 x 630). Re-run it after changing the name, tagline or logo. + +![Share card](public/og.jpg) + ## Deploy Pushes to `main` build and publish to GitHub Pages through `.github/workflows/deploy.yml`, which also runs daily at midnight Manila time. One-time setup by a maintainer: **Settings > Pages > Source = GitHub Actions**, and the custom domain `flutter.ph`. diff --git a/docs/screenshots/desktop-about.jpg b/docs/screenshots/desktop-about.jpg index e0ef6bb..dd908b0 100644 Binary files a/docs/screenshots/desktop-about.jpg and b/docs/screenshots/desktop-about.jpg differ diff --git a/docs/screenshots/desktop-events.jpg b/docs/screenshots/desktop-events.jpg index 8ede643..97f7f82 100644 Binary files a/docs/screenshots/desktop-events.jpg and b/docs/screenshots/desktop-events.jpg differ diff --git a/package.json b/package.json index 7c813d7..deab161 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "lighthouse": "lhci autorun", "analyze": "ANALYZE=true next build --webpack", "check": "pnpm typecheck && pnpm lint && pnpm format:check && pnpm test && pnpm build:preview && pnpm test:e2e && pnpm test:perf", - "test:perf": "playwright test --config playwright.perf.config.ts" + "test:perf": "playwright test --config playwright.perf.config.ts", + "og": "node scripts/build-og.mjs" }, "dependencies": { "@fontsource-variable/google-sans": "^5.3.2", diff --git a/public/og.jpg b/public/og.jpg new file mode 100644 index 0000000..189961d Binary files /dev/null and b/public/og.jpg differ diff --git a/scripts/build-og.mjs b/scripts/build-og.mjs new file mode 100644 index 0000000..2981752 --- /dev/null +++ b/scripts/build-og.mjs @@ -0,0 +1,51 @@ +#!/usr/bin/env node +// Renders the share card (Open Graph and X/Twitter) to public/og.jpg, 1200x630. +// Uses real Chromium so the card is set in the site's own Google Sans. +// Usage: pnpm og (re-run after changing the name, tagline or logo) +import { chromium } from "@playwright/test"; +import { readFile, writeFile } from "node:fs/promises"; +import sharp from "sharp"; + +const root = new URL("../", import.meta.url); +const font = (w) => + readFile( + new URL( + "node_modules/@fontsource-variable/google-sans/files/google-sans-latin-wght-normal.woff2", + root, + ), + ).then((b) => `data:font/woff2;base64,${b.toString("base64")}`); +const logo = await readFile(new URL("public/flutter-ph-logo.svg", root), "utf8"); +const fontUrl = await font(); + +const html = `
+

Flutter Philippines

+

Join thousands of developers, designers and founders building apps with Flutter, Dart and AI.

+
flutter.ph
+
`; + +const browser = await chromium.launch(); +const page = await browser.newPage({ + viewport: { width: 1200, height: 630 }, + deviceScaleFactor: 1, +}); +await page.setContent(html, { waitUntil: "load" }); +await page.evaluate(() => document.fonts.ready); +const png = await page.screenshot({ type: "png" }); +await browser.close(); + +const jpg = await sharp(png) + .jpeg({ quality: 88, mozjpeg: true, chromaSubsampling: "4:4:4" }) + .toBuffer(); +await writeFile(new URL("public/og.jpg", root), jpg); +console.log(`public/og.jpg written (${Math.round(jpg.length / 1024)} KB, 1200x630)`); diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 0790b2d..70256a1 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -10,12 +10,35 @@ import { themeScript } from "./theme-script"; import { site } from "@/lib/site"; import "./globals.css"; +/** Share card, generated by `pnpm og` into public/og.jpg. */ +const ogAlt = + "Flutter Philippines: join thousands of developers, designers and founders building apps with Flutter, Dart and AI."; + export const metadata: Metadata = { metadataBase: new URL(site.url), title: { default: site.name, template: `%s | ${site.name}` }, - description: site.tagline, + description: + "A community of designers, developers and founders in the Philippines building apps with Flutter, Dart and AI. Events, learning resources and ways to join.", applicationName: site.name, - openGraph: { siteName: site.name, locale: site.locale, type: "website" }, + alternates: { canonical: "/" }, + openGraph: { + siteName: site.name, + title: site.name, + description: + "Join thousands of developers, designers and founders building apps with Flutter, Dart and AI.", + url: "/", + locale: site.locale, + type: "website", + images: [{ url: "/og.jpg", width: 1200, height: 630, alt: ogAlt }], + }, + twitter: { + card: "summary_large_image", + site: "@flutter_ph", + title: site.name, + description: + "Join thousands of developers, designers and founders building apps with Flutter, Dart and AI.", + images: [{ url: "/og.jpg", alt: ogAlt }], + }, }; export const viewport: Viewport = {