memorium/routes/movies/[name].tsx

64 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-07-30 21:43:09 +02:00
import { Handlers, PageProps } from "$fresh/server.ts";
import { MainLayout } from "@components/layouts/main.tsx";
2023-08-01 17:50:00 +02:00
import { getMovie, Movie } from "@lib/resource/movies.ts";
2023-07-30 23:55:51 +02:00
import { RecipeHero } from "@components/RecipeHero.tsx";
2023-08-02 01:58:03 +02:00
import { HashTags } from "@components/HashTags.tsx";
2023-08-06 17:47:26 +02:00
import { renderMarkdown } from "@lib/documents.ts";
2023-08-07 14:44:04 +02:00
import { KMenu } from "@islands/KMenu.tsx";
import { RedirectSearchHandler } from "@islands/Search.tsx";
2023-07-30 21:43:09 +02:00
2023-07-30 23:55:51 +02:00
export const handler: Handlers<Movie | null> = {
2023-07-30 21:43:09 +02:00
async GET(_, ctx) {
2023-07-30 23:55:51 +02:00
const movie = await getMovie(ctx.params.name);
return ctx.render({ movie, session: ctx.state.session });
2023-07-30 21:43:09 +02:00
},
};
export default function Greet(
props: PageProps<{ movie: Movie; session: Record<string, string> }>,
) {
const { movie, session } = props.data;
2023-07-30 21:43:09 +02:00
2023-07-31 17:21:17 +02:00
const { author = "", date = "" } = movie.meta;
2023-08-06 17:47:26 +02:00
const content = renderMarkdown(movie.description || "");
2023-07-30 21:43:09 +02:00
return (
2023-08-06 18:06:09 +02:00
<MainLayout url={props.url} title={`Movie > ${movie.name}`} context={movie}>
2023-08-07 14:44:04 +02:00
<RedirectSearchHandler />
<KMenu type="main" context={movie} />
2023-07-31 17:21:17 +02:00
<RecipeHero
data={movie}
2023-08-12 18:32:56 +02:00
subline={[
author && {
title: author,
2023-08-12 21:34:00 +02:00
href: `/?q=${encodeURIComponent(author)}`,
2023-08-12 18:32:56 +02:00
},
date.toString(),
]}
editLink={session
? `https://notes.max-richter.dev/Media/movies/${movie.id}`
: ""}
2023-07-31 17:21:17 +02:00
backlink="/movies"
/>
2023-08-02 01:58:03 +02:00
{movie.tags.length > 0 && (
<>
<br />
<HashTags tags={movie.tags} />
</>
)}
2023-07-30 21:43:09 +02:00
<div class="px-8 text-white mt-10">
2023-08-04 13:48:12 +02:00
{movie?.description?.length > 80
? <h2 class="text-4xl font-bold mb-4">Review</h2>
: <></>}
2023-07-30 21:43:09 +02:00
<pre
class="whitespace-break-spaces"
2023-08-06 17:47:26 +02:00
dangerouslySetInnerHTML={{ __html: content || "" }}
2023-07-30 21:43:09 +02:00
>
2023-08-06 17:47:26 +02:00
{content}
2023-07-30 21:43:09 +02:00
</pre>
</div>
</MainLayout>
);
}