Skip to content

📧✨ Beautiful email. For everyone.

feat: add social preview card to marketing site (#4)

Paul Koeckd3972926934c
diff --git a/apps/marketing/astro.config.mjs b/apps/marketing/astro.config.mjs
index 9d13730..54c3be9 100644
--- a/apps/marketing/astro.config.mjs
+++ b/apps/marketing/astro.config.mjs
@@ -22,6 +22,7 @@ const workerRoutes = {
}
export default defineConfig({
+ site: 'https://inlark.com',
integrations: [react()],
vite: {
plugins: [tailwindcss(), workerRoutes],
diff --git a/apps/marketing/package.json b/apps/marketing/package.json
index 876921e..ef3f42b 100644
--- a/apps/marketing/package.json
+++ b/apps/marketing/package.json
@@ -10,6 +10,7 @@
"preview": "astro preview",
"preview:workers": "astro build && wrangler dev",
"deploy": "astro build && wrangler deploy",
+ "social-card": "astro build && node scripts/social-card.mjs",
"typecheck": "astro check"
},
"dependencies": {
diff --git a/apps/marketing/public/social-card.png b/apps/marketing/public/social-card.png
new file mode 100644
index 0000000..296f5e7
Binary files /dev/null and b/apps/marketing/public/social-card.png differ
diff --git a/apps/marketing/scripts/social-card.mjs b/apps/marketing/scripts/social-card.mjs
new file mode 100644
index 0000000..163faa7
--- /dev/null
+++ b/apps/marketing/scripts/social-card.mjs
@@ -0,0 +1,50 @@
+// Renders src/pages/social-card.astro to public/social-card.png with a headless Chromium.
+// Run after `astro build`; set CHROMIUM when the browser isn't on the PATH as `chromium`.
+import { execFile } from 'node:child_process'
+import { mkdtempSync, readFileSync, rmSync } from 'node:fs'
+import { createServer } from 'node:http'
+import { tmpdir } from 'node:os'
+import { extname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+import { promisify } from 'node:util'
+
+const root = fileURLToPath(new URL('..', import.meta.url))
+const types = {
+ '.html': 'text/html',
+ '.css': 'text/css',
+ '.js': 'text/javascript',
+ '.svg': 'image/svg+xml',
+ '.woff2': 'font/woff2',
+}
+
+// Serves the build output, which uses root-relative asset paths.
+const server = createServer((req, res) => {
+ const path = decodeURIComponent(new URL(req.url, 'http://localhost').pathname)
+ const file = join(root, 'dist', extname(path) ? path : join(path, 'index.html'))
+ try {
+ const body = readFileSync(file)
+ res.writeHead(200, { 'Content-Type': types[extname(file)] ?? 'application/octet-stream' })
+ res.end(body)
+ } catch {
+ res.writeHead(404).end()
+ }
+})
+await new Promise((resolve) => server.listen(0, 'localhost', resolve))
+const profile = mkdtempSync(join(tmpdir(), 'inlark-card-'))
+
+try {
+ await promisify(execFile)(process.env.CHROMIUM ?? 'chromium', [
+ '--headless',
+ '--user-data-dir=' + profile,
+ '--hide-scrollbars',
+ '--force-device-scale-factor=1',
+ '--force-prefers-color-scheme=dark',
+ '--window-size=1200,630',
+ '--virtual-time-budget=4000',
+ '--screenshot=' + join(root, 'public/social-card.png'),
+ `http://localhost:${server.address().port}/social-card/`,
+ ])
+} finally {
+ server.close()
+ rmSync(profile, { recursive: true, force: true })
+}
diff --git a/apps/marketing/src/layouts/Layout.astro b/apps/marketing/src/layouts/Layout.astro
index 9a8ce44..3189191 100644
--- a/apps/marketing/src/layouts/Layout.astro
+++ b/apps/marketing/src/layouts/Layout.astro
@@ -12,6 +12,9 @@ interface Props {
}
const { title, description } = Astro.props
+// Link previews need absolute URLs.
+const card = new URL('/social-card.png', Astro.site)
+const url = new URL(Astro.url.pathname, Astro.site)
---
<!doctype html>
@@ -29,6 +32,17 @@ const { title, description } = Astro.props
<meta property="og:type" content="website" />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
+ <meta property="og:url" content={url} />
+ <meta property="og:site_name" content="Inlark" />
+ <meta property="og:image" content={card} />
+ <meta property="og:image:type" content="image/png" />
+ <meta property="og:image:width" content="1200" />
+ <meta property="og:image:height" content="630" />
+ <meta
+ property="og:image:alt"
+ content="Inlark: beautiful email, for everyone. The unified inbox rising over a dawn horizon."
+ />
+ <meta name="twitter:card" content="summary_large_image" />
<slot name="head" />
</head>
<body class="grain bg-night font-sans text-ink antialiased">
diff --git a/apps/marketing/src/pages/social-card.astro b/apps/marketing/src/pages/social-card.astro
new file mode 100644
index 0000000..596302c
--- /dev/null
+++ b/apps/marketing/src/pages/social-card.astro
@@ -0,0 +1,170 @@
+---
+/* The source of public/social-card.png, the preview image link unfurls show. It is a page so the
+ card uses the site's own fonts, mark, and inbox. After changing it, run `pnpm social-card`. */
+import '@fontsource-variable/newsreader/opsz.css'
+import '@fontsource-variable/newsreader/opsz-italic.css'
+import '@fontsource-variable/hanken-grotesk'
+import '@fontsource-variable/inter'
+import '../styles/global.css'
+import { Mark } from '../components/Mark'
+import { Wordmark } from '@inlark/ui/components/wordmark'
+import InboxWindow from '../components/InboxWindow.astro'
+
+// A fixed seed keeps the sky identical between renders.
+let seed = 7
+const random = () => (seed = (seed * 16807) % 2147483647) / 2147483647
+const stars = Array.from({ length: 70 }, () => ({
+ x: random() * 100,
+ y: Math.pow(random(), 1.3) * 62,
+ size: random() < 0.14 ? 2 : 1,
+ opacity: 0.1 + random() * 0.45,
+}))
+---
+
+<!doctype html>
+<html lang="en" style="color-scheme: dark">
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="robots" content="noindex" />
+ <title>Inlark social card</title>
+ </head>
+ <body>
+ <div class="card">
+ {stars.map((s) => (
+ <span
+ class="star"
+ style={`left:${s.x}%;top:${s.y}%;width:${s.size}px;height:${s.size}px;opacity:${s.opacity.toFixed(2)}`}
+ />
+ ))}
+
+ <div class="brand">
+ <Mark size={34} />
+ <Wordmark height={25} decorative />
+ </div>
+ <h1 class="display">
+ <em class="dawn-text pr-[0.06em]">Beautiful</em> email.
+ <br />
+ For everyone.
+ </h1>
+
+ <div class="sun"></div>
+ <div class="horizon"></div>
+ <div class="window @container">
+ <InboxWindow theme="dark" />
+ </div>
+ </div>
+ </body>
+</html>
+
+<style>
+ body {
+ margin: 0;
+ background: #09090a;
+ }
+
+ .card {
+ position: relative;
+ isolation: isolate;
+ width: 1200px;
+ height: 630px;
+ overflow: hidden;
+ background: #09090a;
+ color: var(--color-ink);
+ font-family: var(--font-sans);
+ text-align: center;
+ }
+
+ .star {
+ position: absolute;
+ z-index: -1;
+ border-radius: 50%;
+ background: #fff;
+ }
+
+ .brand {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 9px;
+ padding-top: 50px;
+ }
+
+ h1 {
+ margin-top: 26px;
+ font-size: 80px;
+ line-height: 1;
+ }
+
+ .sun {
+ position: absolute;
+ left: 50%;
+ top: -60px;
+ z-index: -1;
+ width: 1500px;
+ aspect-ratio: 16 / 9;
+ background: radial-gradient(
+ 50% 50% at 50% 50%,
+ rgb(242 184 139 / 0.46) 0%,
+ rgb(224 158 190 / 0.28) 24%,
+ rgb(140 128 240 / 0.13) 46%,
+ transparent 70%
+ );
+ filter: blur(24px);
+ transform: translateX(-50%);
+ }
+
+ .horizon {
+ --r: 1200px;
+ position: absolute;
+ left: 50%;
+ top: 372px;
+ z-index: -1;
+ width: calc(var(--r) * 2);
+ height: calc(var(--r) * 2);
+ margin-left: calc(var(--r) * -1);
+ border-radius: 50%;
+ background: #09090a;
+ box-shadow:
+ 0 -1px 0 rgb(255 220 196 / 0.55),
+ 0 -2px 12px rgb(242 184 139 / 0.35),
+ 0 -40px 120px -20px rgb(200 150 220 / 0.3),
+ inset 0 40px 80px -40px rgb(255 232 214 / 0.08);
+ }
+
+ /* The window rises out of the bottom edge, as it does in the hero. */
+ .window {
+ position: absolute;
+ left: 50%;
+ top: 318px;
+ width: 1000px;
+ height: 600px;
+ margin-left: -500px;
+ border-radius: 16px;
+ text-align: left;
+ padding: 1px;
+ background: linear-gradient(
+ 180deg,
+ rgb(255 255 255 / 0.2),
+ rgb(255 255 255 / 0.06) 22%,
+ rgb(255 255 255 / 0.03)
+ );
+ box-shadow:
+ 0 0 0 1px rgb(0 0 0 / 0.55),
+ 0 50px 140px -30px rgb(0 0 0 / 0.95),
+ 0 -30px 140px -60px rgb(242 184 139 / 0.45);
+ }
+ .window::before {
+ content: '';
+ position: absolute;
+ inset: 0 12% auto;
+ height: 1px;
+ z-index: 3;
+ background: linear-gradient(90deg, transparent, rgb(255 226 206 / 0.7), transparent);
+ }
+ .window :global(.app),
+ .window :global(.app-shell) {
+ height: 100%;
+ border-radius: 15px;
+ overflow: hidden;
+ }
+</style>