refactor: remove some duplicated code

This commit is contained in:
2023-08-01 17:50:00 +02:00
parent 01697a6686
commit c5cf629482
30 changed files with 377 additions and 321 deletions

View File

@@ -1,5 +1,5 @@
import { unified } from "npm:unified";
import remarkParse from "npm:remark-parse";
import { unified } from "https://esm.sh/unified";
import remarkParse from "https://esm.sh/remark-parse";
import remarkStringify from "https://esm.sh/remark-stringify@10.0.3";
import remarkFrontmatter, {
Root,
@@ -7,10 +7,8 @@ import remarkFrontmatter, {
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";
const SILVERBULLET_SERVER = Deno.env.get("SILVERBULLET_SERVER");
import { SILVERBULLET_SERVER } from "@lib/env.ts";
export type Document = {
name: string;
@@ -20,10 +18,6 @@ export type Document = {
perm: string;
};
export function parseFrontmatter(yaml: string) {
return parse(yaml);
}
export async function getDocuments(): Promise<Document[]> {
const cachedDocuments = await cache.getDocuments();
if (cachedDocuments) return cachedDocuments;
@@ -31,7 +25,7 @@ export async function getDocuments(): Promise<Document[]> {
const headers = new Headers();
headers.append("Accept", "application/json");
const response = await fetch(SILVERBULLET_SERVER + "/index.json", {
const response = await fetch(`${SILVERBULLET_SERVER}/index.json`, {
headers: headers,
});