Compare commits
No commits in common. "30c1f4b894b7dc5f693c7a96d2d660bdc55c2402" and "441713675a216bfa3a8e11cda86f2bc2da088a5d" have entirely different histories.
30c1f4b894
...
441713675a
|
|
@ -128,8 +128,6 @@ export default () => (
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
Install the `vscode-styled-components` VSCode extension to highlight inline `css` tags!
|
|
||||||
|
|
||||||
### css reset
|
### css reset
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -180,8 +178,6 @@ export default () => (
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
Install the `vscode-styled-components` VSCode extension to highlight inline `js` tags!
|
|
||||||
|
|
||||||
### pub
|
### pub
|
||||||
|
|
||||||
Anything in `pub/` is served as-is. Simple stuff.
|
Anything in `pub/` is served as-is. Simple stuff.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import prettier from 'prettier'
|
import prettier from 'prettier'
|
||||||
import { type Context, Hono, type Schema, type Env } from 'hono'
|
import { type Context, Hono } from 'hono'
|
||||||
import { serveStatic } from 'hono/bun'
|
import { serveStatic } from 'hono/bun'
|
||||||
import color from 'kleur'
|
import color from 'kleur'
|
||||||
|
|
||||||
|
|
@ -18,21 +18,14 @@ export type HypeProps = {
|
||||||
reset?: boolean
|
reset?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Hype<
|
export class Hype extends Hono {
|
||||||
E extends Env = Env,
|
|
||||||
S extends Schema = {},
|
|
||||||
BasePath extends string = '/'
|
|
||||||
> extends Hono<E, S, BasePath> {
|
|
||||||
props?: HypeProps
|
|
||||||
routesRegistered = false
|
routesRegistered = false
|
||||||
|
props: HypeProps = {}
|
||||||
|
|
||||||
constructor(props?: HypeProps & ConstructorParameters<typeof Hono<E, S, BasePath>>[0]) {
|
constructor(props?: HypeProps) {
|
||||||
super(props)
|
super()
|
||||||
|
|
||||||
if (props) {
|
if (props) this.props = props
|
||||||
const { pico, reset } = props
|
|
||||||
this.props = { pico, reset }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerRoutes() {
|
registerRoutes() {
|
||||||
|
|
@ -57,22 +50,6 @@ export class Hype<
|
||||||
console.log(fn(`${c.res.status}`), `${color.bold(method)} ${c.req.url} (${end - start}ms)`)
|
console.log(fn(`${c.res.status}`), `${color.bold(method)} ${c.req.url} (${end - start}ms)`)
|
||||||
})
|
})
|
||||||
|
|
||||||
// exception handler
|
|
||||||
this.onError((err, c) => {
|
|
||||||
const isDev = process.env.NODE_ENV !== 'production'
|
|
||||||
|
|
||||||
return c.html(
|
|
||||||
`<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<h1>Error: ${err.message}</h1>
|
|
||||||
${isDev ? `<pre>${err.stack}</pre>` : '<p>An error occurred</p>'}
|
|
||||||
</body>
|
|
||||||
</html>`,
|
|
||||||
500
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
// prettify HTML output
|
// prettify HTML output
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
this.use('*', async (c, next) => {
|
this.use('*', async (c, next) => {
|
||||||
|
|
@ -125,7 +102,7 @@ export class Hype<
|
||||||
Layout = (await import(layoutPath + `?t=${Date.now()}`)).default
|
Layout = (await import(layoutPath + `?t=${Date.now()}`)).default
|
||||||
|
|
||||||
const page = await import(path + `?t=${Date.now()}`)
|
const page = await import(path + `?t=${Date.now()}`)
|
||||||
const innerHTML = typeof page.default === 'function' ? <page.default c={c} req={c.req} /> : page.default
|
const innerHTML = typeof page.default === 'function' ? <page.default req={c.req} /> : page.default
|
||||||
const withLayout = Layout ? <Layout props={this.props}>{innerHTML}</Layout> : innerHTML
|
const withLayout = Layout ? <Layout props={this.props}>{innerHTML}</Layout> : innerHTML
|
||||||
return c.html(withLayout)
|
return c.html(withLayout)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -105,19 +105,6 @@ export function unique<T>(array: T[]): T[] {
|
||||||
return [...new Set(array)]
|
return [...new Set(array)]
|
||||||
}
|
}
|
||||||
|
|
||||||
// shuffle a copy of an array
|
|
||||||
export function shuffle<T>(arr: readonly T[]): T[] {
|
|
||||||
const out = arr.slice()
|
|
||||||
for (let i = out.length - 1; i > 0; i--) {
|
|
||||||
const j = Math.floor(Math.random() * (i + 1))
|
|
||||||
|
|
||||||
const tmp = out[i]!
|
|
||||||
out[i] = out[j]!
|
|
||||||
out[j] = tmp
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// random number between 1 and 10, with decreasing probability
|
// random number between 1 and 10, with decreasing probability
|
||||||
export function weightedRand(): number {
|
export function weightedRand(): number {
|
||||||
// Weights: 1 has weight 10, 2 has weight 9, ..., 10 has weight 1
|
// Weights: 1 has weight 10, 2 has weight 9, ..., 10 has weight 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user