From 864adfa02658ca14a3370947b415162472d73f0f Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Sun, 30 Nov 2025 12:20:10 -0800 Subject: [PATCH] prettyHTML --- src/index.tsx | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index de48bbb..8ba2038 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -16,6 +16,7 @@ export * from './utils' export type HypeProps = { pico?: boolean reset?: boolean + prettyHTML?: boolean } export class Hype< @@ -23,16 +24,13 @@ export class Hype< S extends Schema = {}, BasePath extends string = '/' > extends Hono { - props?: HypeProps + props: HypeProps routesRegistered = false constructor(props?: HypeProps & ConstructorParameters>[0]) { super(props) - if (props) { - const { pico, reset } = props - this.props = { pico, reset } - } + this.props = props ?? {} } registerRoutes() { @@ -74,16 +72,16 @@ export class Hype< }) // prettify HTML output - if (process.env.NODE_ENV !== 'production') { + if (this.props.prettyHTML ?? process.env.NODE_ENV !== 'production') { this.use('*', async (c, next) => { - await next(); + await next() if (c.res.headers.get('content-type')?.includes('text/html')) { - const html = await c.res.text(); - const formatted = await prettier.format(html, { parser: 'html' }); - c.res = new Response(formatted, c.res); + const html = await c.res.text() + const formatted = await prettier.format(html, { parser: 'html' }) + c.res = new Response(formatted, c.res) } - }); + }) } // css reset @@ -114,6 +112,7 @@ export class Hype< const pageName = (c.req.param('page') ?? 'index').replace('.', '') if (pageName.startsWith('_')) return render404(c) + console.log(process.env.PWD) const path = join(process.env.PWD ?? '.', `./src/pages/${pageName}.tsx`) if (!(await Bun.file(path).exists()))