feat: implement adding movie details from tmdb
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { unified } from "npm:unified";
|
||||
import remarkParse from "npm:remark-parse";
|
||||
import remarkFrontmatter from "https://esm.sh/remark-frontmatter@4";
|
||||
import remarkRehype from "https://esm.sh/remark-rehype";
|
||||
import rehypeSanitize from "https://esm.sh/rehype-sanitize";
|
||||
import rehypeStringify from "https://esm.sh/rehype-stringify";
|
||||
import remarkStringify from "https://esm.sh/remark-stringify@10.0.3";
|
||||
import remarkFrontmatter, {
|
||||
Root,
|
||||
} from "https://esm.sh/remark-frontmatter@4.0.1";
|
||||
import remarkRehype from "https://esm.sh/remark-rehype@10.1.0";
|
||||
import rehypeSanitize from "https://esm.sh/rehype-sanitize@5.0.1";
|
||||
import rehypeStringify from "https://esm.sh/rehype-stringify@9.0.3";
|
||||
import { parse } from "https://deno.land/std@0.194.0/yaml/mod.ts";
|
||||
import * as cache from "@lib/cache/documents.ts";
|
||||
|
||||
@@ -38,7 +41,7 @@ export async function getDocuments(): Promise<Document[]> {
|
||||
return documents;
|
||||
}
|
||||
|
||||
export async function createDocument(
|
||||
export function createDocument(
|
||||
name: string,
|
||||
content: string | ArrayBuffer,
|
||||
mediaType?: string,
|
||||
@@ -49,13 +52,11 @@ export async function createDocument(
|
||||
headers.append("Content-Type", mediaType);
|
||||
}
|
||||
|
||||
const response = await fetch(SILVERBULLET_SERVER + "/" + name, {
|
||||
return fetch(SILVERBULLET_SERVER + "/" + name, {
|
||||
body: content,
|
||||
method: "PUT",
|
||||
headers,
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function getDocument(name: string): Promise<string> {
|
||||
@@ -70,6 +71,33 @@ export async function getDocument(name: string): Promise<string> {
|
||||
return text;
|
||||
}
|
||||
|
||||
export function transformDocument(input: string, cb: (r: Root) => Root) {
|
||||
const out = unified()
|
||||
.use(remarkParse)
|
||||
.use(remarkFrontmatter, ["yaml"])
|
||||
.use(() => (tree) => {
|
||||
return cb(tree);
|
||||
})
|
||||
.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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function parseDocument(doc: string) {
|
||||
return unified()
|
||||
.use(remarkParse).use(remarkFrontmatter, ["yaml", "toml"])
|
||||
|
||||
Reference in New Issue
Block a user