the home site for me: also iteration 3 or 4 of my site

feat: add initial og image gen code

+3 -1
.gitignore
···
-
public
+
public
+
node_modules
+
.env
bun.lockb

This is a binary file and will not be displayed.

+14
package.json
···
+
{
+
"name": "zera",
+
"module": "index.ts",
+
"type": "module",
+
"devDependencies": {
+
"@types/bun": "latest"
+
},
+
"peerDependencies": {
+
"typescript": "^5.0.0"
+
},
+
"dependencies": {
+
"puppeteer": "^23.5.3"
+
}
+
}
+28
tools/genOG.ts
···
+
import puppeteer from "puppeteer";
+
+
const template = await Bun.file("tools/og.html").text();
+
+
const browser = await puppeteer.launch();
+
+
async function og(
+
postname: string,
+
outputPath: string,
+
width = 1200,
+
height = 630
+
) {
+
const page = await browser.newPage();
+
+
await page.setViewport({ width, height });
+
+
await page.setContent(template.toString().replace("{{postname}}", postname));
+
+
await page.screenshot({ path: outputPath });
+
}
+
+
try {
+
await og("an early tale of tomfoolery", "og.png");
+
} catch (e) {
+
console.error(e);
+
} finally {
+
await browser.close();
+
}
+70
tools/og.html
···
+
<!DOCTYPE html>
+
<html>
+
<head>
+
<style>
+
:root,
+
::backdrop {
+
color-scheme: dark;
+
--bg: #222529;
+
--bg-light: #464949;
+
--text: #d6d6d6;
+
--text-light: #c5c0b7;
+
--accent: #78b6ad;
+
--accent-light: #87c9e5;
+
--accent-text: var(--bg);
+
--border: #dbd5bc;
+
--link: #e2c8a2;
+
}
+
+
body {
+
font-weight: 600;
+
color: #d6d6d6;
+
background-color: #222529;
+
font-family: Consolas, Menlo, Monaco, "Andale Mono", "Ubuntu Mono",
+
monospace;
+
display: flex;
+
flex-direction: column;
+
text-align: center;
+
}
+
+
div {
+
margin: 0;
+
display: flex;
+
flex-direction: column;
+
align-items: center;
+
justify-content: center;
+
height: 90vh; /* 90% of viewport height */
+
width: 90vw; /* 90% of viewport width */
+
padding: 5vh 5vw; /* 5% border on all sides */
+
box-sizing: border-box;
+
align-self: center;
+
}
+
+
h1 {
+
font-size: calc(
+
2rem + 2vw
+
); /* Adjust font size based on viewport width */
+
margin: 0.5em 0;
+
line-height: 1.1;
+
}
+
+
h1::before {
+
color: var(--accent);
+
content: "# ";
+
}
+
+
p {
+
margin: 1rem 0;
+
font-size: calc(
+
1rem + 1vw
+
); /* Adjust font size based on viewport width */
+
}
+
</style>
+
</head>
+
<body>
+
<div>
+
<h1>{{postname}} lol eat food hapily</h1>
+
<p>By Kieran Klukas</p>
+
</div>
+
</body>
+
</html>
+27
tsconfig.json
···
+
{
+
"compilerOptions": {
+
// Enable latest features
+
"lib": ["ESNext", "DOM"],
+
"target": "ESNext",
+
"module": "ESNext",
+
"moduleDetection": "force",
+
"jsx": "react-jsx",
+
"allowJs": true,
+
+
// Bundler mode
+
"moduleResolution": "bundler",
+
"allowImportingTsExtensions": true,
+
"verbatimModuleSyntax": true,
+
"noEmit": true,
+
+
// Best practices
+
"strict": true,
+
"skipLibCheck": true,
+
"noFallthroughCasesInSwitch": true,
+
+
// Some stricter flags (disabled by default)
+
"noUnusedLocals": false,
+
"noUnusedParameters": false,
+
"noPropertyAccessFromIndexSignature": false
+
}
+
}