feat: Support implicit index.md in /docs/petal/…/folder
This commit is contained in:
parent
f8db23ad7d
commit
b39a017918
|
@ -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 })
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue