Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
**Read before writing or reviewing code:**
[context/coding-standards.md](./context/coding-standards.md).

The share card and its `?v=` rule: [context/share-card.md](./context/share-card.md).

## Git — read before any `git` or `gh` command

**Default: never stage, commit, branch, push or open a PR on your own
Expand Down
23 changes: 23 additions & 0 deletions apps/site/assets/share/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Share images

Upload-ready images for the places that take a picture by hand.

| File | Size | Use |
| -------------------- | ---------- | ---------------------------------------------------------------------------------------- |
| `og-1200x630.png` | 1200 x 630 | The site card, the same bytes as `public/og.png`. For profiles and listings. |
| `og-sky.png` | 1200 x 630 | The previous card. The script reads its aurora as the sky; not for upload. |

The card stacks the shield, the wordmark and the line in a column centred in the middle
630 pixels, so an app that crops a square keeps all of it. It is a palette PNG under 300 KB,
the most WhatsApp loads.

Regenerate it, with the same bytes each time (it writes `public/og.png` and `og-1200x630.png`):

```sh
node scripts/build-og-card.mjs
```

Upload `og-1200x630.png` where a card is set by hand: the GitHub organisation profile and
any directory listing. The site itself serves `public/og.png`.

This folder is outside `public/`, so the site build does not publish it.
Binary file added apps/site/assets/share/og-1200x630.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/site/assets/share/og-sky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions apps/site/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { createHash } from "node:crypto";
import { readFileSync } from "node:fs";
import { defineConfig } from "astro/config";
import sitemap from "@astrojs/sitemap";

// The first 12 hex digits of the share card's SHA-256, hashed once per build.
// Base.astro ends the card's URL in `?v=` plus this (context/share-card.md).
const ogCardHash = createHash("sha256")
.update(readFileSync(new URL("./public/og.png", import.meta.url)))
.digest("hex")
.slice(0, 12);

// Static output; the Worker in wrangler.jsonc serves `dist/` as assets only.
export default defineConfig({
site: "https://northguild.dev",
output: "static",
// @astrojs/sitemap leaves the 404 and 500 pages out of the sitemap itself.
integrations: [sitemap()],
vite: { define: { __OG_CARD_HASH__: JSON.stringify(ogCardHash) } },
});
Binary file modified apps/site/public/og.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/site/public/robots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Disallow: /gmt/api/

Sitemap: https://northguild.dev/sitemap-index.xml
Sitemap: https://northguild.dev/gmt/sitemap-index.xml
Sitemap: https://northguild.dev/worktree/sitemap-index.xml
2 changes: 2 additions & 0 deletions apps/site/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** The share card's hash, set by `vite.define` in astro.config.mjs. */
declare const __OG_CARD_HASH__: string;
7 changes: 5 additions & 2 deletions apps/site/src/layouts/Base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ const {
noindex = false,
} = Astro.props;

// Social cards need absolute URLs.
// Social cards need absolute URLs. The image URL carries the card's hash
// (astro.config.mjs), so a new card gets a new address and platforms that
// cache by URL (Facebook, LinkedIn) fetch it again.
const pageUrl = new URL(Astro.url.pathname, Astro.site);
const ogImage = new URL("/og.png", Astro.site);
const ogImage = new URL(`/og.png?v=${__OG_CARD_HASH__}`, Astro.site);
const ogAlt =
"NorthGuild: open-source tools for developers, under the northern lights.";
---
Expand All @@ -53,6 +55,7 @@ const ogAlt =
}
<meta property="og:type" content="website" />
<meta property="og:site_name" content="NorthGuild" />
<meta property="og:locale" content="en_US" />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:url" content={pageUrl} />
Expand Down
41 changes: 41 additions & 0 deletions context/share-card.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Share card

The picture that link-preview apps show for `northguild.dev/` and its 404 page:
`apps/site/public/og.png`, 1200 x 630, served from `/og.png`.

## What it is

Aurora sky, with a dark glass panel in the middle. On the panel the shield sits above the
"NorthGuild" wordmark (Michroma) and the line "Open-source tools for developers.".

- **Square-safe.** Some apps cut a 630-pixel square from the middle of the card
(x 285 to 915). The column and the panel sit inside it with a margin, so nothing is cut.
The aurora outside the square is decoration only.
- **Under 300 KB.** WhatsApp loads no preview image over 300 KB. The card is a palette PNG
(about 145 KB).
- **Text contrast** is at least 4.5:1; the script fails below that.

## Regenerate

```sh
eval "$(fnm env)" && fnm use && node scripts/build-og-card.mjs
```

Run it by hand, never in the build. It is deterministic: the same bytes every run. It writes
`apps/site/public/og.png` and the same bytes to `apps/site/assets/share/og-1200x630.png`
(the copy to upload by hand; see the README there).

Its sources: `apps/site/assets/share/og-sky.png` (the previous card, whose aurora is the
sky; keep it, because `og.png` is overwritten), the shield paths of
`NorthGuildMark.astro`, `scripts/fonts/Michroma-Regular.ttf` (SIL OFL text beside it) and
the `@northguild/theme` colours as RGB values. `sharp` and `canvaskit-wasm` are root dev
dependencies.

## The `?v=` rule

`Base.astro` ends `og:image` and `twitter:image` in `?v=` plus the first 12 hex digits of the
SHA-256 of `public/og.png`. `astro.config.mjs` hashes the file once per build and hands the
value to `Base.astro` as `__OG_CARD_HASH__`. Platforms such as Facebook and LinkedIn cache
a card by URL, so a new card needs a new URL. Change the card, rebuild, and the address
changes by itself; never edit the hash by hand. After a deploy, ask each platform's debugger
to scrape the page again.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
"devDependencies": {
"@changesets/cli": "^3.0.2",
"@northguild/gmt-oxlint": "^1.2.1",
"canvaskit-wasm": "0.42.0",
"geotiff": "3.0.5",
"jpeg-js": "^0.4.4",
"oxfmt": "^0.63.0",
"oxlint": "^1.78.0"
"oxlint": "^1.78.0",
"sharp": "0.35.5"
},
"engines": {
"node": ">=24"
Expand Down
19 changes: 18 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading