feat: static documentation pages

This commit is contained in:
sam 2024-12-25 17:53:31 -05:00
parent fe1cf7ce8a
commit 7468aa20ab
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
6 changed files with 58 additions and 7 deletions

View file

@ -7,11 +7,7 @@ const md = new MarkdownIt({
linkify: true,
}).disable(["heading", "lheading", "link", "table", "blockquote"]);
const unsafeMd = new MarkdownIt({
html: false,
breaks: true,
linkify: true,
});
const unsafeMd = new MarkdownIt();
export const renderMarkdown = (src: string | null) => (src ? sanitize(md.render(src)) : null);

View file

@ -0,0 +1,14 @@
import { baseRequest } from "$api";
import ApiError from "$api/error";
export const load = async ({ fetch, params }) => {
const resp = await baseRequest("GET", `/meta/page/${params.page}`, { fetch });
if (resp.status < 200 || resp.status > 299) {
const err = await resp.json();
if ("code" in err) throw new ApiError(err);
else throw new ApiError();
}
const pageText = await resp.text();
return { page: params.page, text: pageText };
};

View file

@ -0,0 +1,22 @@
<script lang="ts">
import { renderUnsafeMarkdown } from "$lib/markdown";
import type { PageData } from "./$types";
type Props = { data: PageData };
let { data }: Props = $props();
let md = $derived(renderUnsafeMarkdown(data.text));
let title = $derived.by(() => {
let title = data.text.split("\n")[0];
if (title.startsWith("# ")) title = title.substring("# ".length);
return title;
});
</script>
<svelte:head>
<title>{title} • pronouns.cc</title>
</svelte:head>
<div class="container">
{@html md}
</div>