feat: display articles
Some checks failed
Deploy to SFTP Server / build (push) Failing after 3m59s

This commit is contained in:
Max Richter
2025-10-22 17:43:04 +02:00
parent ae266dbdc5
commit 342f83c783
7 changed files with 14 additions and 18 deletions

View File

@@ -3,9 +3,8 @@ import type { ImageMetadata } from "astro";
import { Picture as AstroImage } from "astro:assets"; import { Picture as AstroImage } from "astro:assets";
import { inferRemoteSize } from 'astro/assets/utils'; import { inferRemoteSize } from 'astro/assets/utils';
import { generateThumbHash, getExifData } from "@helpers/image"; import { generateThumbHash, getExifData } from "@helpers/image";
import sharp from "sharp";
interface Props { interface Props {
src: ImageMetadata & { fsPath?: string }; src: ImageMetadata & { fsPath?: string, src?: string };
alt: string; alt: string;
pictureClass?: string; pictureClass?: string;
class?: string; class?: string;
@@ -16,7 +15,6 @@ interface Props {
} }
async function checkImage(image: ImageMetadata) { async function checkImage(image: ImageMetadata) {
console.log("Checking image: ", image);
const src = image.src; const src = image.src;
try { try {
if (src.startsWith("/@fs") || src.startsWith("/_astro")) return true; if (src.startsWith("/@fs") || src.startsWith("/_astro")) return true;

View File

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

View File

@@ -1,7 +1,8 @@
--- ---
import * as memorium from "@helpers/memorium"; import * as memorium from "@helpers/memorium";
import { markdownToHtml, markdownToText } from "@helpers/markdown"; import { markdownToHtml } from "@helpers/markdown";
import Image from "@components/Image.astro"; import Image from "@components/Image.astro";
import type { ImageMetadata } from "astro";
const { resource } = Astro.props const { resource } = Astro.props
const ingredients = resource?.content?.recipeIngredient || []; const ingredients = resource?.content?.recipeIngredient || [];
@@ -10,7 +11,7 @@ const instructions = resource?.content?.recipeInstructions || [];
<h1 class="text-4xl">{resource?.content?.name}</h1> <h1 class="text-4xl">{resource?.content?.name}</h1>
<div> <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" />} {resource?.content?.image && <Image hash src={{src: memorium.getImageUrl(resource.content.image)} as ImageMetadata} alt="Cover for {resource?.content?.name}" class="rounded-2xl overflow-hidden" pictureClass="rounded-2xl" />}
</div> </div>
<p>{resource?.content?.description}</p> <p>{resource?.content?.description}</p>
<h2 class="text-2xl">Ingredients</h2> <h2 class="text-2xl">Ingredients</h2>

View File

@@ -17,7 +17,7 @@ export async function generateThumbHash(
if (!imagePath) return; if (!imagePath) return;
let sp; let sp: ReturnType<typeof sharp>;
if (imagePath.startsWith("https://") || imagePath.startsWith("http://")) { if (imagePath.startsWith("https://") || imagePath.startsWith("http://")) {
const res = await fetch(imagePath); const res = await fetch(imagePath);
if (!res.ok) { if (!res.ok) {

View File

@@ -4,8 +4,6 @@ import { useTranslatedPath } from "@i18n/utils";
import ResourceDisplay from "@components/resources/Display.astro"; import ResourceDisplay from "@components/resources/Display.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 { markdownToText } from "@helpers/markdown";
import Image from "@components/Image.astro";
const { resourceType, resourceName } = Astro?.params; const { resourceType, resourceName } = Astro?.params;

View File

@@ -3,11 +3,10 @@ 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 { markdownToText } from "@helpers/markdown";
const { resourceType } = Astro.params; const { resourceType } = Astro.params;
async function safeGetResource(resType) { async function safeGetResource() {
try { try {
return await memorium.listResource(resourceType); return await memorium.listResource(resourceType);
} catch (error) { } catch (error) {
@@ -15,7 +14,7 @@ async function safeGetResource(resType) {
} }
} }
const resources = await safeGetResource(resourceType); const resources = await safeGetResource();
export async function getStaticPaths() { export async function getStaticPaths() {
return resourceTypes.map((type: any) => { return resourceTypes.map((type: any) => {
@@ -29,6 +28,7 @@ export async function getStaticPaths() {
} }
function isValidResource(res) { function isValidResource(res) {
if(!res.content) return false;
if (res?.content?.name) return true; if (res?.content?.name) return true;
if (res?.content?.headline) return true; if (res?.content?.headline) return true;
return false; return false;
@@ -38,7 +38,7 @@ function isValidResource(res) {
<Layout title="Max Richter"> <Layout title="Max Richter">
{ {
resources.content resources.content
.filter((res) => res && res?.content) .filter((res) => isValidResource(res))
.map((resource: any) => ( .map((resource: any) => (
<HeroCard <HeroCard
post={{ post={{

View File

@@ -1,6 +1,6 @@
const collection = "resources"; const collection = "resources";
type Resource = { export type ResourceType = {
id: string; id: string;
collection: string; collection: string;
data: { data: {
@@ -57,4 +57,4 @@ const recipes = {
// }, // },
// }; // };
export const resources: Resource[] = [recipes, articles]; export const resources: ResourceType[] = [recipes, articles];