feat: add initial add article command

This commit is contained in:
2023-08-01 21:35:21 +02:00
parent e51667bbac
commit ea11495d1a
17 changed files with 534 additions and 67 deletions

View File

@@ -5,3 +5,28 @@ export function json(content: unknown) {
headers,
});
}
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;
}
});
};