feat: initial refactor to use marka as backend

This commit is contained in:
Max Richter
2025-10-28 20:15:23 +01:00
parent 0beb3b1071
commit f680b5f832
39 changed files with 245 additions and 1012 deletions

View File

@@ -1,6 +1,6 @@
import { Handlers, PageProps } from "$fresh/server.ts";
import { MainLayout } from "@components/layouts/main.tsx";
import { Article, getArticle } from "@lib/resource/articles.ts";
import { Article } from "@lib/resource/articles.ts";
import { KMenu } from "@islands/KMenu.tsx";
import { YoutubePlayer } from "@components/Youtube.tsx";
import { HashTags } from "@components/HashTags.tsx";
@@ -10,10 +10,11 @@ import { RedirectSearchHandler } from "@islands/Search.tsx";
import PageHero from "@components/PageHero.tsx";
import { Star } from "@components/Stars.tsx";
import { MetaTags } from "@components/MetaTags.tsx";
import { fetchResource } from "@lib/resources.ts";
export const handler: Handlers<{ article: Article; session: unknown }> = {
async GET(_, ctx) {
const article = await getArticle(ctx.params.name);
const article = await fetchResource(`articles/${ctx.params.name}.md`);
if (!article) {
return ctx.renderNotFound();
}
@@ -26,34 +27,39 @@ export default function Greet(
) {
const { article, session } = props.data;
const { author = "", date = "" } = article.meta;
const { author = "", date = "", articleBody = "" } = article?.content || {};
const content = renderMarkdown(
removeImage(article.content, article.meta.image),
removeImage(articleBody, article.content.image),
);
console.log({ article });
return (
<MainLayout
url={props.url}
title={`Article > ${article.name}`}
title={`Article > ${article.content.headline}`}
context={article}
>
<RedirectSearchHandler />
<KMenu type="main" context={{ type: "article" }} />
<MetaTags resource={article} />
<PageHero image={article.meta.image} thumbnail={article.meta.thumbnail}>
<PageHero
image={article.content.image}
thumbnail={article.content.thumbnail}
>
<PageHero.Header>
<PageHero.BackLink href="/articles" />
{session && (
<PageHero.EditLink
href={`https://notes.max-richter.dev/Media/articles/${article.id}`}
href={`https://notes.max-richter.dev/resources/articles/${article.name}`}
/>
)}
</PageHero.Header>
<PageHero.Footer>
<PageHero.Title link={article.meta.link}>
{article.name}
<PageHero.Title link={article.content.url}>
{article.content.headline}
</PageHero.Title>
<PageHero.Subline
entries={[
@@ -64,20 +70,20 @@ export default function Greet(
date.toString(),
]}
>
{article.meta.rating && <Star rating={article.meta.rating} />}
{article.content.rating && <Star rating={article.content.rating} />}
</PageHero.Subline>
</PageHero.Footer>
</PageHero>
{article.tags.length > 0 && (
{article.content?.tags?.length > 0 && (
<>
<br />
<HashTags tags={article.tags} />
<HashTags tags={article.content.tags} />
</>
)}
<div class="px-8 text-white mt-10">
{isYoutubeLink(article.meta.link) && (
<YoutubePlayer link={article.meta.link} />
{isYoutubeLink(article.content.url) && (
<YoutubePlayer link={article.content.url} />
)}
<pre
class="whitespace-break-spaces markdown-body"
@@ -85,7 +91,7 @@ export default function Greet(
data-dark-theme="dark"
dangerouslySetInnerHTML={{ __html: content || "" }}
>
{content||""}
{content || ""}
</pre>
</div>
</MainLayout>

View File

@@ -1,6 +1,6 @@
import { Handlers, PageProps } from "$fresh/server.ts";
import { MainLayout } from "@components/layouts/main.tsx";
import { Article, getAllArticles } from "@lib/resource/articles.ts";
import { Article } from "@lib/resource/articles.ts";
import { KMenu } from "@islands/KMenu.tsx";
import { Grid } from "@components/Grid.tsx";
import { IconArrowLeft } from "@components/icons.tsx";
@@ -9,12 +9,14 @@ import { parseResourceUrl, searchResource } from "@lib/search.ts";
import { GenericResource } from "@lib/types.ts";
import { ResourceCard } from "@components/Card.tsx";
import { Link } from "@islands/Link.tsx";
import { fetchResource } from "@lib/resources.ts";
export const handler: Handlers<
{ articles: Article[] | null; searchResults?: GenericResource[] }
> = {
async GET(req, ctx) {
const articles = await getAllArticles();
const { content: articles } = await fetchResource("articles");
const searchParams = parseResourceUrl(req.url);
const searchResults = searchParams &&
await searchResource({ ...searchParams, types: ["article"] });