Share cards
What a link to a SpaceBot page looks like when it is pasted into Discord, X, Slack or a message.
How it works
src/lib/seo/social.tsholds one table. Each public route maps to a card (a 1200×630 image) and to the title and description in the preview.socialFor(pathname)finds the match.- The root layout (
src/routes/+layout.svelte) rendersSocialMeta.sveltefor every page, so the page getsog:*andtwitter:*tags with a large image, the right URL and image alt text. - The cards are PNG files in
static/og/, drawn ahead of time bybun scripts/generate-og-cards.tsfrom the template insrc/lib/seo/og-svg.ts(an SVG turned into a PNG by resvg). They are not drawn on request: Cloudflare Workers will not compile the WebAssembly that does it at runtime, so a live generator fell back to an SVG in production, which Discord and X will not show. Run the script after changing a card, the template or the mark, and commit the PNGs. A test checks that every card has a 1200×630 file. /api/og?page=<card>is the old address. It redirects to the card's PNG (an unknown name gets the home card) so links that already point at it keep working.- Pages built from data write their own tags with
SocialMetaand are markedown: truein the table, so the layout skips them and the page never has two sets: a listed server (/servers/<id>, uses the server's icon), a developer document (/docs/dev/<slug>) and a member profile (/profile/...). - Any path not in the table gets the home card, not a bare logo. Each card has the astronaut mark
(
src/lib/assets/spacebot-mark.png), the words on the left, and on the right a drawing of what is on the page: an uptime graph for the status page, a leaderboard, a code window, and so on.
Adding a page
- Add a card to
OG_CARDSif the page deserves its own (keep the description under 90 characters; a test checks it fits the image). Draw what is on the page inVISUALSinog-svg.ts(the types fail the build until every card has a drawing), then runbun scripts/generate-og-cards.tsand commit the PNG. - Add a route to
ROUTESwith the title and description for the preview. - Add the path to the sitemap if the page is public (
src/lib/server/sitemap.ts). A test checks that every sitemap page has its own card.
Caveats
- Discord, X and others cache a card for a long time. After changing a card, a link already shared keeps the old picture until their cache expires. Their debuggers can force a refresh.
- The drawings are illustrations, not data: the status card's uptime graph is made up, and no card says anything is currently up or down.
- The script needs the network: it fetches the Inter fonts (regular, medium, semibold, bold) from Google Fonts each time it runs.