diff --git a/src/components/HeroCard.astro b/src/components/HeroCard.astro index 66675e8..b8db077 100644 --- a/src/components/HeroCard.astro +++ b/src/components/HeroCard.astro @@ -1,5 +1,5 @@ --- -import { markdownToText,readDuration } from "@helpers/markdown"; +import { markdownToText, readDuration } from "@helpers/markdown"; import { Card } from "./card"; import { useTranslatedPath, useTranslations } from "@i18n/utils"; import Image from "@components/Image.astro"; @@ -15,7 +15,7 @@ interface Props { } const { - data: { title, cover, icon, date }, + data: { title, cover, icon, date, reviewRating }, collection, body, id, @@ -30,7 +30,11 @@ const link = translatePath(`/${collection}/${id.split("/")[0]}`); - {(date || body)&& } + { + (date || body || reviewRating !== undefined) && ( + + ) + } { icon && diff --git a/src/components/card/Metadata.svelte b/src/components/card/Metadata.svelte index 9034869..51762ca 100644 --- a/src/components/card/Metadata.svelte +++ b/src/components/card/Metadata.svelte @@ -10,12 +10,17 @@ return isNaN(v.getTime()) ? "" : v.toISOString(); }; - const formatDate = (d: string | Date) => - new Intl.DateTimeFormat("de-DE", { - day: "2-digit", - month: "long", - year: "numeric", - }).format(toDate(d)); + const formatDate = (d: string | Date) => { + try { + return new Intl.DateTimeFormat("de-DE", { + day: "2-digit", + month: "long", + year: "numeric", + }).format(toDate(d)); + } catch (err) { + return ""; + } + };
diff --git a/src/components/resources/Display.astro b/src/components/resources/Display.astro index a79cad3..9404d01 100644 --- a/src/components/resources/Display.astro +++ b/src/components/resources/Display.astro @@ -1,13 +1,34 @@ --- +import { Code } from 'astro:components'; import Recipe from "./Recipe.astro"; import Article from "./Article.astro"; +import IconCode from "~icons/tabler/Code"; +import Review from "./Review.astro"; const { resource } = Astro.props; const type = resource?.content?._type ?? "unknown"; --- {type === "Recipe" && } {type === "Article" &&
} +{type === "Review" && } -{type === "unknown" &&
-

Unknown resource type

-
} +{ + type === "unknown" && ( +
+

Unknown resource type

+
+ ) +} + +
+ + +
+ + diff --git a/src/components/resources/Review.astro b/src/components/resources/Review.astro new file mode 100644 index 0000000..2876ad1 --- /dev/null +++ b/src/components/resources/Review.astro @@ -0,0 +1,28 @@ +--- +import * as memorium from "@helpers/memorium"; +import { markdownToHtml } from "@helpers/markdown"; +import Image from "@components/Image.astro"; +import type { ImageMetadata } from "astro"; + +const { resource } = Astro.props; +--- + +
+ { + resource?.content?.image && ( + Cover for {resource?.content?.name} + ) + } +

{resource?.content?.itemReviewed?.name || "Unknown Name"}

+ { resource?.content?.reviewRating?.ratingValue !== undefined &&
{resource?.content?.reviewRating?.ratingValue}
} +
+ +
diff --git a/src/pages/resources/[resourceType]/index.astro b/src/pages/resources/[resourceType]/index.astro index 4344df9..b06c788 100644 --- a/src/pages/resources/[resourceType]/index.astro +++ b/src/pages/resources/[resourceType]/index.astro @@ -21,17 +21,14 @@ export async function getStaticPaths() { return { params: { resourceType: type.id, - resourceName: "Recipe", + resourceName: type.data.title, }, }; }); } function isValidResource(res) { - if(!res.content) return false; - if (res?.content?.name) return true; - if (res?.content?.headline) return true; - return false; + return !!res?.content?._type; } --- @@ -45,8 +42,9 @@ function isValidResource(res) { collection: "resources/" + resourceType, id: resource.name.replace(/\.md$/, ""), data: { - title: resource.content.name ?? resource.content.headline, + title: resource?.content?.name ?? resource?.content?.headline ?? resource.content?.itemReviewed?.name, date: resource?.content?.datePublished, + rating: resource?.content?.reviewRating, cover: { src: memorium.getImageUrl(resource.content.image), }, @@ -56,4 +54,3 @@ function isValidResource(res) { )) } - diff --git a/src/pages/resources/resources.ts b/src/pages/resources/resources.ts index b6351ac..fa268ca 100644 --- a/src/pages/resources/resources.ts +++ b/src/pages/resources/resources.ts @@ -3,6 +3,7 @@ const collection = "resources"; export type ResourceType = { id: string; collection: string; + body?: string; data: { title: string; icon: string; @@ -37,24 +38,22 @@ const recipes = { }, }; -// const movies = { -// id: "Movies", -// collection, -// body: "Movies", -// data: { -// title: "Movies", -// icon: "🎥", -// }, -// }; +const movies = { + id: "movies", + collection, + data: { + title: "Movies", + icon: "🎥", + }, +}; -// const series = { -// id: "Series", -// collection, -// body: "Series", -// data: { -// title: "Series", -// icon: "📺", -// }, -// }; +const series = { + id: "series", + collection, + data: { + title: "Series", + icon: "📺", + }, +}; -export const resources: ResourceType[] = [recipes, articles]; +export const resources: ResourceType[] = [recipes, articles, movies, series];