From 10c84d2dce5c8d635746c03270bc08eeffdffd5e Mon Sep 17 00:00:00 2001 From: Endeavorance Date: Wed, 12 Mar 2025 17:07:19 -0400 Subject: [PATCH] Massive update to html rendering --- bun.lock | 10 ++++------ package.json | 2 +- src/index.ts | 14 ++++++++++---- src/lib/binding.ts | 10 ++++++++++ src/lib/markdown.ts | 22 ---------------------- 5 files changed, 25 insertions(+), 33 deletions(-) diff --git a/bun.lock b/bun.lock index 6a89811..fa42901 100644 --- a/bun.lock +++ b/bun.lock @@ -4,7 +4,7 @@ "": { "name": "@proscenium/muse", "dependencies": { - "@proscenium/playbill": "0.0.4", + "@proscenium/playbill": "link:@proscenium/playbill", "chalk": "^5.4.1", "lodash-es": "^4.17.21", "yaml": "^2.7.0", @@ -39,9 +39,9 @@ "@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@1.9.4", "", { "os": "win32", "cpu": "x64" }, "sha512-8Y5wMhVIPaWe6jw2H+KlEm4wP/f7EW3810ZLmDlrEEy5KvBsb9ECEfu/kMWD484ijfQ8+nIi0giMgu9g1UAuuA=="], - "@proscenium/playbill": ["@proscenium/playbill@0.0.4", "https://git.astral.camp/api/packages/proscenium/npm/%40proscenium%2Fplaybill/-/0.0.4/playbill-0.0.4.tgz", { "dependencies": { "lodash-es": "^4.17.21", "marked": "^15.0.7", "zod": "^3.24.2" } }, "sha512-0E+92ECdLMpOOWnZ4xOYiQ2TxDuEfB2MWC1LPrVrVpedr4ebDDbEzC+m7WjInQCH+y90YGArpuMPaGt6iN43ag=="], + "@proscenium/playbill": ["@proscenium/playbill@link:@proscenium/playbill", {}], - "@types/bun": ["@types/bun@1.2.4", "", { "dependencies": { "bun-types": "1.2.4" } }, "sha512-QtuV5OMR8/rdKJs213iwXDpfVvnskPXY/S0ZiFbsTjQZycuqPbMW8Gf/XhLfwE5njW8sxI2WjISURXPlHypMFA=="], + "@types/bun": ["@types/bun@1.2.5", "", { "dependencies": { "bun-types": "1.2.5" } }, "sha512-w2OZTzrZTVtbnJew1pdFmgV99H0/L+Pvw+z1P67HaR18MHOzYnTYOi6qzErhK8HyT+DB782ADVPPE92Xu2/Opg=="], "@types/lodash": ["@types/lodash@4.17.16", "", {}, "sha512-HX7Em5NYQAXKW+1T+FiuG27NGwzJfCX3s1GjOa7ujxZa52kjJLOr4FUxT+giF6Tgxv1e+/czV/iTtBw27WTU9g=="], @@ -51,14 +51,12 @@ "@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="], - "bun-types": ["bun-types@1.2.4", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-nDPymR207ZZEoWD4AavvEaa/KZe/qlrbMSchqpQwovPZCKc7pwMoENjEtHgMKaAjJhy+x6vfqSBA1QU3bJgs0Q=="], + "bun-types": ["bun-types@1.2.5", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-3oO6LVGGRRKI4kHINx5PIdIgnLRb7l/SprhzqXapmoYkFl5m4j6EvALvbDVuuBFaamB46Ap6HCUxIXNLCGy+tg=="], "chalk": ["chalk@5.4.1", "", {}, "sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w=="], "lodash-es": ["lodash-es@4.17.21", "", {}, "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw=="], - "marked": ["marked@15.0.7", "", { "bin": { "marked": "bin/marked.js" } }, "sha512-dgLIeKGLx5FwziAnsk4ONoGwHwGPJzselimvlVskE9XLN4Orv9u2VA3GWw/lYUqjfA0rUT/6fqKwfZJapP9BEg=="], - "typescript": ["typescript@5.8.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ=="], "undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="], diff --git a/package.json b/package.json index 70a332a..3597282 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "typescript": "^5.0.0" }, "dependencies": { - "@proscenium/playbill": "0.0.4", + "@proscenium/playbill": "link:@proscenium/playbill", "chalk": "^5.4.1", "lodash-es": "^4.17.21", "yaml": "^2.7.0", diff --git a/src/index.ts b/src/index.ts index 447c2bd..22bfb3b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -121,12 +121,18 @@ async function main(): Promise { for await (const event of watcher) { console.log(`Detected ${event.eventType} on ${event.filename}`); - lastProcessResult = await processBinding(cliArguments); - if (lastProcessResult === ExitCode.Error) { + try { + lastProcessResult = await processBinding(cliArguments); + + if (lastProcessResult === ExitCode.Error) { + console.error(`Error processing ${event.filename}`); + } else { + console.log("Reprocessed changes"); + } + } catch (error) { console.error(`Error processing ${event.filename}`); - } else { - console.log("Reprocessed changes"); + console.error(error); } } return ExitCode.Success; diff --git a/src/lib/binding.ts b/src/lib/binding.ts index b75de22..c1d52ff 100644 --- a/src/lib/binding.ts +++ b/src/lib/binding.ts @@ -1,5 +1,6 @@ import path from "node:path"; import { + IDSchema, PlaybillSchema, type Playbill, type UnknownResource, @@ -14,6 +15,12 @@ const HTMLRenderOptionsSchema = z.object({ styles: z.array(z.string()).optional(), }); +const PageDefinitionSchema = z.object({ + id: z.string(), + title: z.string(), + resources: z.array(IDSchema), +}); + const BindingFileSchema = z.object({ $binding: z.literal("playbill"), extends: z.string().optional(), @@ -25,6 +32,8 @@ const BindingFileSchema = z.object({ files: z.array(z.string()).default(["**/*.yaml", "**/*.md"]), html: HTMLRenderOptionsSchema.optional(), + + pages: PageDefinitionSchema.array().optional(), }); type BindingFileContent = z.infer; @@ -45,6 +54,7 @@ export interface PlaybillBinding { description: string; html?: z.infer; + pages?: z.infer[]; playbill: Playbill; } diff --git a/src/lib/markdown.ts b/src/lib/markdown.ts index ae3bd79..e5d7905 100644 --- a/src/lib/markdown.ts +++ b/src/lib/markdown.ts @@ -1,8 +1,3 @@ -import rehypeStringify from "rehype-stringify"; -import remarkGfm from "remark-gfm"; -import remarkParse from "remark-parse"; -import remarkRehype from "remark-rehype"; -import { unified } from "unified"; import YAML from "yaml"; const FRONTMATTER_REGEX = /^---[\s\S]*?---/gm; @@ -58,20 +53,3 @@ ${YAML.stringify(frontmatterToWrite)} ${markdown.trim()} `; } - -/** - * Given a string of markdown, convert it to HTML - * - * @param markdown The markdown to convert - * @returns A promise resolving to the HTML representation of the markdown - */ -export async function markdownToHtml(markdown: string): Promise { - const rendered = await unified() - .use(remarkParse) - .use(remarkGfm) - .use(remarkRehype) - .use(rehypeStringify) - .process(markdown); - - return String(rendered); -}