Skip to content
Closed
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
Binary file added src/assets/og/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 22 additions & 4 deletions src/pages/og/[...slog].png.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { getCollection } from "astro:content";
import { createElement } from "react";
import { ImageResponse } from "workers-og";

import backgroundImageUrl from "../../assets/og/background.png";
import SumUpBlackData from "../../assets/fonts/sumup-black-latin-s.ttf";
import SumUpNarrowMediumData from "../../assets/fonts/sumup-narrow-latin-s-medium.ttf";
import SumUpNarrowRegularData from "../../assets/fonts/sumup-narrow-latin-s-regular.ttf";

interface Props {
params: { slog?: string };
request: Request;
}

export const prerender = false;
Expand Down Expand Up @@ -110,8 +112,9 @@ async function resolvePageMetadata(path: string) {
return defaultMetadata;
}

export async function GET({ params }: Props) {
export async function GET({ params, request }: Props) {
const { title, description } = await resolvePageMetadata(params.slog ?? "");
const backgroundSrc = new URL(backgroundImageUrl.src, request.url).toString();

const sumUpBlack = toSupportedFontData(SumUpBlackData, "SumUp Black");
const sumUpNarrowMedium = toSupportedFontData(
Expand Down Expand Up @@ -140,13 +143,28 @@ export async function GET({ params }: Props) {
alignItems: "center",
justifyContent: "center",
fontFamily: narrowFontFamily,
overflow: "hidden",
},
},
createElement("img", {
src: backgroundSrc,
alt: "",
width: "1200",
height: "600",
style: {
position: "absolute",
inset: 0,
width: "100%",
height: "100%",
objectFit: "cover",
},
}),
createElement(
"div",
{
style: {
display: "flex",
position: "relative",
flexDirection: "column",
width: "100%",
height: "100%",
Expand All @@ -173,7 +191,7 @@ export async function GET({ params }: Props) {
fontSize: "42px",
color: "#f0eee7",
fontFamily: narrowFontFamily,
fontWeight: 500,
fontWeight: 550,
letterSpacing: "0.01em",
},
},
Expand Down Expand Up @@ -218,7 +236,7 @@ export async function GET({ params }: Props) {
display: "flex",
fontFamily: blackFontFamily,
fontSize: "72px",
fontWeight: 700,
fontWeight: 650,
lineHeight: 1,
color: "#f0eee7",
margin: 0,
Expand All @@ -240,7 +258,7 @@ export async function GET({ params }: Props) {
lineHeight: 1.25,
color: "#f0eee7",
fontFamily: narrowFontFamily,
fontWeight: 400,
fontWeight: 550,
maxWidth: "960px",
wordWrap: "break-word",
},
Expand Down