fix: handle empty markdown
All checks were successful
Deploy to SFTP Server / build (push) Successful in 10m50s

This commit is contained in:
Max Richter
2025-10-22 18:15:38 +02:00
parent 3b583eade5
commit c542408f6a
3 changed files with 6 additions and 4 deletions

View File

@@ -17,13 +17,16 @@ export async function generateThumbHash(
if (!imagePath) return;
if (imagePath.endsWith(".svg")) return;
let sp: ReturnType<typeof sharp>;
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 "";
}

View File

@@ -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);
}

View File

@@ -24,7 +24,6 @@ export async function listResource(
id: string,
): Promise<MemoriumEntry | undefined> {
const url = `https://marka.max-richter.dev/resources/${id}`;
console.log("Fetching: ", url);
try {
const response = await fetch(url);
if (response.ok) {