Compare commits

...

2 commits

2 changed files with 13 additions and 5 deletions

View file

@ -19,11 +19,9 @@ export const remarkInclude: Plugin<[], Root> = ({ resolveFrom }: { resolveFrom:
&& node.meta !== "options"))
return [node];
// !== "options" because those are special, parsed from options.json:
// TODO: temporarily !== "options" because those are special, parsed from options.json:
// https://github.com/NixOS/nixpkgs/blob/d31617bedffa3e5fe067feba1c68b1a7f644cb4f/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/manual.py#L81-L102
console.log("awa", node);
const includes = node.value.split("\n");
return includes.flatMap(included => {
@ -34,7 +32,7 @@ export const remarkInclude: Plugin<[], Root> = ({ resolveFrom }: { resolveFrom:
includeContents = readSync(includePath, "utf8");
} catch (err) {
throw new Error(
`The @include file path at ${includePath} was not found.\n\nInclude Location: ${file.path}:${node.position.start.line}:${node.position.start.column}`
`The {=include=} file path at ${includePath} was not found.\n\nInclude Location: ${file.path}:${node.position.start.line}:${node.position.start.column}`
);
}

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