From 83c099873d6e849178041e52fd839ffaa861dc2a Mon Sep 17 00:00:00 2001 From: Max Richter Date: Fri, 24 Oct 2025 19:08:03 +0200 Subject: [PATCH] feat: add external link to articles --- src/components/HeroCard.astro | 9 ++++-- src/components/card/Metadata.svelte | 30 ++++++++++++------- src/content.config.ts | 1 + src/helpers/memorium.ts | 9 ++++-- src/i18n/ui.ts | 2 +- .../[resourceType]/[resourceName].astro | 1 + .../resources/[resourceType]/index.astro | 9 ++++-- 7 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/components/HeroCard.astro b/src/components/HeroCard.astro index 010e0cb..8f1857f 100644 --- a/src/components/HeroCard.astro +++ b/src/components/HeroCard.astro @@ -15,7 +15,7 @@ interface Props { } const { - data: { title, cover, icon, date, rating }, + data: { title, cover, icon, date, rating, author }, collection, body, id, @@ -32,7 +32,12 @@ const link = translatePath(`/${collection}/${id.split("/")[0]}`); { (date || body || rating !== undefined) && ( - + ) } diff --git a/src/components/card/Metadata.svelte b/src/components/card/Metadata.svelte index 6a13c21..a2ae662 100644 --- a/src/components/card/Metadata.svelte +++ b/src/components/card/Metadata.svelte @@ -2,6 +2,7 @@ export let date: string | Date; export let readDuration: number | undefined; export let rating: string | number | undefined; + export let author: string | undefined; const toDate = (d: string | Date) => typeof d === "string" ? new Date(d) : d; @@ -33,19 +34,28 @@ }; -
+
+ {#if rating} +
{formatRating(rating)}
+ {/if} {#if date} - {/if} - - {#if typeof readDuration === "number"} - {#if readDuration > 1} -
{readDuration} mins read
- {/if} + {#if readDuration > 1} +
{readDuration} mins read
{/if} - - {#if rating} -
{formatRating(rating)}
+ {#if author} +
{author}
{/if}
+ + + diff --git a/src/content.config.ts b/src/content.config.ts index 4c81fd5..40f9406 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -12,6 +12,7 @@ const defaultSchema = ({ image }: { image: ImageFunction }) => toc: z.boolean().optional(), description: z.string().optional(), icon: z.string().optional(), + author: z.string().optional(), draft: z.boolean().optional(), featured: z.boolean().optional(), tags: z.array(z.string()).optional(), diff --git a/src/helpers/memorium.ts b/src/helpers/memorium.ts index a4aa1d4..ecaa75c 100644 --- a/src/helpers/memorium.ts +++ b/src/helpers/memorium.ts @@ -20,10 +20,13 @@ export type MemoriumDir = { export type MemoriumEntry = MemoriumFile | MemoriumDir; +// const SERVER_URL = "https://marka.max-richter.dev"; +const SERVER_URL = "http://localhost:8080"; + export async function listResource( id: string, ): Promise { - const url = `https://marka.max-richter.dev/resources/${id}`; + const url = `${SERVER_URL}/resources/${id}`; try { const response = await fetch(url); if (response.ok) { @@ -52,7 +55,7 @@ export function getImageUrl(input: string): string { return input; } if (input.startsWith("/")) { - return `https://marka.max-richter.dev${input}`; + return `${SERVER_URL}${input}`; } - return `https://marka.max-richter.dev/${input}`; + return `${SERVER_URL}/${input}`; } diff --git a/src/i18n/ui.ts b/src/i18n/ui.ts index 41168cd..d24b4a6 100644 --- a/src/i18n/ui.ts +++ b/src/i18n/ui.ts @@ -53,7 +53,7 @@ export const ui = { "toc.title": "Inhaltsverzeichnis", "articles": "📰 Artikel", "articles.description": - "Random Artikel die mich beim lesen beindruckt haben", + "Random Artikel die mich beim Lesen beindruckt haben", "movies": "🎥 Filme", "movies.description": "Gesehen, nicht gesehen, für gut befunden, für schlecht befunden.", diff --git a/src/pages/resources/[resourceType]/[resourceName].astro b/src/pages/resources/[resourceType]/[resourceName].astro index e3580e5..c879923 100644 --- a/src/pages/resources/[resourceType]/[resourceName].astro +++ b/src/pages/resources/[resourceType]/[resourceName].astro @@ -43,6 +43,7 @@ const resource = await memorium.listResource( href={path("/resources/" + resourceType)}> back + {resource?.content?.url && link}
{ resource?.content.datePublished?.toLocaleString("en-US", { diff --git a/src/pages/resources/[resourceType]/index.astro b/src/pages/resources/[resourceType]/index.astro index 43c75b0..873e534 100644 --- a/src/pages/resources/[resourceType]/index.astro +++ b/src/pages/resources/[resourceType]/index.astro @@ -3,7 +3,7 @@ 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 {useTranslations} from "@i18n/utils"; +import { useTranslations } from "@i18n/utils"; const { resourceType } = Astro.params; @@ -34,7 +34,6 @@ function isValidResource(res) { } --- -

{t(resourceType)}

{t(`${resourceType as "articles"}.description`)}

@@ -47,8 +46,12 @@ function isValidResource(res) { collection: "resources/" + resourceType, id: resource.name.replace(/\.md$/, ""), data: { - title: resource?.content?.name ?? resource?.content?.headline ?? resource.content?.itemReviewed?.name, + title: + resource?.content?.name ?? + resource?.content?.headline ?? + resource.content?.itemReviewed?.name, date: resource?.content?.datePublished, + author: resource?.content?.author?.name, rating: resource?.content?.reviewRating?.ratingValue, cover: { src: memorium.getImageUrl(resource.content.image),