mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
36 lines
1 KiB
TypeScript
36 lines
1 KiB
TypeScript
import { getLogger } from "@logtape/logtape";
|
|
import { markdownParse } from "~/classes/functions/status";
|
|
import { sentry } from "./sentry.ts";
|
|
|
|
export const renderMarkdownInPath = async (
|
|
path: string,
|
|
defaultText?: string,
|
|
): Promise<{
|
|
content: string;
|
|
lastModified: Date;
|
|
}> => {
|
|
let content = await markdownParse(defaultText ?? "");
|
|
let lastModified = new Date(1970, 0, 0);
|
|
|
|
const extendedDescriptionFile = Bun.file(path || "");
|
|
|
|
if (path && (await extendedDescriptionFile.exists())) {
|
|
content =
|
|
(await markdownParse(
|
|
(await extendedDescriptionFile.text().catch(async (e) => {
|
|
await getLogger("server").error`${e}`;
|
|
sentry?.captureException(e);
|
|
return "";
|
|
})) ||
|
|
defaultText ||
|
|
"",
|
|
)) || "";
|
|
lastModified = new Date(extendedDescriptionFile.lastModified);
|
|
}
|
|
|
|
return {
|
|
content,
|
|
lastModified,
|
|
};
|
|
};
|