mirror of
https://github.com/andwati/andwati.com.git
synced 2026-11-19 15:15:18 +00:00
Replace Astro/Strapi site with Next.js static export
- Fresh structure: Next.js App Router + Tailwind v4 at the repo root, exported as static files (output: export) and served by static-web-server - Remove the Strapi CMS, Astro app, Pagefind search, comments, old scripts, Lighthouse config and compose files; content in content/ is now plain markdown with YAML frontmatter - Pages: About, Writing, Reading (3D bookshelf) and Portfolio, styled after adammaj.com - SEO: metadata and canonicals, JSON-LD, generated OG images, sitemap, robots, RSS and JSON feeds, llms.txt - Umami via PUBLIC_UMAMI_SCRIPT_URL / PUBLIC_UMAMI_WEBSITE_ID (build args) - Dockerfile builds the export and serves it with sws.toml (security headers, clean URLs, .well-known, OG image content type, immutable asset caching) - Prettier and cspell for content with a husky/lint-staged pre-commit hook - Old redirect list dropped to start from a clean slate
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
type Book,
|
||||
coverExists,
|
||||
formatDate,
|
||||
getBooks,
|
||||
spineFor,
|
||||
} from "@/lib/content";
|
||||
|
||||
export type ShelfBook = {
|
||||
slug: string;
|
||||
href: string;
|
||||
title: string;
|
||||
coverImage?: string;
|
||||
spineColor: string;
|
||||
textColor: string;
|
||||
};
|
||||
|
||||
export function getShelf(): ShelfBook[] {
|
||||
return getBooks().map((b) => ({
|
||||
slug: b.slug,
|
||||
href: `/reading/${b.slug}`,
|
||||
title: b.data.title,
|
||||
coverImage: coverExists(b.data.coverImage) ? b.data.coverImage : undefined,
|
||||
...spineFor(b.data.title),
|
||||
}));
|
||||
}
|
||||
|
||||
export function readLine(b: Book) {
|
||||
return [
|
||||
b.dateFinished && `Read: ${formatDate(b.dateFinished)}`,
|
||||
b.rating && `Rating: ${b.rating}/5`,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" • ");
|
||||
}
|
||||
|
||||
export function byline(b: Book) {
|
||||
const parts = [
|
||||
b.authors?.length && `By: ${b.authors.join(", ")}`,
|
||||
b.dateFinished && `Read: ${formatDate(b.dateFinished)}`,
|
||||
b.rating && `Rating: ${b.rating}/5`,
|
||||
];
|
||||
return parts.filter(Boolean).join(" - ");
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import matter from "gray-matter";
|
||||
|
||||
const ROOT = path.join(process.cwd(), "content");
|
||||
|
||||
export type Entry<T> = { slug: string; data: T; content: string };
|
||||
|
||||
export type Writing = {
|
||||
title: string;
|
||||
description?: string;
|
||||
date: string;
|
||||
tags?: string[];
|
||||
};
|
||||
|
||||
export type Portfolio = {
|
||||
title: string;
|
||||
description?: string;
|
||||
role?: string;
|
||||
dateStart?: string;
|
||||
dateEnd?: string;
|
||||
outcome?: string;
|
||||
links?: { label: string; url: string }[];
|
||||
};
|
||||
|
||||
export type Book = {
|
||||
title: string;
|
||||
kind: "book" | "paper";
|
||||
authors?: string[];
|
||||
url?: string;
|
||||
coverImage?: string;
|
||||
rating?: number;
|
||||
status?: string;
|
||||
dateFinished?: string;
|
||||
tags?: string[];
|
||||
};
|
||||
|
||||
function readDir<T>(dir: string): Entry<T>[] {
|
||||
const full = path.join(ROOT, dir);
|
||||
if (!fs.existsSync(full)) return [];
|
||||
return fs
|
||||
.readdirSync(full)
|
||||
.filter((f) => f.endsWith(".md"))
|
||||
.map((f) => {
|
||||
const { data, content } = matter(
|
||||
fs.readFileSync(path.join(full, f), "utf8"),
|
||||
);
|
||||
return { slug: f.replace(/\.md$/, ""), data: data as T, content };
|
||||
});
|
||||
}
|
||||
|
||||
export function getWritings() {
|
||||
return readDir<Writing>("writing").sort((a, b) =>
|
||||
String(b.data.date).localeCompare(String(a.data.date)),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPortfolio() {
|
||||
return readDir<Portfolio>("portfolio").sort((a, b) =>
|
||||
String(b.data.dateStart ?? "").localeCompare(
|
||||
String(a.data.dateStart ?? ""),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getBooks() {
|
||||
return readDir<Book>("reading").sort(
|
||||
(a, b) =>
|
||||
(b.data.rating ?? 0) - (a.data.rating ?? 0) ||
|
||||
a.data.title.localeCompare(b.data.title),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAbout() {
|
||||
const { content } = matter(
|
||||
fs.readFileSync(path.join(ROOT, "about.md"), "utf8"),
|
||||
);
|
||||
return content;
|
||||
}
|
||||
|
||||
/** The part of a review shown on the index: everything before "## My Notes". */
|
||||
export function summarize(content: string) {
|
||||
return content.split(/^## My Notes/m)[0].trim();
|
||||
}
|
||||
|
||||
export function formatDate(date: string) {
|
||||
return new Date(`${date}T00:00:00Z`).toLocaleDateString("en-US", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
timeZone: "UTC",
|
||||
});
|
||||
}
|
||||
|
||||
const SPINES: [string, string][] = [
|
||||
["#7c3a2d", "#fbe9d0"],
|
||||
["#264653", "#e9f5f2"],
|
||||
["#2a4d3a", "#f1f7e8"],
|
||||
["#5b3a6b", "#f6ecfa"],
|
||||
["#c9a227", "#2b2110"],
|
||||
["#1d3557", "#f1faee"],
|
||||
["#8d5a3b", "#fff4e6"],
|
||||
["#3b3b3b", "#f0f0f0"],
|
||||
];
|
||||
|
||||
export function spineFor(title: string) {
|
||||
let h = 0;
|
||||
for (const c of title) h = (h * 31 + c.charCodeAt(0)) >>> 0;
|
||||
const [spineColor, textColor] = SPINES[h % SPINES.length];
|
||||
return { spineColor, textColor };
|
||||
}
|
||||
|
||||
export function coverExists(coverImage?: string) {
|
||||
return (
|
||||
!!coverImage &&
|
||||
fs.existsSync(path.join(process.cwd(), "public", coverImage))
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import rehypeRaw from "rehype-raw";
|
||||
import rehypeStringify from "rehype-stringify";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import remarkParse from "remark-parse";
|
||||
import remarkRehype from "remark-rehype";
|
||||
import { unified } from "unified";
|
||||
import { getWritings } from "@/lib/content";
|
||||
import { abs } from "@/lib/site";
|
||||
|
||||
const processor = unified()
|
||||
.use(remarkParse)
|
||||
.use(remarkGfm)
|
||||
.use(remarkRehype, { allowDangerousHtml: true })
|
||||
.use(rehypeRaw)
|
||||
.use(rehypeStringify);
|
||||
|
||||
/** Post bodies as HTML with root-relative links made absolute, for feed readers. */
|
||||
export async function getFeedItems() {
|
||||
return Promise.all(
|
||||
getWritings().map(async (p) => {
|
||||
const html = String(await processor.process(p.content)).replace(
|
||||
/(src|href)="\/(?!\/)/g,
|
||||
`$1="${abs("/")}`,
|
||||
);
|
||||
return {
|
||||
slug: p.slug,
|
||||
url: abs(`/writing/${p.slug}`),
|
||||
title: p.data.title,
|
||||
description: p.data.description ?? "",
|
||||
date: new Date(String(p.data.date)),
|
||||
tags: p.data.tags ?? [],
|
||||
html,
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export const xml = (s: string) =>
|
||||
s
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """);
|
||||
@@ -0,0 +1,56 @@
|
||||
import { ImageResponse } from "next/og";
|
||||
import { site } from "@/lib/site";
|
||||
|
||||
export const ogSize = { width: 1200, height: 630 };
|
||||
export const ogContentType = "image/png";
|
||||
|
||||
/** 1200x630 social card: title on white, name and domain along the bottom. */
|
||||
export function ogImage(title: string, kicker?: string) {
|
||||
return new ImageResponse(
|
||||
<div
|
||||
style={{
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "space-between",
|
||||
background: "#ffffff",
|
||||
color: "#1a202c",
|
||||
padding: "72px 80px",
|
||||
borderLeft: "16px solid #2b6cb0",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
fontSize: 30,
|
||||
color: "#718096",
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: 3,
|
||||
}}
|
||||
>
|
||||
{kicker ?? ""}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
fontSize: title.length > 60 ? 56 : 72,
|
||||
fontWeight: 700,
|
||||
lineHeight: 1.15,
|
||||
display: "flex",
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
fontSize: 30,
|
||||
}}
|
||||
>
|
||||
<span style={{ color: "#1a202c" }}>{site.name}</span>
|
||||
<span style={{ color: "#718096" }}>andwati.com</span>
|
||||
</div>
|
||||
</div>,
|
||||
ogSize,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
export const site = {
|
||||
name: "Ian Andwati",
|
||||
alias: "mockingspectre",
|
||||
title: "Ian Andwati (mockingspectre) | Software Engineer & CTF Player",
|
||||
tagline: "Thoughts and musings",
|
||||
description:
|
||||
"Software engineer and captain of the binarysith CTF team. Essays on low-level programming, distributed systems, compilers, database internals and security.",
|
||||
baseUrl: "https://andwati.com",
|
||||
locale: "en_US",
|
||||
twitter: "@andwati_",
|
||||
keywords: [
|
||||
"Ian Andwati",
|
||||
"mockingspectre",
|
||||
"binarysith",
|
||||
"software engineering",
|
||||
"cyber security",
|
||||
"CTF writeups",
|
||||
"binary exploitation",
|
||||
"reverse engineering",
|
||||
"low-level programming",
|
||||
"distributed systems",
|
||||
"compiler design",
|
||||
"database internals",
|
||||
],
|
||||
nav: [
|
||||
{ name: "Home", href: "/" },
|
||||
{ name: "Reading", href: "/reading" },
|
||||
{ name: "Writing", href: "/writing" },
|
||||
{ name: "Portfolio", href: "/portfolio" },
|
||||
],
|
||||
social: [
|
||||
{ name: "GitHub", href: "https://github.com/andwati" },
|
||||
{ name: "Twitter", href: "https://twitter.com/andwati_" },
|
||||
{ name: "YouTube", href: "https://www.youtube.com/@pwnforfunandprofit" },
|
||||
{ name: "Email", href: "mailto:[email protected]" },
|
||||
],
|
||||
sameAs: [
|
||||
"https://github.com/andwati",
|
||||
"https://twitter.com/andwati_",
|
||||
"https://www.youtube.com/@pwnforfunandprofit",
|
||||
"https://ctftime.org/team/379200",
|
||||
],
|
||||
};
|
||||
|
||||
export const abs = (path: string) => new URL(path, site.baseUrl).toString();
|
||||
Reference in New Issue
Block a user