Skip to content

Commit

Permalink
goodbye edge runtime (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchg authored Nov 27, 2024
1 parent 9fae447 commit 44039ad
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 69 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ dist
.pnpm-debug.log
TODO
.env*.local
fonts/*
!fonts/init.mjs
38 changes: 6 additions & 32 deletions app/(post)/og/[id]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,22 @@ export async function generateStaticParams() {
}

// fonts
const fontsDir = join(process.cwd(), "fonts");

const inter300 = readFileSync(
join(
process.cwd(),
"node_modules",
"@fontsource",
"inter",
"files",
"inter-latin-300-normal.woff"
)
join(fontsDir, "inter-latin-300-normal.woff")
);

const inter500 = readFileSync(
join(
process.cwd(),
"node_modules",
"@fontsource",
"inter",
"files",
"inter-latin-500-normal.woff"
)
join(fontsDir, "inter-latin-500-normal.woff")
);

const inter600 = readFileSync(
join(
process.cwd(),
"node_modules",
"@fontsource",
"inter",
"files",
"inter-latin-600-normal.woff"
)
join(fontsDir, "inter-latin-600-normal.woff")
);

const robotoMono400 = readFileSync(
join(
process.cwd(),
"node_modules",
"@fontsource",
"roboto-mono",
"files",
"roboto-mono-latin-400-normal.woff"
)
join(fontsDir, "roboto-mono-latin-400-normal.woff")
);

export async function GET(_req: Request, props) {
Expand Down
19 changes: 7 additions & 12 deletions app/about/opengraph-image/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,18 @@ const rauchgPhoto = toArrayBuffer(
);

// Fonts
const fontsDir = join(process.cwd(), "fonts");

const inter300 = readFileSync(
join(
process.cwd(),
"node_modules/@fontsource/inter/files/inter-latin-300-normal.woff"
)
join(fontsDir, "inter-latin-300-normal.woff")
);

const inter500 = readFileSync(
join(
process.cwd(),
"node_modules/@fontsource/inter/files/inter-latin-500-normal.woff"
)
join(fontsDir, "inter-latin-500-normal.woff")
);

const robotoMono400 = readFileSync(
join(
process.cwd(),
"node_modules/@fontsource/roboto-mono/files/roboto-mono-latin-400-normal.woff"
)
join(fontsDir, "roboto-mono-latin-400-normal.woff")
);

export async function GET() {
Expand Down
10 changes: 10 additions & 0 deletions app/about/page.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import Image from "next/image";

export const metadata = {
title: 'Guillermo Rauch',
description: 'An overview of my career and technical contributions',
openGraph: {
title: 'Vercel',
description: 'An overview of my career and technical contributions',
images: [{ url: '/about/opengraph-image' }]
}
}

# About

<a href="https://twitter.com/rauchg" target="_blank">
Expand Down
29 changes: 5 additions & 24 deletions app/opengraph-image/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,18 @@ import { getPosts } from "@/app/get-posts";
import { readFileSync } from "fs";
import { join } from "path";

const fontsDir = join(process.cwd(), "fonts");

const inter300 = readFileSync(
join(
process.cwd(),
"node_modules",
"@fontsource",
"inter",
"files",
"inter-latin-300-normal.woff"
)
join(fontsDir, "inter-latin-300-normal.woff")
);

const inter600 = readFileSync(
join(
process.cwd(),
"node_modules",
"@fontsource",
"inter",
"files",
"inter-latin-600-normal.woff"
)
join(fontsDir, "inter-latin-600-normal.woff")
);

const robotoMono400 = readFileSync(
join(
process.cwd(),
"node_modules",
"@fontsource",
"roboto-mono",
"files",
"roboto-mono-latin-400-normal.woff"
)
join(fontsDir, "roboto-mono-latin-400-normal.woff")
);

export async function GET() {
Expand Down
35 changes: 35 additions & 0 deletions fonts/init.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// this script is run by the npm postinstall hook to copy the font
// files from the node_modules directory to the public directory

import fs from "fs";
import path from "path";

// Define the source paths
const fontPaths = [
"node_modules/@fontsource/inter/files/inter-latin-300-normal.woff",
"node_modules/@fontsource/inter/files/inter-latin-500-normal.woff",
"node_modules/@fontsource/inter/files/inter-latin-600-normal.woff",
"node_modules/@fontsource/roboto-mono/files/roboto-mono-latin-400-normal.woff",
];

// Ensure the destination directory exists
const ensureDirectoryExistence = filePath => {
const dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
return true;
}
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname, { recursive: true });
};

// Copy each font file
fontPaths.forEach(src => {
const fileName = path.basename(src);
const dest = path.join("fonts", fileName);
ensureDirectoryExistence(dest);
const exists = fs.existsSync(dest);
if (!exists) {
fs.copyFileSync(src, dest);
console.log(`Copied ${src} to ${dest}`);
}
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"scripts": {
"dev": "next dev --turbopack -H 0.0.0.0",
"build": "next build",
"start": "next start"
"start": "next start",
"postinstall": "node ./fonts/init.mjs"
},
"prettier": {
"arrowParens": "avoid"
Expand Down

0 comments on commit 44039ad

Please sign in to comment.