feat: add initial add article command
This commit is contained in:
@@ -9,6 +9,7 @@ import rehypeSanitize from "https://esm.sh/rehype-sanitize@5.0.1";
|
||||
import rehypeStringify from "https://esm.sh/rehype-stringify@9.0.3";
|
||||
import * as cache from "@lib/cache/documents.ts";
|
||||
import { SILVERBULLET_SERVER } from "@lib/env.ts";
|
||||
import { fixRenderedMarkdown } from "@lib/helpers.ts";
|
||||
|
||||
export type Document = {
|
||||
name: string;
|
||||
@@ -75,26 +76,13 @@ export function transformDocument(input: string, cb: (r: Root) => Root) {
|
||||
.use(remarkStringify)
|
||||
.processSync(input);
|
||||
|
||||
return String(out)
|
||||
.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;
|
||||
}
|
||||
});
|
||||
return fixRenderedMarkdown(String(out));
|
||||
}
|
||||
|
||||
export function parseDocument(doc: string) {
|
||||
return unified()
|
||||
.use(remarkParse).use(remarkFrontmatter, ["yaml", "toml"])
|
||||
.use(remarkParse)
|
||||
.use(remarkFrontmatter, ["yaml", "toml"])
|
||||
.parse(doc);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user