~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

docs-site: a link to the landing unfurls into the photograph and wordmark

Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:docs-site/og-image
docs-site/src/pages/index.astro+22−3
@@ -7,11 +7,19 @@
// (.claude/skills/landing).
import { Picture } from 'astro:assets'
import '../monolith.css'
import { FONTS, REPO, url } from '../../content.mjs'
import { BASE, FONTS, REPO, url } from '../../content.mjs'
import hero from '../assets/hero.jpg'
const title = 'Monolith: an atproto PDS in Rust'
const sentence = 'Monolith is an atproto PDS written in Rust.'
const description = sentence
const alt = 'A black monolith on a hilltop, backlit by a hazy glow'
// The card a link to the site unfurls into, drawn by pages/og.jpg.ts.
// Crawlers want absolute URLs, so both are made against the configured site.
const ogImage = new URL(`${BASE}/og.jpg`, Astro.site).href
const ogAlt = `${alt}, above the words MONOLITH, an atproto PDS`
const pageUrl = new URL(url(''), Astro.site).href
---
<!doctype html>
@@ -21,8 +29,19 @@ const description = sentence
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="color-scheme" content="dark" />
{FONTS.map((href) => <link rel="preload" href={href} as="font" type="font/woff2" crossorigin />)}
<title>Monolith: an atproto PDS in Rust</title>
<title>{title}</title>
<meta name="description" content={description} />
<link rel="canonical" href={pageUrl} />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="Monolith PDS" />
<meta property="og:url" content={pageUrl} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={ogImage} />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta property="og:image:alt" content={ogAlt} />
<meta name="twitter:card" content="summary_large_image" />
</head>
<body>
<header class="hero">
@@ -31,7 +50,7 @@ const description = sentence
formats={['avif', 'webp']}
widths={[960, 1600, 2400]}
sizes="100vw"
alt="A black monolith on a hilltop, backlit by a hazy glow"
alt={alt}
class="hero-image"
loading="eager"
fetchpriority="high"
docs-site/src/pages/og.jpg.tsnew+52−0
@@ -0,0 +1,52 @@
// The card a link to the site unfurls into (og:image, pages/index.astro):
// the landing's photograph at Open Graph's 1200 by 630, cropped about its
// centre, which keeps the monolith and its hilltop, with the wordmark on the
// ground below it as the landing sets it (`.logo` there). The letters are
// drawn as outlines from the site's own JetBrains Mono, so the card looks
// the same wherever it is built, with no font installed.
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import type { APIRoute } from 'astro'
import { create, type Font } from 'fontkitten'
import sharp from 'sharp'
const W = 1200
const H = 630
/** The wordmark's size, and its tagline's distance from the card's foot, in px. */
const SIZE = 26
const BOTTOM = 36
const INK = '#a8a8a2'
// From the site's root, which the build runs in: this module is bundled
// elsewhere before it runs, so its own location does not lead to the files.
const font = create(readFileSync(join(process.cwd(), 'public/fonts/jetbrains-mono-latin.woff2'))) as Font
const scale = SIZE / font.unitsPerEm
// Where the baseline sits in a line box of `line-height: 1`, as a browser sets it.
const baseline = (SIZE - (font.ascent - font.descent) * scale) / 2 + font.ascent * scale
/** `text` as SVG path data, centred across the card, its line box's top at `top`, `spacing` em between letters. */
function line(text: string, top: number, spacing = 0): string {
const glyphs = font.glyphsForString(text)
const gap = spacing * font.unitsPerEm
const width = (glyphs.reduce((w, g) => w + g.advanceWidth, 0) + gap * (glyphs.length - 1)) * scale
let x = (W - width) / 2
let d = ''
for (const g of glyphs) {
d += g.path.transform(scale, 0, 0, -scale, x, top + baseline).toSVG()
x += (g.advanceWidth + gap) * scale
}
return d
}
export const GET: APIRoute = async () => {
const tagTop = H - BOTTOM - SIZE
const nameTop = tagTop - 0.5 * SIZE - SIZE
const d = line('MONOLITH', nameTop, 0.5) + line('an atproto PDS', tagTop)
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}"><path fill="${INK}" d="${d}"/></svg>`
const jpeg = await sharp(join(process.cwd(), 'src/assets/hero.jpg'))
.resize(W, H, { fit: 'cover' })
.composite([{ input: Buffer.from(svg) }])
.jpeg({ quality: 82 })
.toBuffer()
return new Response(new Uint8Array(jpeg), { headers: { 'Content-Type': 'image/jpeg' } })
}
docs-site/package-lock.json+3−4
@@ -8,7 +8,9 @@
"dependencies": {
"@astrojs/markdown-remark": "7.3.5",
"@astrojs/starlight": "0.42.7",
"astro": "7.4.3"
"astro": "7.4.3",
"fontkitten": "1.0.3",
"sharp": "0.35.5"
}
},
"node_modules/@astrojs/compiler-binding": {
@@ -723,7 +725,6 @@
"resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz",
"integrity": "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==",
"license": "MIT",
"optional": true,
"engines": {
"node": ">=18"
}
@@ -5661,7 +5662,6 @@
"resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",
"integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",
"license": "ISC",
"optional": true,
"bin": {
"semver": "bin/semver.js"
},
@@ -5674,7 +5674,6 @@
"resolved": "https://registry.npmjs.org/sharp/-/sharp-0.35.5.tgz",
"integrity": "sha512-Ywn4OnzGukp7CDMrp08RQ50YKmuwG47brZgIVPTvBaaAfQlRlygrRqSrxdCiL9M+LlzLBiJ68IR1QqvzHyjC7g==",
"license": "Apache-2.0",
"optional": true,
"dependencies": {
"@img/colour": "^1.1.0",
"detect-libc": "^2.1.2",
docs-site/package.json+3−1
@@ -11,6 +11,8 @@
"dependencies": {
"@astrojs/markdown-remark": "7.3.5",
"@astrojs/starlight": "0.42.7",
"astro": "7.4.3"
"astro": "7.4.3",
"fontkitten": "1.0.3",
"sharp": "0.35.5"
}
}