memorium/routes/articles/[name].tsx
2023-08-07 14:44:04 +02:00

63 lines
1.8 KiB
TypeScript

import { Handlers, PageProps } from "$fresh/server.ts";
import { MainLayout } from "@components/layouts/main.tsx";
import { Article, getArticle } from "@lib/resource/articles.ts";
import { RecipeHero } from "@components/RecipeHero.tsx";
import { KMenu } from "@islands/KMenu.tsx";
import { YoutubePlayer } from "@components/Youtube.tsx";
import { HashTags } from "@components/HashTags.tsx";
import { isYoutubeLink } from "@lib/string.ts";
import { renderMarkdown } from "@lib/documents.ts";
import { RedirectSearchHandler } from "@islands/Search.tsx";
export const handler: Handlers<Article | null> = {
async GET(_, ctx) {
const movie = await getArticle(ctx.params.name);
return ctx.render(movie);
},
};
export default function Greet(props: PageProps<Article>) {
const article = props.data;
const { author = "", date = "" } = article.meta;
const content = renderMarkdown(article.content);
return (
<MainLayout
url={props.url}
title={`Article > ${article.name}`}
context={article}
>
<RedirectSearchHandler />
<KMenu type="main" context={{ type: "article" }} />
<RecipeHero
data={article}
subline={[author, date.toString()]}
editLink={`https://notes.max-richter.dev/Media/articles/${article.id}`}
backlink="/articles"
/>
{article.tags.length > 0 && (
<>
<br />
<HashTags tags={article.tags} />
</>
)}
<div class="px-8 text-white mt-10">
{isYoutubeLink(article.meta.link) && (
<YoutubePlayer link={article.meta.link} />
)}
<pre
class="whitespace-break-spaces markdown-body"
data-color-mode="dark"
data-dark-theme="dark"
dangerouslySetInnerHTML={{ __html: content || "" }}
>
{content||""}
</pre>
</div>
</MainLayout>
);
}