87 lines
2.7 KiB
TypeScript
87 lines
2.7 KiB
TypeScript
import { PageProps, RouteContext } from "$fresh/server.ts";
|
|
import { MainLayout } from "@components/layouts/main.tsx";
|
|
import { Movie } from "@lib/resource/movies.ts";
|
|
import { removeImage, renderMarkdown } from "@lib/documents.ts";
|
|
import { KMenu } from "@islands/KMenu.tsx";
|
|
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
|
import { Recommendations } from "@islands/Recommendations.tsx";
|
|
import PageHero from "@components/PageHero.tsx";
|
|
import { Star } from "@components/Stars.tsx";
|
|
import { MetaTags } from "@components/MetaTags.tsx";
|
|
import { parseRating } from "@lib/helpers.ts";
|
|
import { fetchResource } from "@lib/resources.ts";
|
|
|
|
export default async function Greet(
|
|
props: PageProps<{ movie: Movie; session: Record<string, string> }>,
|
|
ctx: RouteContext,
|
|
) {
|
|
const movie = await fetchResource(`movies/${ctx.params.name}.md`);
|
|
const session = ctx.state.session;
|
|
|
|
if (!movie) {
|
|
return ctx.renderNotFound();
|
|
}
|
|
|
|
const { author = "", date = "" } = movie.content;
|
|
|
|
const content = renderMarkdown(
|
|
removeImage(movie.content.reviewBody || "", movie.content.image),
|
|
);
|
|
|
|
return (
|
|
<MainLayout url={props.url} title={`Movie > ${movie.name}`} context={movie}>
|
|
<RedirectSearchHandler />
|
|
<KMenu type="main" context={movie} />
|
|
<MetaTags resource={movie} />
|
|
<PageHero
|
|
image={movie.content.image}
|
|
thumbnail={movie.content.thumbnail}
|
|
>
|
|
<PageHero.Header>
|
|
<PageHero.BackLink href="/movies" />
|
|
{session && (
|
|
<PageHero.EditLink
|
|
href={`https://notes.max-richter.dev/resources/movies/${movie.name}`}
|
|
/>
|
|
)}
|
|
</PageHero.Header>
|
|
<PageHero.Footer>
|
|
<PageHero.Title>{movie.name}</PageHero.Title>
|
|
<PageHero.Subline
|
|
entries={[
|
|
author && {
|
|
title: author?.name,
|
|
href: `/?q=${encodeURIComponent(author?.name)}`,
|
|
},
|
|
date.toString(),
|
|
]}
|
|
>
|
|
{movie.content.reviewRating && (
|
|
<Star
|
|
rating={parseRating(movie.content.reviewRating?.ratingValue)}
|
|
/>
|
|
)}
|
|
</PageHero.Subline>
|
|
</PageHero.Footer>
|
|
</PageHero>
|
|
{false && (
|
|
<Recommendations
|
|
id={movie.id}
|
|
type="movie"
|
|
/>
|
|
)}
|
|
<div class="px-8 text-white mt-10">
|
|
{movie?.content?.reviewBody?.length > 80
|
|
? <h2 class="text-4xl font-bold mb-4">Review</h2>
|
|
: <></>}
|
|
<pre
|
|
class="whitespace-break-spaces"
|
|
dangerouslySetInnerHTML={{ __html: content || "" }}
|
|
>
|
|
{content}
|
|
</pre>
|
|
</div>
|
|
</MainLayout>
|
|
);
|
|
}
|