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 type { PageServerLoad } from "./$types";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { renderToHtml } from "$lib/docs";
|
import { renderToHtml } from "$lib/docs";
|
||||||
|
import { stat } from "fs/promises";
|
||||||
|
|
||||||
|
|
||||||
export const load: PageServerLoad = async (event) => {
|
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.
|
// we shouldn't need this, but it doesn't hurt.
|
||||||
if (userPath.split("/").find(c => /^\.*$/.test(c)))
|
if (userPath.split("/").find(c => /^\.*$/.test(c)))
|
||||||
throw new Error("url is sus");
|
throw new Error("url is sus");
|
||||||
|
|
||||||
const base = join(process.cwd(), ".petalpkgs");
|
const base = join(process.cwd(), ".petalpkgs");
|
||||||
|
|
||||||
|
{
|
||||||
|
const isFolder = await stat(join(base, userPath))
|
||||||
|
.then(f => f.isDirectory())
|
||||||
|
.catch(() => false);
|
||||||
|
|
||||||
|
if (isFolder) userPath += "/index";
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
html: await renderToHtml({ base, path: userPath })
|
html: await renderToHtml({ base, path: userPath })
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue