fix: handle empty markdown
All checks were successful
Deploy to SFTP Server / build (push) Successful in 10m50s
All checks were successful
Deploy to SFTP Server / build (push) Successful in 10m50s
This commit is contained in:
@@ -17,13 +17,16 @@ export async function generateThumbHash(
|
|||||||
|
|
||||||
if (!imagePath) return;
|
if (!imagePath) return;
|
||||||
|
|
||||||
|
if (imagePath.endsWith(".svg")) return;
|
||||||
|
|
||||||
let sp: ReturnType<typeof sharp>;
|
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) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sp = sharp(await res.arrayBuffer());
|
const buffer = await res.arrayBuffer();
|
||||||
|
sp = sharp(buffer);
|
||||||
} else {
|
} else {
|
||||||
sp = sharp(imagePath);
|
sp = sharp(imagePath);
|
||||||
}
|
}
|
||||||
@@ -44,10 +47,9 @@ export async function generateThumbHash(
|
|||||||
|
|
||||||
const buffer = rgbaToThumbHash(smallWidth, smallHeight, smallImg);
|
const buffer = rgbaToThumbHash(smallWidth, smallHeight, smallImg);
|
||||||
return Buffer.from(buffer).toString("base64");
|
return Buffer.from(buffer).toString("base64");
|
||||||
} catch (error) {
|
} catch (_error) {
|
||||||
console.log(
|
console.log(
|
||||||
`Could not generate thumbhash for ${image.fsPath ?? image.src}`,
|
`Could not generate thumbhash for ${image.fsPath ?? image.src}`,
|
||||||
error,
|
|
||||||
);
|
);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import MarkdownIt from "markdown-it";
|
|||||||
const parser = new MarkdownIt();
|
const parser = new MarkdownIt();
|
||||||
|
|
||||||
export function readDuration(markdown: string): number | undefined {
|
export function readDuration(markdown: string): number | undefined {
|
||||||
|
if (!markdown) return;
|
||||||
const words = markdown.split(" ")?.filter(Boolean)?.length;
|
const words = markdown.split(" ")?.filter(Boolean)?.length;
|
||||||
return words && Math.round(words / 250);
|
return words && Math.round(words / 250);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ 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 = `https://marka.max-richter.dev/resources/${id}`;
|
||||||
console.log("Fetching: ", url);
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user