Dieser Commit ist enthalten in:
Chaoscaot 2023-10-08 15:08:39 +02:00
Ursprung 17d46c3964
Commit e65a70aa40
4 geänderte Dateien mit 26 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -3,11 +3,12 @@ import {ArrowLeftSolid} from "flowbite-svelte-icons";
import {Button, Card, Input, Label, Navbar, NavBrand, NavHamburger, NavUl, Spinner} from "flowbite-svelte"; import {Button, Card, Input, Label, Navbar, NavBrand, NavHamburger, NavUl, Spinner} from "flowbite-svelte";
import {pageRepo} from "../repo/repo.js"; import {pageRepo} from "../repo/repo.js";
import {mapToMap, nameRegex} from "../util.ts"; import {mapToMap, nameRegex} from "../util.ts";
import Editor from "./edit/Editor.svelte";
import TypeAheadSearch from "../components/TypeAheadSearch.svelte"; import TypeAheadSearch from "../components/TypeAheadSearch.svelte";
import {branches} from "../stores/stores.ts"; 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 selected: number | null = null;
let selectedBranch: string = "master"; 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
}
}
</script> </script>
<div class="flex flex-col h-screen overflow-scroll"> <div class="flex flex-col h-screen overflow-scroll">
<Navbar let:hidden let:toggle> <Navbar let:hidden let:toggle>
@ -73,8 +84,9 @@ async function deleteBranch() {
<div class="border-b border-b-gray-600 pb-2 flex justify-between"> <div class="border-b border-b-gray-600 pb-2 flex justify-between">
<TypeAheadSearch items={availableBranches} bind:selected={selectedBranch} bind:searchValue /> <TypeAheadSearch items={availableBranches} bind:selected={selectedBranch} bind:searchValue />
<div> <div>
<Button on:click={deleteBranch} color="ghost">Delete Branch</Button>
<Button on:click={createBranch}>Create Branch</Button> <Button on:click={createBranch}>Create Branch</Button>
<Button on:click={createFile} color="alternative">Create File</Button>
<Button on:click={deleteBranch} color="ghost">Delete Branch</Button>
</div> </div>
</div> </div>
{@const pagesMap = mapToMap(pages)} {@const pagesMap = mapToMap(pages)}

Datei anzeigen

@ -10,7 +10,7 @@ export class PageRepo {
public async listPages(branch: string = "master"): Promise<PageList> { public async listPages(branch: string = "master"): Promise<PageList> {
return await fetchWithToken(this.token, `/page?branch=${branch}`) return await fetchWithToken(this.token, `/page?branch=${branch}`)
.then(value => value.json()) .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<Page> { public async getPage(id: number, branch: string = "master"): Promise<Page> {
@ -41,4 +41,8 @@ export class PageRepo {
public async deleteBranch(branch: string): Promise<void> { public async deleteBranch(branch: string): Promise<void> {
await fetchWithToken(this.token, `/page/branch`, {method: "DELETE", body: JSON.stringify({branch})}) await fetchWithToken(this.token, `/page/branch`, {method: "DELETE", body: JSON.stringify({branch})})
} }
public async createFile(path: string, branch: string = "master"): Promise<void> {
await fetchWithToken(this.token, `/page?branch=${branch}`, {method: "POST", body: JSON.stringify({path})})
}
} }

Datei anzeigen

@ -24,4 +24,9 @@ export const PageSchema = z.object({
id: z.number().positive() id: z.number().positive()
}) })
export type Page = z.infer<typeof PageSchema>; export type Page = z.infer<typeof PageSchema>;
export type Pages = {
dirs: {[key: string]: Pages},
files: {[key: string]: ListPage}
}

Datei anzeigen

@ -1,7 +0,0 @@
---
title: [Enter Title]
description: [Enter Description]
slug: [Enter Slug]
---
# src/content/pages/en/about.md