feat: implement adding movie details from tmdb
This commit is contained in:
11
lib/cache/cache.ts
vendored
11
lib/cache/cache.ts
vendored
@ -30,13 +30,20 @@ const cache = await createCache();
|
||||
|
||||
export async function get<T>(id: string, binary = false) {
|
||||
if (binary && !(cache instanceof Map)) {
|
||||
return await cache.sendCommand("GET", [id], {
|
||||
const cacheHit = await cache.sendCommand("GET", [id], {
|
||||
returnUint8Arrays: true,
|
||||
}) as T;
|
||||
if (cacheHit) console.log("[cache] HIT ", { id });
|
||||
else console.log("[cache] MISS", { id });
|
||||
return cacheHit;
|
||||
}
|
||||
return await cache.get(id) as T;
|
||||
const cacheHit = await cache.get(id) as T;
|
||||
if (cacheHit) console.log("[cache] HIT ", { id });
|
||||
else console.log("[cache] MISS", { id });
|
||||
return cacheHit;
|
||||
}
|
||||
|
||||
export async function set<T extends RedisValue>(id: string, content: T) {
|
||||
console.log("[cache] storing ", { id });
|
||||
return await cache.set(id, content);
|
||||
}
|
||||
|
@ -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"])
|
||||
|
4
lib/string.ts
Normal file
4
lib/string.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export function formatDate(date: Date): string {
|
||||
const options = { year: "numeric", month: "long", day: "numeric" } as const;
|
||||
return new Intl.DateTimeFormat("en-US", options).format(date);
|
||||
}
|
Reference in New Issue
Block a user