2024-06-27 01:11:39 +02:00
|
|
|
import { getLogger } from "@logtape/logtape";
|
2024-06-29 05:50:56 +02:00
|
|
|
import { markdownParse } from "~/classes/functions/status";
|
2024-06-11 21:55:40 +02:00
|
|
|
|
|
|
|
|
export const renderMarkdownInPath = async (
|
|
|
|
|
path: string,
|
|
|
|
|
defaultText?: string,
|
|
|
|
|
) => {
|
|
|
|
|
let content = await markdownParse(defaultText ?? "");
|
|
|
|
|
let lastModified = new Date(1970, 0, 0);
|
|
|
|
|
|
2024-06-13 04:26:43 +02:00
|
|
|
const extendedDescriptionFile = Bun.file(path || "");
|
2024-06-11 21:55:40 +02:00
|
|
|
|
2024-06-13 04:26:43 +02:00
|
|
|
if (path && (await extendedDescriptionFile.exists())) {
|
2024-06-11 21:55:40 +02:00
|
|
|
content =
|
|
|
|
|
(await markdownParse(
|
2024-06-13 04:26:43 +02:00
|
|
|
(await extendedDescriptionFile.text().catch(async (e) => {
|
2024-06-27 01:11:39 +02:00
|
|
|
await getLogger("server").error`${e}`;
|
2024-06-11 21:55:40 +02:00
|
|
|
return "";
|
|
|
|
|
})) ||
|
|
|
|
|
defaultText ||
|
|
|
|
|
"",
|
|
|
|
|
)) || "";
|
2024-06-13 04:26:43 +02:00
|
|
|
lastModified = new Date(extendedDescriptionFile.lastModified);
|
2024-06-11 21:55:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
content: content,
|
|
|
|
|
lastModified,
|
|
|
|
|
};
|
|
|
|
|
};
|