From c542408f6a29e3f620a4436196bd0af2596b9b21 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Wed, 22 Oct 2025 18:15:38 +0200 Subject: [PATCH] fix: handle empty markdown --- src/helpers/image.ts | 8 +++++--- src/helpers/markdown.ts | 1 + src/helpers/memorium.ts | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/helpers/image.ts b/src/helpers/image.ts index f594b6b..3d69610 100644 --- a/src/helpers/image.ts +++ b/src/helpers/image.ts @@ -17,13 +17,16 @@ export async function generateThumbHash( if (!imagePath) return; + if (imagePath.endsWith(".svg")) return; + let sp: ReturnType; if (imagePath.startsWith("https://") || imagePath.startsWith("http://")) { const res = await fetch(imagePath); if (!res.ok) { return; } - sp = sharp(await res.arrayBuffer()); + const buffer = await res.arrayBuffer(); + sp = sharp(buffer); } else { sp = sharp(imagePath); } @@ -44,10 +47,9 @@ export async function generateThumbHash( const buffer = rgbaToThumbHash(smallWidth, smallHeight, smallImg); return Buffer.from(buffer).toString("base64"); - } catch (error) { + } catch (_error) { console.log( `Could not generate thumbhash for ${image.fsPath ?? image.src}`, - error, ); return ""; } diff --git a/src/helpers/markdown.ts b/src/helpers/markdown.ts index 63f6f61..6745597 100644 --- a/src/helpers/markdown.ts +++ b/src/helpers/markdown.ts @@ -2,6 +2,7 @@ import MarkdownIt from "markdown-it"; const parser = new MarkdownIt(); export function readDuration(markdown: string): number | undefined { + if (!markdown) return; const words = markdown.split(" ")?.filter(Boolean)?.length; return words && Math.round(words / 250); } diff --git a/src/helpers/memorium.ts b/src/helpers/memorium.ts index f3f820d..a4aa1d4 100644 --- a/src/helpers/memorium.ts +++ b/src/helpers/memorium.ts @@ -24,7 +24,6 @@ export async function listResource( id: string, ): Promise { const url = `https://marka.max-richter.dev/resources/${id}`; - console.log("Fetching: ", url); try { const response = await fetch(url); if (response.ok) {