2023-08-01 17:50:00 +02:00
|
|
|
export function json(content: unknown) {
|
|
|
|
const headers = new Headers();
|
|
|
|
headers.append("Content-Type", "application/json");
|
|
|
|
return new Response(JSON.stringify(content), {
|
|
|
|
headers,
|
|
|
|
});
|
|
|
|
}
|
2023-08-01 21:35:21 +02:00
|
|
|
|
|
|
|
export const isValidUrl = (urlString: string) => {
|
|
|
|
try {
|
|
|
|
return Boolean(new URL(urlString));
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const fixRenderedMarkdown = (content: string) => {
|
|
|
|
return content.replace("***\n", "---")
|
|
|
|
.replace("----------------", "---")
|
|
|
|
.replace("\n---", "---")
|
|
|
|
.replace(/^(date:[^'\n]*)'|'/gm, (match, p1, p2) => {
|
|
|
|
if (p1) {
|
|
|
|
// This is a line starting with date: followed by single quotes
|
|
|
|
return p1.replace(/'/gm, "");
|
|
|
|
} else if (p2) {
|
|
|
|
return "";
|
|
|
|
} else {
|
|
|
|
// This is a line with single quotes, but not starting with date:
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|