Skip to content
Open
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
11 changes: 4 additions & 7 deletions public/favicon.svg
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 public/og-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions scripts/og-template.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions scripts/render-og.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node
// Render the OG card SVG to a static PNG using sharp.
// Run via: node scripts/render-og.mjs
import { readFile, writeFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";
import sharp from "sharp";

const here = dirname(fileURLToPath(import.meta.url));
const svgPath = resolve(here, "og-template.svg");
const outPath = resolve(here, "..", "public", "og-image.png");

const svg = await readFile(svgPath);

const png = await sharp(svg, { density: 144 })
.resize(1200, 630, { fit: "cover" })
.png({ compressionLevel: 9, palette: false })
.toBuffer();

await writeFile(outPath, png);
console.log(`Wrote ${outPath} (${png.length} bytes)`);
32 changes: 13 additions & 19 deletions src/components/BaseHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
// Import the global.css file here so that it is included on
// all pages through the use of the <BaseHead /> component.
import "../styles/global.css";
import type { ImageMetadata } from "astro";
import FallbackImage from "../assets/blog-placeholder-1.jpg";
import { SITE_TITLE } from "../consts";

interface Props {
title: string;
description: string;
image?: ImageMetadata;
image?: string;
}

const canonicalURL = new URL(Astro.url.pathname, Astro.site);

const { title, description, image = FallbackImage } = Astro.props;
const { title, description, image = "/og-image.png" } = Astro.props;
const ogImageUrl = new URL(image, Astro.url).toString();
---

<!-- Global Metadata -->
Expand All @@ -29,21 +28,14 @@ const { title, description, image = FallbackImage } = Astro.props;
href={new URL("rss.xml", Astro.site)}
/>
<meta name="generator" content={Astro.generator} />
<meta name="theme-color" content="#f5f0e5" />

<!-- Font preloads -->
<!-- Fonts: IBM Plex Sans (body + display), IBM Plex Mono (UI/labels) -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="preload"
href="/fonts/atkinson-regular.woff"
as="font"
type="font/woff"
crossorigin
/>
<link
rel="preload"
href="/fonts/atkinson-bold.woff"
as="font"
type="font/woff"
crossorigin
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,300;0,400;0,500;0,600;1,400&family=IBM+Plex+Sans:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,300;1,400&display=swap"
/>

<!-- Canonical URL -->
Expand All @@ -59,11 +51,13 @@ const { title, description, image = FallbackImage } = Astro.props;
<meta property="og:url" content={Astro.url} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={new URL(image.src, Astro.url)} />
<meta property="og:image" content={ogImageUrl} />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />

<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content={Astro.url} />
<meta property="twitter:title" content={title} />
<meta property="twitter:description" content={description} />
<meta property="twitter:image" content={new URL(image.src, Astro.url)} />
<meta property="twitter:image" content={ogImageUrl} />
Loading