feat: Support implicit index.md in /docs/petal/…/folder

This commit is contained in:
mei (ckie) 2024-11-24 02:14:39 +02:00
parent f8db23ad7d
commit b39a017918
Signed by: ckie
GPG key ID: 13E79449C0525215

View file

@ -1,15 +1,25 @@
import type { PageServerLoad } from "./$types";
import { join } from "path";
import { renderToHtml } from "$lib/docs";
import { stat } from "fs/promises";
export const load: PageServerLoad = async (event) => {
const userPath = event.params.rest;
let userPath = event.params.rest;
// we shouldn't need this, but it doesn't hurt.
if (userPath.split("/").find(c => /^\.*$/.test(c)))
throw new Error("url is sus");
const base = join(process.cwd(), ".petalpkgs");
{
const isFolder = await stat(join(base, userPath))
.then(f => f.isDirectory())
.catch(() => false);
if (isFolder) userPath += "/index";
}
return {
html: await renderToHtml({ base, path: userPath })
};