From e65a70aa402d9ec1ffd4201b443a9ddaf5f7c60e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 8 Oct 2023 15:08:39 +0200 Subject: [PATCH] Changes --- src/components/admin/pages/Edit.svelte | 18 +++++++++++++++--- src/components/admin/repo/page.ts | 6 +++++- src/components/admin/types/page.ts | 7 ++++++- src/content/src/content/pages/en/about.md | 7 ------- 4 files changed, 26 insertions(+), 12 deletions(-) delete mode 100644 src/content/src/content/pages/en/about.md diff --git a/src/components/admin/pages/Edit.svelte b/src/components/admin/pages/Edit.svelte index b5a9d12..1f537a9 100644 --- a/src/components/admin/pages/Edit.svelte +++ b/src/components/admin/pages/Edit.svelte @@ -3,11 +3,12 @@ import {ArrowLeftSolid} from "flowbite-svelte-icons"; import {Button, Card, Input, Label, Navbar, NavBrand, NavHamburger, NavUl, Spinner} from "flowbite-svelte"; import {pageRepo} from "../repo/repo.js"; import {mapToMap, nameRegex} from "../util.ts"; -import Editor from "./edit/Editor.svelte"; import TypeAheadSearch from "../components/TypeAheadSearch.svelte"; import {branches} from "../stores/stores.ts"; +import Editor from "./edit/Editor.svelte"; + +$: pagesFuture = $pageRepo.listPages(selectedBranch); -let pagesFuture = $pageRepo.listPages(); let selected: number | null = null; let selectedBranch: string = "master"; @@ -54,6 +55,16 @@ async function deleteBranch() { } } +async function createFile() { + let name = prompt("File name:", "pages/en/[Name]") + if (name) { + await $pageRepo.createFile(`${name}.md`, selectedBranch) + const w = selectedBranch + selectedBranch = "###!" + selectedBranch = w + } +} +
@@ -73,8 +84,9 @@ async function deleteBranch() {
- + +
{@const pagesMap = mapToMap(pages)} diff --git a/src/components/admin/repo/page.ts b/src/components/admin/repo/page.ts index a4c5580..e659783 100644 --- a/src/components/admin/repo/page.ts +++ b/src/components/admin/repo/page.ts @@ -10,7 +10,7 @@ export class PageRepo { public async listPages(branch: string = "master"): Promise { return await fetchWithToken(this.token, `/page?branch=${branch}`) .then(value => value.json()) - .then(value => PageListSchema.parse(value)) + .then(value => PageListSchema.parse(value).map(value1 => ({...value1, path: value1.path.replace("src/content/", "")}))) } public async getPage(id: number, branch: string = "master"): Promise { @@ -41,4 +41,8 @@ export class PageRepo { public async deleteBranch(branch: string): Promise { await fetchWithToken(this.token, `/page/branch`, {method: "DELETE", body: JSON.stringify({branch})}) } + + public async createFile(path: string, branch: string = "master"): Promise { + await fetchWithToken(this.token, `/page?branch=${branch}`, {method: "POST", body: JSON.stringify({path})}) + } } \ No newline at end of file diff --git a/src/components/admin/types/page.ts b/src/components/admin/types/page.ts index 4c7992a..bf08056 100644 --- a/src/components/admin/types/page.ts +++ b/src/components/admin/types/page.ts @@ -24,4 +24,9 @@ export const PageSchema = z.object({ id: z.number().positive() }) -export type Page = z.infer; \ No newline at end of file +export type Page = z.infer; + +export type Pages = { + dirs: {[key: string]: Pages}, + files: {[key: string]: ListPage} +} \ No newline at end of file diff --git a/src/content/src/content/pages/en/about.md b/src/content/src/content/pages/en/about.md deleted file mode 100644 index 2089477..0000000 --- a/src/content/src/content/pages/en/about.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: [Enter Title] -description: [Enter Description] -slug: [Enter Slug] ---- - -# src/content/pages/en/about.md \ No newline at end of file