diff --git a/README.md b/README.md index f06d19b..95913db 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,14 @@ The `req` JSX prop will be given the `Hono` request: export default ({ req }) => `Query Param 'id': ${req.query('id')}` -If `_layout.tsx` exists, your pages will automatically be wrapped in it: +To put a file in `./src/pages` but prevent it from being server, preface it with `_`. + +### Layout + +`hype` will wrap everything in a simple default layout unless `./src/pages/_layout.tsx` exists, +in which case it'll use the default export in that file. + +Here's a starting point: ```tsx export default ({ children, title }: any) => ( @@ -73,8 +80,6 @@ export default ({ children, title }: any) => ( ) ``` -(Files starting with `_` don't get served directly.) - ### css CSS can be accessed via `/css/main.css`: diff --git a/src/index.tsx b/src/index.tsx index 06953e2..bdbe3be 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -4,6 +4,7 @@ import { serveStatic } from 'hono/bun' import color from 'kleur' import { transpile } from './utils' +import defaultLayout from './layout' const SHOW_HTTP_LOG = true const CSS_RESET = await Bun.file(join(import.meta.dir, '/reset.css')).text() @@ -70,7 +71,7 @@ export class Hype extends Hono { return render404(c) const layoutPath = join(process.env.PWD ?? '.', `./src/pages/_layout.tsx`) - let Layout + let Layout = defaultLayout if (await Bun.file(layoutPath).exists()) Layout = (await import(layoutPath + `?t=${Date.now()}`)).default diff --git a/src/layout.tsx b/src/layout.tsx new file mode 100644 index 0000000..e104605 --- /dev/null +++ b/src/layout.tsx @@ -0,0 +1,20 @@ +import { type FC } from 'hono/jsx' + +const Layout: FC = ({ children, title }) => + + + {title ?? 'hype'} + + + + + + + +
+ {children} +
+ + + +export default Layout