did a lot of syle work and started search and detail pages

This commit is contained in:
Chris Kruining 2025-05-19 17:00:18 +02:00
parent 7c5d2a25ff
commit 275fb87eeb
No known key found for this signature in database
GPG key ID: EB894A3560CCCAD2
23 changed files with 301155 additions and 243 deletions

View file

@ -0,0 +1,59 @@
import {
createAsync,
json,
Params,
query,
redirect,
RouteDefinition,
useParams,
} from "@solidjs/router";
import { Show } from "solid-js";
import { Details } from "~/components/details";
import { createSlug, Entry, getEntry } from "~/features/content";
const healUrl = async (slug: string, entry: Entry) => {
const actualSlug = createSlug(entry);
if (slug !== actualSlug) {
// Not entirely sure a permanent redirect is what we want in this case
throw redirect(`/details/${actualSlug}`, { status: 308 });
}
};
interface ItemParams extends Params {
slug: string;
}
export const route = {
async preload({ params }) {
const slug = params.slug;
if (!slug) {
return;
}
const entry = await getEntry(slug.slice(slug.lastIndexOf("-") + 1));
if (entry === undefined) {
return json(null, { status: 404 });
}
healUrl(slug, entry);
return entry;
},
} satisfies RouteDefinition;
export default function Item() {
const { slug } = useParams<ItemParams>();
const id = slug.slice(slug.lastIndexOf("-") + 1);
const entry = createAsync(() => getEntry(id));
return (
<>
<Show when={entry()} fallback="Some kind of pretty 404 page I guess">{
entry => <Details entry={entry()} />
}</Show>
</>
);
}