feat: display articles

This commit is contained in:
Max Richter
2025-10-22 17:17:34 +02:00
parent d57df62513
commit b6bee0df53
10 changed files with 121 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
---
import markdownToText from "@helpers/markdownToText";
import { markdownToText,readDuration } from "@helpers/markdown";
import { Card } from "./card";
import { useTranslatedPath, useTranslations } from "@i18n/utils";
import Image from "@components/Image.astro";
@@ -30,7 +30,7 @@ const link = translatePath(`/${collection}/${id.split("/")[0]}`);
<Card
classes={`grid gradient border-1 border-neutral overflow-hidden ${cover ? "grid-rows-[200px_1fr] xs:grid-rows-none xs:grid-cols-[1fr_200px]" : ""}`}>
<Card.Content classes="px-8 py-7 order-last xs:order-first">
{date && (<Card.Metadata date={date} />)}
{(date || body)&& <Card.Metadata date={date} readDuration={readDuration(body)} />}
<Card.Title classes="text-4xl flex items-center gap-2">
{
icon &&

View File

@@ -1,5 +1,5 @@
---
import markdownToText from "@helpers/markdownToText";
import { markdownToText } from "@helpers/markdown";
import { useTranslatedPath } from "@i18n/utils";
import type { InferEntrySchema } from "astro:content";

View File

@@ -1,5 +1,6 @@
<script lang="ts">
export let date: string | Date;
export let readDuration: string | undefined;
const toDate = (d: string | Date) =>
typeof d === "string" ? new Date(d) : d;
@@ -22,4 +23,8 @@
<time class="text-sm text-neutral" datetime={iso(date)}
>{formatDate(date)}</time>
{/if}
{#if readDuration}
<div class="text-sm text-neutral">{readDuration} mins read</div>
{/if}
</div>

View File

@@ -0,0 +1,25 @@
---
import * as memorium from "@helpers/memorium";
import { markdownToHtml, markdownToText } from "@helpers/markdown";
import Image from "@components/Image.astro";
const { resource } = Astro.props;
const ingredients = resource?.content?.recipeIngredient || [];
const instructions = resource?.content?.recipeInstructions || [];
---
<h1 class="text-4xl">{resource?.content?.headline}</h1>
<div>
{
resource?.content?.image && (
<Image
hash
src={{ src: memorium.getImageUrl(resource.content.image) }}
alt="Cover for {resource?.content?.name}"
class="rounded-2xl overflow-hidden"
pictureClass="rounded-2xl"
/>
)
}
</div>
<div set:html={markdownToHtml(resource?.content?.articleBody)} />

View File

@@ -0,0 +1,13 @@
---
import Recipe from "./Recipe.astro";
import Article from "./Article.astro";
const { resource } = Astro.props;
const type = resource?.content?._type ?? "unknown";
---
{type === "Recipe" && <Recipe resource={resource} />}
{type === "Article" && <Article resource={resource} />}
{type === "unknown" && <div>
<h3>Unknown resource type</h3>
</div>}

View File

@@ -0,0 +1,32 @@
---
import * as memorium from "@helpers/memorium";
import { markdownToHtml, markdownToText } from "@helpers/markdown";
import Image from "@components/Image.astro";
const { resource } = Astro.props
const ingredients = resource?.content?.recipeIngredient || [];
const instructions = resource?.content?.recipeInstructions || [];
---
<h1 class="text-4xl">{resource?.content?.name}</h1>
<div>
{resource?.content?.image && <Image hash src={{src: memorium.getImageUrl(resource.content.image)}} alt="Cover for {resource?.content?.name}" class="rounded-2xl overflow-hidden" pictureClass="rounded-2xl" />}
</div>
<p>{resource?.content?.description}</p>
<h2 class="text-2xl">Ingredients</h2>
<ul>
{
ingredients.map((ingredient) => (
<li set:html={markdownToHtml(ingredient)}/>
))
}
</ul>
<h2 class="text-2xl">Steps</h2>
<ol>
{
instructions.map((ingredient) => (
<li set:html={markdownToHtml(ingredient)}/>
))
}
</ol>