Compare commits

..

No commits in common. "ddce0c8589cea696c89aa1e3c2bd27aaae29c2ad" and "794cc9adaba580afcb8f534c0d79a75b7fea4a02" have entirely different histories.

9 changed files with 8 additions and 60 deletions

View File

@ -12,7 +12,7 @@
`hype` wraps `hono` with useful features for fast prototyping:
- HTTP logging to the console (disable with `NO_HTTP_LOG` env variable)
- HTTP logging (disable with `NO_HTTP_LOG` env variable)
- Static files served from `pub/`
- Page-based routing to `.tsx` files that export a `JSX` function in `./src/pages`
- Transpile `.ts` files in `src/js/blah.ts` via `website.com/js/blah.ts`

View File

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

View File

@ -34,7 +34,3 @@ h1 {
background-position: 100% 50%;
}
}
ul {
list-style-type: none;
}

View File

@ -2,8 +2,6 @@ export function initBurger() {
document.addEventListener('click', ev => {
const el = (ev?.target as HTMLElement).closest('.burger') as HTMLImageElement
if (!el) return
el.src = el.src.endsWith('/img/burger.png') ? '/img/bite1.png' : '/img/bite2.png'
if (el) el.src = '/img/bite.png'
})
}

View File

@ -4,10 +4,6 @@ export default () => (
<h1>Hello, world!</h1>
<p>Welcome to <span class="hype">hype</span>!</p>
<p>If you're seeing this, something definitely went right.</p>
<ul>
<li><a href="/about">About This Website</a></li>
<li><a href="/js-test">JS Test</a></li>
</ul>
<a href="/about">About This Website</a>
</section>
)

View File

@ -1,11 +0,0 @@
import { frontend as fe } from 'hype'
fe(function test() {
alert('ding dong')
})
export default () => (
<section>
<a href="#" click="test()">test</a>
</section>
)

View File

@ -1,10 +0,0 @@
let funcs: string[] = []
// Designate a function in a .tsx file as frontend
export function frontend(code: Function) {
funcs.push(code.toString())
}
export function feFunctions(): string[] {
return funcs
}

View File

@ -6,14 +6,12 @@ import color from 'kleur'
import { transpile } from './utils'
import defaultLayout from './layout'
import { feFunctions } from './frontend'
const SHOW_HTTP_LOG = true
const CSS_RESET = await Bun.file(join(import.meta.dir, '/reset.css')).text()
const PICO_CSS = await Bun.file(join(import.meta.dir, '/pico.css')).text()
export * from './utils'
export { frontend } from './frontend'
export type HypeProps = {
pico?: boolean
@ -78,33 +76,14 @@ export class Hype<
this.use('*', async (c, next) => {
await next()
const contentType = c.res.headers.get('content-type')
if (!contentType?.includes('text/html')) return
const res = c.res.clone()
const html = await res.text()
const formatted = formatHTML(html)
c.res = new Response(formatted, c.res)
if (c.res.headers.get('content-type')?.includes('text/html')) {
const html = await c.res.text()
const formatted = formatHTML(html)
c.res = new Response(formatted, c.res)
}
})
}
// serve frontend js
this.use('*', async (c, next) => {
await next()
const contentType = c.res.headers.get('content-type')
if (!contentType?.includes('text/html')) return
const fns = feFunctions()
if (!fns.length) return
const res = c.res.clone()
const html = await res.text()
const newHtml = html.replace('</body>', `<script>${fns.join('\n')}</script></body>`)
c.res = new Response(newHtml, c.res)
})
// css reset
this.get('/css/reset.css', async c => new Response(CSS_RESET, { headers: { 'Content-Type': 'text/css' } }))