From 342f83c783390e68a815c4cc3d9c5fc4640b499b Mon Sep 17 00:00:00 2001 From: Max Richter Date: Wed, 22 Oct 2025 17:43:04 +0200 Subject: [PATCH] feat: display articles --- src/components/Image.astro | 4 +--- src/components/resources/Article.astro | 7 +++---- src/components/resources/Recipe.astro | 5 +++-- src/helpers/image.ts | 2 +- src/pages/resources/[resourceType]/[resourceName].astro | 2 -- src/pages/resources/[resourceType]/index.astro | 8 ++++---- src/pages/resources/resources.ts | 4 ++-- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/components/Image.astro b/src/components/Image.astro index f69f8ba..946da3b 100644 --- a/src/components/Image.astro +++ b/src/components/Image.astro @@ -3,9 +3,8 @@ import type { ImageMetadata } from "astro"; import { Picture as AstroImage } from "astro:assets"; import { inferRemoteSize } from 'astro/assets/utils'; import { generateThumbHash, getExifData } from "@helpers/image"; -import sharp from "sharp"; interface Props { - src: ImageMetadata & { fsPath?: string }; + src: ImageMetadata & { fsPath?: string, src?: string }; alt: string; pictureClass?: string; class?: string; @@ -16,7 +15,6 @@ interface Props { } async function checkImage(image: ImageMetadata) { -console.log("Checking image: ", image); const src = image.src; try { if (src.startsWith("/@fs") || src.startsWith("/_astro")) return true; diff --git a/src/components/resources/Article.astro b/src/components/resources/Article.astro index 82e47a6..5989818 100644 --- a/src/components/resources/Article.astro +++ b/src/components/resources/Article.astro @@ -1,11 +1,10 @@ --- import * as memorium from "@helpers/memorium"; -import { markdownToHtml, markdownToText } from "@helpers/markdown"; +import { markdownToHtml } from "@helpers/markdown"; import Image from "@components/Image.astro"; +import type { ImageMetadata } from "astro"; const { resource } = Astro.props; -const ingredients = resource?.content?.recipeIngredient || []; -const instructions = resource?.content?.recipeInstructions || []; ---

{resource?.content?.headline}

@@ -14,7 +13,7 @@ const instructions = resource?.content?.recipeInstructions || []; resource?.content?.image && ( Cover for {resource?.content?.name}{resource?.content?.name}
- {resource?.content?.image && Cover for {resource?.content?.name}} + {resource?.content?.image && Cover for {resource?.content?.name}}

{resource?.content?.description}

Ingredients

diff --git a/src/helpers/image.ts b/src/helpers/image.ts index ac4c53b..f594b6b 100644 --- a/src/helpers/image.ts +++ b/src/helpers/image.ts @@ -17,7 +17,7 @@ export async function generateThumbHash( if (!imagePath) return; - let sp; + let sp: ReturnType; if (imagePath.startsWith("https://") || imagePath.startsWith("http://")) { const res = await fetch(imagePath); if (!res.ok) { diff --git a/src/pages/resources/[resourceType]/[resourceName].astro b/src/pages/resources/[resourceType]/[resourceName].astro index 1ba7241..488909b 100644 --- a/src/pages/resources/[resourceType]/[resourceName].astro +++ b/src/pages/resources/[resourceType]/[resourceName].astro @@ -4,8 +4,6 @@ import { useTranslatedPath } from "@i18n/utils"; import ResourceDisplay from "@components/resources/Display.astro"; import * as memorium from "@helpers/memorium"; import { resources as resourceTypes } from "../resources.ts"; -import { markdownToText } from "@helpers/markdown"; -import Image from "@components/Image.astro"; const { resourceType, resourceName } = Astro?.params; diff --git a/src/pages/resources/[resourceType]/index.astro b/src/pages/resources/[resourceType]/index.astro index 5e49737..4344df9 100644 --- a/src/pages/resources/[resourceType]/index.astro +++ b/src/pages/resources/[resourceType]/index.astro @@ -3,11 +3,10 @@ import Layout from "@layouts/Layout.astro"; import HeroCard from "@components/HeroCard.astro"; import * as memorium from "@helpers/memorium"; import { resources as resourceTypes } from "../resources.ts"; -import { markdownToText } from "@helpers/markdown"; const { resourceType } = Astro.params; -async function safeGetResource(resType) { +async function safeGetResource() { try { return await memorium.listResource(resourceType); } catch (error) { @@ -15,7 +14,7 @@ async function safeGetResource(resType) { } } -const resources = await safeGetResource(resourceType); +const resources = await safeGetResource(); export async function getStaticPaths() { return resourceTypes.map((type: any) => { @@ -29,6 +28,7 @@ export async function getStaticPaths() { } function isValidResource(res) { + if(!res.content) return false; if (res?.content?.name) return true; if (res?.content?.headline) return true; return false; @@ -38,7 +38,7 @@ function isValidResource(res) { { resources.content - .filter((res) => res && res?.content) + .filter((res) => isValidResource(res)) .map((resource: any) => (