Files
sweet/www/routes/_error.tsx
T
Christian Svensson 24c86ea20e fix: correct anchors by using heading text only (#3167)
Addresses the issue mentioned in
https://github.com/denoland/fresh/pull/3163#discussion_r2246708003.

The issue was that the `raw` markdown was being used for e.g. `## My
title`, thus the slug became `-my-title` instead of `my-title`. Slugs
were working correctly for `codespan` in headers, e.g. ``## `someCode`
``.

I decided to hard error if unexpected heading syntax is used over
sluggifying unexpected content (can become super weird otherwise, e.g.
`## <button ...>My heading</button>`). I can revert to fallbacking to
`raw` if preferred, but perhaps with at least trimming leading `-` just
in case.
2025-08-01 12:46:12 +02:00

47 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { HttpError, type PageProps } from "fresh";
import LemonDrop from "../islands/LemonDrop.tsx";
export function ServerCodePage(
props: { serverCode: number; codeDescription: string },
) {
return (
<>
<section>
<div class="w-full flex justify-center items-center flex-col bg-green-300 mt-0 pt-8 !mb-0 bg-gradient-to-br from-blue-100 via-green-200 to-yellow-100">
<LemonDrop />
</div>
<div class="text-center">
<h1 class="text-6xl md:text-9xl font-extrabold">
{props.serverCode}
</h1>
<p class="p-4 text-2xl md:text-3xl">
{props.codeDescription}
</p>
<p class="p-4">
<a href="/" class="hover:underline">Back to the Homepage</a>
</p>
</div>
</section>
</>
);
}
export default function ErrorPage(props: PageProps) {
const error = props.error;
if (error instanceof HttpError) {
if (error.status === 404) {
return ServerCodePage({
serverCode: 404,
codeDescription: "Couldn’t find what you’re looking for.",
});
}
}
return ServerCodePage({
serverCode: 500,
codeDescription: "Oops! Something went wrong.",
});
}