feat($lib/docs): introduce new docs pipeline #8

Merged
ckie merged 7 commits from ckie/init/docs into main 2024-11-24 00:29:14 +00:00
Showing only changes of commit b39a017918 - Show all commits

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 })
};