## Summary A cleanup pass across the blog: route and feed bugs fixed, SEO basics added, smaller and lazier images, accessibility fixes, and a real README. No content or design changes beyond small fixes. ## Bug fixes - **Tag/category pages**: static params now use slugs, so pre-rendered pages match the links (before, `/tags/standard-model` was only rendered on demand and the pre-built pages said "Tag not found"). Unknown slugs now return a real 404, and there's a new not-found page. - **Recently updated**: sorts by last modification *before* taking the top 5, so older posts that were updated recently now show up. - **Atom feed**: `rel="self"` now points to `/feed.xml` (was `/feed`); `<updated>` uses the `updated` frontmatter field. - **No-JS flash**: the `no-js` → `js` class swap runs in an inline `<head>` script before first paint, not after hydration. - **Markdown links**: only internal paths go through `next/link`; `#anchors`, `mailto:` and links without an `href` no longer break. - **Invalid HTML**: images in a paragraph together with text (e.g. "**Screenshots:**" followed by images on the Projects page) produced `<p><figure>` and a hydration error. Those paragraphs are now split. - **Dates**: frontmatter dates are normalized to ISO, so `<time datetime>` values are valid. Formatting is pinned to Europe/Prague so a UTC build server can't shift a date by a day. ## SEO - `sitemap.xml` and `robots.txt` - Canonical URLs, Twitter cards and a feed link on every page, built by a shared `pageMetadata()` helper - Generated Open Graph images: a site card, and for each post its cover image or a branded title card (pre-rendered at build time) - `BlogPosting` JSON-LD on post pages ## Performance - Only the post cover and the latest-post image are preloaded (was: every image) - In-post image quality 100 → 90, plus responsive `sizes` - Screenshots downscaled to 1800px wide; `linkboard-old.png` converted to WebP (3.1 MB → 60 KB) - `CodeWrapper` is now a server component; only the copy button ships to the client - Mermaid CDN script pinned to `11.17.2` for reproducible builds ## Accessibility - Accessible names for icon-only links (share, social, mobile nav) and `aria-current` on active nav items - Copy button: uses React state instead of mutating `innerHTML`, handles clipboard errors, announces the result to screen readers, and is no longer inside an `aria-hidden` header - Code-block line numbers hidden from screen readers - Image captions: the Markdown `"title"` becomes the caption; captions that only repeat the alt text are hidden from screen readers ## Content & maintenance - **Frontmatter validation**: a missing or malformed field fails the build and names the file, instead of rendering a broken post - **`draft: true` support**: drafts only render in development - About/Projects/Setup pages share one `MarkdownPage` component; tag/category lists share `PostList` - Markdown rendering is cached, so metadata and page share one render - New README covering features, env vars, frontmatter schema, Markdown extensions and deployment - Removed unused ESLint setup and the unrelated `hast` package; `oxlint`, `oxfmt` and `puppeteer` moved to devDependencies (locked versions unchanged) - Typo fix in the Tessera cover alt text; removed unused `math`/`mermaid` flags from two posts ## Deployment notes - **`SITE_URL` is now required**: the build fails with a clear error if it's missing. - **Puppeteer is a devDependency now**: Nixpacks installs dev dependencies for the build by default, but check that Mermaid diagrams render on the first deploy (the Standard Model post has one). ## Testing - `tsc --noEmit` and `bun run lint` pass - `bun run build` passes; all 81 pages are generated statically - Smoke-tested `next start`: posts, tags, categories, feed, sitemap and OG images return 200; unknown tags and routes return 404 - No block elements nested inside `<p>` in any built page Reviewed-on: #1
194 lines
7.2 KiB
TypeScript
194 lines
7.2 KiB
TypeScript
import { AUTHOR, pageMetadata, SITE_NAME, SITE_URL } from '@/app/metadata'
|
|
import { ImageWrapper } from '@/components/content/ImageWrapper'
|
|
import { ShareLinks } from '@/components/post/ShareLinks'
|
|
import { TableOfContents } from '@/components/post/TableOfContents'
|
|
import { getAllPostSlugs, getNextAndPreviousPosts, getPostBySlug } from '@/lib/posts'
|
|
import { slugify } from '@/utils/slug'
|
|
import { dateTimeFormatter, shortDateFormatter } from '@/utils/time'
|
|
import { ArrowLeft, ArrowRight, Pencil, SendHorizonal } from 'lucide-react'
|
|
import type { Metadata } from 'next'
|
|
import Link from 'next/link'
|
|
|
|
export async function generateStaticParams() {
|
|
return getAllPostSlugs().map((slug) => ({ slug }))
|
|
}
|
|
|
|
export const dynamicParams = false
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: {
|
|
params: Promise<{ slug: string }>
|
|
}): Promise<Metadata> {
|
|
const { slug } = await params
|
|
const { meta } = await getPostBySlug(slug)
|
|
return pageMetadata({
|
|
title: meta.title,
|
|
description: meta.description,
|
|
path: `/posts/${slug}`,
|
|
image: `/posts/${slug}/opengraph-image`,
|
|
openGraph: {
|
|
type: 'article',
|
|
publishedTime: meta.date,
|
|
modifiedTime: meta.updated,
|
|
authors: [AUTHOR.url],
|
|
section: meta.category,
|
|
tags: meta.tags,
|
|
},
|
|
})
|
|
}
|
|
|
|
export default async function Post({ params }: { params: Promise<{ slug: string }> }) {
|
|
const { slug } = await params
|
|
const { meta, content, tableOfContents } = await getPostBySlug(slug)
|
|
const { next, previous } = getNextAndPreviousPosts(slug)
|
|
const url = `${SITE_URL}/posts/${slug}`
|
|
|
|
const jsonLd = {
|
|
'@context': 'https://schema.org',
|
|
'@type': 'BlogPosting',
|
|
headline: meta.title,
|
|
description: meta.description,
|
|
url,
|
|
mainEntityOfPage: url,
|
|
datePublished: meta.date,
|
|
dateModified: meta.updated ?? meta.date,
|
|
image: `${url}/opengraph-image`,
|
|
articleSection: meta.category,
|
|
keywords: meta.tags.join(', '),
|
|
author: { '@type': 'Person', name: AUTHOR.name, url: AUTHOR.url },
|
|
publisher: { '@type': 'Person', name: AUTHOR.name, url: AUTHOR.url },
|
|
isPartOf: { '@type': 'Blog', name: SITE_NAME, url: SITE_URL },
|
|
}
|
|
|
|
return (
|
|
<main className="flex w-full">
|
|
<script
|
|
type="application/ld+json"
|
|
// Escape "<" so post content can never close the script tag early
|
|
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd).replace(/</g, '\\u003c') }}
|
|
/>
|
|
<article className="max-w-3xl 2xl:max-w-4xl mx-auto px-4 py-8 mb-8 lg:py-16 min-w-0">
|
|
{meta.category && (
|
|
<Link
|
|
href={`/categories/${slugify(meta.category)}`}
|
|
className="text-accent hover:underline font-sm mb-2 inline-block"
|
|
>
|
|
{meta.category}
|
|
</Link>
|
|
)}
|
|
<h1 className="text-4xl font-bold mb-4">{meta.title}</h1>
|
|
<div className="flex justify-between md:justify-normal items-center gap-2 text-fg-dim mb-4 border-y border-border py-2 px-2 md:px-4 text-sm">
|
|
<div className="flex items-center gap-2">
|
|
<span className="hidden md:inline">Posted</span>
|
|
<span className="md:hidden">
|
|
<SendHorizonal className="w-3 h-3" />
|
|
</span>
|
|
<time
|
|
dateTime={meta.date}
|
|
title={dateTimeFormatter.format(new Date(meta.date))}
|
|
className="font-semibold"
|
|
>
|
|
{shortDateFormatter.format(new Date(meta.date))}
|
|
</time>
|
|
</div>
|
|
<span className="hidden md:inline">·</span>
|
|
{meta.updated && (
|
|
<>
|
|
<div className="flex items-center gap-2">
|
|
<span className="hidden md:inline">Updated</span>
|
|
<span className="md:hidden">
|
|
<Pencil className="w-3 h-3" />
|
|
</span>
|
|
<time
|
|
dateTime={meta.updated}
|
|
title={dateTimeFormatter.format(new Date(meta.updated))}
|
|
className="font-semibold"
|
|
>
|
|
{shortDateFormatter.format(new Date(meta.updated))}
|
|
</time>
|
|
</div>
|
|
<span className="hidden md:inline">·</span>
|
|
</>
|
|
)}
|
|
<span>{meta.readingTimeText}</span>
|
|
</div>
|
|
<p className="text-fg text-lg mb-4">{meta.description}</p>
|
|
{process.env.NODE_ENV === 'development' && (
|
|
<span className="text-fg-dim text-sm mb-4 block">
|
|
Description has {meta.description.length} characters, which is{' '}
|
|
{meta.description.length < 120
|
|
? 'too short'
|
|
: meta.description.length > 160
|
|
? 'too long'
|
|
: 'just right'}{' '}
|
|
for SEO.
|
|
</span>
|
|
)}
|
|
{meta.coverImage && (
|
|
<ImageWrapper src={meta.coverImage} alt={meta.coverImageAlt} priority />
|
|
)}
|
|
<div className="prose">{content}</div>
|
|
|
|
{meta.tags.length > 0 && (
|
|
<div className="mt-6 border-t border-border pt-4 flex gap-2 items-center flex-wrap">
|
|
<h2 className="text-lg font-bold">Tags</h2>
|
|
<div className="flex flex-wrap gap-1">
|
|
{meta.tags.map((tag) => (
|
|
<Link
|
|
key={tag}
|
|
href={`/tags/${slugify(tag)}`}
|
|
className="bg-accent/20 text-accent px-3 py-1 rounded-full text-xs hover:bg-accent/30 transition-colors"
|
|
>
|
|
{tag}
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<div className="mt-8 mx-auto flex">
|
|
<ShareLinks url={url} title={meta.title} description={meta.description} />
|
|
</div>
|
|
|
|
<div className="mt-12 grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4 border-t border-border pt-8">
|
|
{previous ? (
|
|
<Link
|
|
href={`/posts/${previous.slug}`}
|
|
className="group flex flex-col gap-1 rounded-lg p-4 transition-colors hover:bg-fg/10 active:bg-fg/15"
|
|
>
|
|
<span className="flex items-center gap-1 text-xs text-fg-dim uppercase tracking-wide">
|
|
<ArrowLeft className="w-3 h-3 shrink-0 transition-transform group-hover:-translate-x-1" />
|
|
Previous
|
|
</span>
|
|
<span className="text-accent font-medium group-hover:underline line-clamp-2">
|
|
{previous.title}
|
|
</span>
|
|
</Link>
|
|
) : (
|
|
<div className="hidden sm:block" />
|
|
)}
|
|
|
|
{next ? (
|
|
<Link
|
|
href={`/posts/${next.slug}`}
|
|
className="group flex flex-col gap-1 rounded-lg p-4 transition-colors hover:bg-fg/10 active:bg-fg/15 sm:text-right"
|
|
>
|
|
<span className="flex items-center gap-1 text-xs text-fg-dim uppercase tracking-wide sm:justify-end">
|
|
Next
|
|
<ArrowRight className="w-3 h-3 shrink-0 transition-transform group-hover:translate-x-1" />
|
|
</span>
|
|
<span className="text-accent font-medium group-hover:underline line-clamp-2">
|
|
{next.title}
|
|
</span>
|
|
</Link>
|
|
) : (
|
|
<div className="hidden sm:block" />
|
|
)}
|
|
</div>
|
|
</article>
|
|
|
|
<TableOfContents items={tableOfContents} />
|
|
</main>
|
|
)
|
|
}
|