Skip to content

Commit

Permalink
🎉 feat: 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Dec 15, 2023
1 parent 371921b commit 080b406
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 85 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

# 0.8.0-rc.0 - 15 Dec 2023
Change:
- Add support for Elysia 0.8

# 0.7.1 - 8 Oct 2023
Improvement:
- [#19](https://github.com/elysiajs/elysia-html/pull/20) Update to Kita HTML v3
Expand Down
Binary file modified bun.lockb
Binary file not shown.
20 changes: 14 additions & 6 deletions example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,20 @@ const indexSchema = {
})
}

new Elysia()
const app = new Elysia()
// https://elysiajs.com/plugins/html.html#options
.use(html())
.get('/', ({ query }) => page(query), indexSchema)
.get('/tsx', ({ query }) => <TsxPage name={query.name} />, indexSchema)
.get('/async', ({ query, stream }) => stream(<AsyncPage name={query.name} />, query), indexSchema)
.use(html({
autoDetect: true
}))
.get('/', ({ html }) => html('<h1>Hello World!</h1>')
)
// .get('/', ({ query }) => page(query), indexSchema)
// .get('/tsx', ({ query }) => <TsxPage name={query.name} />, indexSchema)
// .get('/async', ({ query, stream }) => stream(<AsyncPage name={query.name} />, query), indexSchema)
.listen(8080, () => console.log('Listening on http://localhost:8080'))


app.handle(new Request('http://localhost:8080/'))
.then((x) => x.text())
.then(console.log)

console.log(app.routes[0]?.composed?.toString())
13 changes: 10 additions & 3 deletions example/simple.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Elysia } from 'elysia'
import { html } from '../src'

new Elysia()
.use(html())
.get('/0.7', () => <h1>Hello World</h1>)
const app = new Elysia()
.use(html({ autoDetect: true }))
.get('/a', ({ html }) => html(`<h1>Hello World</h1>`))
.compile()

console.log(app.routes[0]?.composed?.toString())

app.handle(new Request('http://localhost:8080/a'))
.then((x) => x.text())
.then(console.log)
144 changes: 72 additions & 72 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
{
"name": "@elysiajs/html",
"version": "0.8.0-rc.1",
"description": "Plugin for Elysia that add support for returning html",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
"email": "[email protected]"
"name": "@elysiajs/html",
"version": "0.8.0-rc.0",
"description": "Plugin for Elysia that add support for returning html",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
"email": "[email protected]"
},
"main": "./dist/index.js",
"exports": {
".": {
"bun": "./dist/index.js",
"node": "./dist/cjs/index.js",
"require": "./dist/cjs/index.js",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"main": "./dist/index.js",
"exports": {
".": {
"bun": "./dist/index.js",
"node": "./dist/cjs/index.js",
"require": "./dist/cjs/index.js",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"./htmx": {
"bun": "./dist/html.js",
"node": "./dist/cjs/htmx.js",
"require": "./dist/cjs/htmx.js",
"import": "./dist/htmx.js",
"default": "./dist/htmx.js"
},
"./hotwire": {
"bun": "./dist/hotwire.js",
"node": "./dist/cjs/hotwire.js",
"require": "./dist/cjs/hotwire.js",
"import": "./dist/hotwire.js",
"default": "./dist/hotwire.js"
}
"./htmx": {
"bun": "./dist/html.js",
"node": "./dist/cjs/htmx.js",
"require": "./dist/cjs/htmx.js",
"import": "./dist/htmx.js",
"default": "./dist/htmx.js"
},
"types": "./src/index.ts",
"keywords": [
"elysia",
"html"
],
"homepage": "https://github.com/elysiajs/elysia-html",
"repository": {
"type": "git",
"url": "https://github.com/elysiajs/elysia-html"
},
"bugs": "https://github.com/elysiajs/elysia-html/issues",
"license": "MIT",
"scripts": {
"dev": "bun run --watch example/index.tsx",
"test": "bun test && npm run test:node",
"test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
"release": "npm run build && npm run test && npm publish --access public",
"format": "prettier --write ."
},
"peerDependencies": {
"elysia": ">= 0.8.0-rc.0"
},
"devDependencies": {
"@elysiajs/stream": "^0.7.2",
"@types/node": "^20.7.2",
"bun-types": "^1.0.3",
"elysia": "0.8.0-rc.0",
"eslint": "^8.50.0",
"rimraf": "^5.0.5",
"typescript": "^5.2.2"
},
"dependencies": {
"@kitajs/html": "^3.0.2",
"@kitajs/ts-html-plugin": "^1.2.0"
"./hotwire": {
"bun": "./dist/hotwire.js",
"node": "./dist/cjs/hotwire.js",
"require": "./dist/cjs/hotwire.js",
"import": "./dist/hotwire.js",
"default": "./dist/hotwire.js"
}
},
"types": "./src/index.ts",
"keywords": [
"elysia",
"html"
],
"homepage": "https://github.com/elysiajs/elysia-html",
"repository": {
"type": "git",
"url": "https://github.com/elysiajs/elysia-html"
},
"bugs": "https://github.com/elysiajs/elysia-html/issues",
"license": "MIT",
"scripts": {
"dev": "bun run --watch example/index.tsx",
"test": "bun test && npm run test:node",
"test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
"release": "npm run build && npm run test && npm publish --access public",
"format": "prettier --write ."
},
"peerDependencies": {
"elysia": ">= 0.8.0-rc.0"
},
"devDependencies": {
"@elysiajs/stream": "^0.7.2",
"@types/node": "^20.7.2",
"bun-types": "^1.0.3",
"elysia": "0.8.0-rc.2",
"eslint": "^8.50.0",
"rimraf": "^5.0.5",
"typescript": "^5.2.2"
},
"dependencies": {
"@kitajs/html": "^3.0.2",
"@kitajs/ts-html-plugin": "^1.2.0"
},
"peerDependenciesMeta": {
"@kitajs/html": {
"optional": true
},
"peerDependenciesMeta": {
"@kitajs/html": {
"optional": true
},
"@kitajs/ts-html-plugin": {
"optional": true
}
"@kitajs/ts-html-plugin": {
"optional": true
}
}
}
3 changes: 1 addition & 2 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ export function handleHtml(
isHtml(value) &&
// Avoids double adding !doctype or adding to non root html tags.
isTagHtml(value)
) {
)
value = '<!doctype html>' + value
}

return new Response(
value,
Expand Down
2 changes: 2 additions & 0 deletions src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export function html(options: HtmlOptions = {}) {

if (response instanceof Response) return response

set.headers['content-type'] = options.contentType!

return new Response(response)
}

Expand Down
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* @see https://stackoverflow.com/q/11229831
*/
export function isHtml(this: void, value?: any): value is string {
if (typeof value !== 'string') {
if (typeof value !== 'string')
return false
}

value = value.trim()
const length = value.length
Expand Down

0 comments on commit 080b406

Please sign in to comment.