memorium/routes/articles/[name].tsx

67 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-08-01 21:35:21 +02:00
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";
2023-08-02 01:58:03 +02:00
import { HashTags } from "@components/HashTags.tsx";
import { isYoutubeLink } from "@lib/string.ts";
2023-08-06 17:47:26 +02:00
import { renderMarkdown } from "@lib/documents.ts";
2023-08-07 14:44:04 +02:00
import { RedirectSearchHandler } from "@islands/Search.tsx";
2023-08-01 21:35:21 +02:00
export const handler: Handlers<Article | null> = {
async GET(_, ctx) {
const article = await getArticle(ctx.params.name);
return ctx.render({ article, session: ctx.state.session });
2023-08-01 21:35:21 +02:00
},
};
export default function Greet(
props: PageProps<{ article: Article; session: Record<string, string> }>,
) {
const { article, session } = props.data;
2023-08-01 21:35:21 +02:00
const { author = "", date = "" } = article.meta;
2023-08-06 17:47:26 +02:00
const content = renderMarkdown(article.content);
2023-08-01 21:35:21 +02:00
return (
2023-08-06 18:06:09 +02:00
<MainLayout
url={props.url}
title={`Article > ${article.name}`}
context={article}
>
2023-08-07 14:44:04 +02:00
<RedirectSearchHandler />
<KMenu type="main" context={{ type: "article" }} />
2023-08-01 21:35:21 +02:00
<RecipeHero
data={article}
subline={[author, date.toString()]}
editLink={session
? `https://notes.max-richter.dev/Media/articles/${article.id}`
: ""}
2023-08-01 21:35:21 +02:00
backlink="/articles"
/>
2023-08-02 01:58:03 +02:00
{article.tags.length > 0 && (
<>
<br />
<HashTags tags={article.tags} />
</>
)}
2023-08-01 21:35:21 +02:00
<div class="px-8 text-white mt-10">
2023-08-02 01:58:03 +02:00
{isYoutubeLink(article.meta.link) && (
<YoutubePlayer link={article.meta.link} />
)}
2023-08-01 21:35:21 +02:00
<pre
class="whitespace-break-spaces markdown-body"
data-color-mode="dark"
data-dark-theme="dark"
2023-08-06 17:47:26 +02:00
dangerouslySetInnerHTML={{ __html: content || "" }}
2023-08-01 21:35:21 +02:00
>
2023-08-06 17:47:26 +02:00
{content||""}
2023-08-01 21:35:21 +02:00
</pre>
</div>
</MainLayout>
);
}