implemented page view for freely available wiki pages

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-09-19 20:45:54 +02:00
parent 93124a9a8c
commit 60d116664b
3 changed files with 62 additions and 4 deletions

View File

@@ -0,0 +1,51 @@
<script>
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte';
import { t } from '../../translations.svelte';
let { key } = $props();
let error = $state(null);
let page = $state(null);
let router = useTinyRouter();
async function loadContent(res){
if (res.ok){
page = null;
page = await res.json();
error = null;
return true;
} else {
error = await res.text();
return false;
}
}
async function loadPage(){
const url = api(`wiki/page/${key}`);
const res = await fetch(url,{credentials:'include'});
loadContent(res);
}
function onclick(e){
e.preventDefault();
let href = e.target.getAttribute('href');
if (href) router.navigate(href);
return false;
}
$effect(loadPage);
</script>
{#if error}
<span class="error">{error}</span>
{/if}
{#if page}
<div class="wiki page">
<h2>{page.title}</h2>
<div class="markdown">
{@html page.content.rendered}
</div>
</div>
{/if}