feat: add external link to articles
Some checks failed
Deploy to SFTP Server / build (push) Failing after 3m13s

This commit is contained in:
Max Richter
2025-10-24 19:08:03 +02:00
parent cf336da3c4
commit 83c099873d
7 changed files with 42 additions and 19 deletions

View File

@@ -15,7 +15,7 @@ interface Props {
} }
const { const {
data: { title, cover, icon, date, rating }, data: { title, cover, icon, date, rating, author },
collection, collection,
body, body,
id, id,
@@ -32,7 +32,12 @@ const link = translatePath(`/${collection}/${id.split("/")[0]}`);
<Card.Content classes="px-8 py-7 order-last xs:order-first"> <Card.Content classes="px-8 py-7 order-last xs:order-first">
{ {
(date || body || rating !== undefined) && ( (date || body || rating !== undefined) && (
<Card.Metadata date={date} readDuration={readDuration(body)} rating={rating} /> <Card.Metadata
date={date}
readDuration={readDuration(body)}
rating={rating}
author={author}
/>
) )
} }
<Card.Title classes="text-4xl flex items-center gap-2"> <Card.Title classes="text-4xl flex items-center gap-2">

View File

@@ -2,6 +2,7 @@
export let date: string | Date; export let date: string | Date;
export let readDuration: number | undefined; export let readDuration: number | undefined;
export let rating: string | number | undefined; export let rating: string | number | undefined;
export let author: string | undefined;
const toDate = (d: string | Date) => const toDate = (d: string | Date) =>
typeof d === "string" ? new Date(d) : d; typeof d === "string" ? new Date(d) : d;
@@ -33,19 +34,28 @@
}; };
</script> </script>
<div class="flex gap-5"> <div class="flex gap-3 wrapper">
{#if rating}
<div class="text-sm bg-light">{formatRating(rating)}</div>
{/if}
{#if date} {#if date}
<time class="text-sm text-neutral" datetime={iso(date)} <time class="text-sm bg-light" datetime={iso(date)}
>{formatDate(date)}</time> >{formatDate(date)}</time>
{/if} {/if}
{#if readDuration > 1}
{#if typeof readDuration === "number"} <div class="text-sm bg-light">{readDuration} mins read</div>
{#if readDuration > 1}
<div class="text-sm text-neutral">{readDuration} mins read</div>
{/if}
{/if} {/if}
{#if author}
{#if rating} <div class="text-sm bg-light">{author}</div>
<div class="text-sm text-neutral">{formatRating(rating)}</div>
{/if} {/if}
</div> </div>
<style>
.wrapper > * {
padding: 2px 11px;
border-radius: 14px;
font-size: 11px;
opacity: 0.7;
}
</style>

View File

@@ -12,6 +12,7 @@ const defaultSchema = ({ image }: { image: ImageFunction }) =>
toc: z.boolean().optional(), toc: z.boolean().optional(),
description: z.string().optional(), description: z.string().optional(),
icon: z.string().optional(), icon: z.string().optional(),
author: z.string().optional(),
draft: z.boolean().optional(), draft: z.boolean().optional(),
featured: z.boolean().optional(), featured: z.boolean().optional(),
tags: z.array(z.string()).optional(), tags: z.array(z.string()).optional(),

View File

@@ -20,10 +20,13 @@ export type MemoriumDir = {
export type MemoriumEntry = MemoriumFile | MemoriumDir; export type MemoriumEntry = MemoriumFile | MemoriumDir;
// const SERVER_URL = "https://marka.max-richter.dev";
const SERVER_URL = "http://localhost:8080";
export async function listResource( export async function listResource(
id: string, id: string,
): Promise<MemoriumEntry | undefined> { ): Promise<MemoriumEntry | undefined> {
const url = `https://marka.max-richter.dev/resources/${id}`; const url = `${SERVER_URL}/resources/${id}`;
try { try {
const response = await fetch(url); const response = await fetch(url);
if (response.ok) { if (response.ok) {
@@ -52,7 +55,7 @@ export function getImageUrl(input: string): string {
return input; return input;
} }
if (input.startsWith("/")) { 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}`;
} }

View File

@@ -53,7 +53,7 @@ export const ui = {
"toc.title": "Inhaltsverzeichnis", "toc.title": "Inhaltsverzeichnis",
"articles": "📰 Artikel", "articles": "📰 Artikel",
"articles.description": "articles.description":
"Random Artikel die mich beim lesen beindruckt haben", "Random Artikel die mich beim Lesen beindruckt haben",
"movies": "🎥 Filme", "movies": "🎥 Filme",
"movies.description": "movies.description":
"Gesehen, nicht gesehen, für gut befunden, für schlecht befunden.", "Gesehen, nicht gesehen, für gut befunden, für schlecht befunden.",

View File

@@ -43,6 +43,7 @@ const resource = await memorium.listResource(
href={path("/resources/" + resourceType)}> href={path("/resources/" + resourceType)}>
<span class="i-tabler-arrow-left"></span> back <span class="i-tabler-arrow-left"></span> back
</a> </a>
{resource?.content?.url && <a class="flex gap-1 items-center"href={resource?.content?.url}>link<span class="inline-block w-3 h-3 i-tabler-external-link"/></a>}
<div class="date opacity-50"> <div class="date opacity-50">
{ {
resource?.content.datePublished?.toLocaleString("en-US", { resource?.content.datePublished?.toLocaleString("en-US", {

View File

@@ -3,7 +3,7 @@ import Layout from "@layouts/Layout.astro";
import HeroCard from "@components/HeroCard.astro"; import HeroCard from "@components/HeroCard.astro";
import * as memorium from "@helpers/memorium"; import * as memorium from "@helpers/memorium";
import { resources as resourceTypes } from "../resources.ts"; import { resources as resourceTypes } from "../resources.ts";
import {useTranslations} from "@i18n/utils"; import { useTranslations } from "@i18n/utils";
const { resourceType } = Astro.params; const { resourceType } = Astro.params;
@@ -34,7 +34,6 @@ function isValidResource(res) {
} }
--- ---
<Layout title="Max Richter"> <Layout title="Max Richter">
<h1 class="text-4xl mb-4">{t(resourceType)}</h1> <h1 class="text-4xl mb-4">{t(resourceType)}</h1>
<p>{t(`${resourceType as "articles"}.description`)}</p> <p>{t(`${resourceType as "articles"}.description`)}</p>
@@ -47,8 +46,12 @@ function isValidResource(res) {
collection: "resources/" + resourceType, collection: "resources/" + resourceType,
id: resource.name.replace(/\.md$/, ""), id: resource.name.replace(/\.md$/, ""),
data: { 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, date: resource?.content?.datePublished,
author: resource?.content?.author?.name,
rating: resource?.content?.reviewRating?.ratingValue, rating: resource?.content?.reviewRating?.ratingValue,
cover: { cover: {
src: memorium.getImageUrl(resource.content.image), src: memorium.getImageUrl(resource.content.image),