Skip to content

Commit 080b406

Browse files
committed
🎉 feat: 0.8
1 parent 371921b commit 080b406

File tree

8 files changed

+105
-85
lines changed

8 files changed

+105
-85
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2+
# 0.8.0-rc.0 - 15 Dec 2023
3+
Change:
4+
- Add support for Elysia 0.8
5+
16
# 0.7.1 - 8 Oct 2023
27
Improvement:
38
- [#19](https://github.com/elysiajs/elysia-html/pull/20) Update to Kita HTML v3

bun.lockb

-8.93 KB
Binary file not shown.

example/index.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,20 @@ const indexSchema = {
5858
})
5959
}
6060

61-
new Elysia()
61+
const app = new Elysia()
6262
// https://elysiajs.com/plugins/html.html#options
63-
.use(html())
64-
.get('/', ({ query }) => page(query), indexSchema)
65-
.get('/tsx', ({ query }) => <TsxPage name={query.name} />, indexSchema)
66-
.get('/async', ({ query, stream }) => stream(<AsyncPage name={query.name} />, query), indexSchema)
63+
.use(html({
64+
autoDetect: true
65+
}))
66+
.get('/', ({ html }) => html('<h1>Hello World!</h1>')
67+
)
68+
// .get('/', ({ query }) => page(query), indexSchema)
69+
// .get('/tsx', ({ query }) => <TsxPage name={query.name} />, indexSchema)
70+
// .get('/async', ({ query, stream }) => stream(<AsyncPage name={query.name} />, query), indexSchema)
6771
.listen(8080, () => console.log('Listening on http://localhost:8080'))
6872

69-
73+
app.handle(new Request('http://localhost:8080/'))
74+
.then((x) => x.text())
75+
.then(console.log)
76+
77+
console.log(app.routes[0]?.composed?.toString())

example/simple.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { Elysia } from 'elysia'
22
import { html } from '../src'
33

4-
new Elysia()
5-
.use(html())
6-
.get('/0.7', () => <h1>Hello World</h1>)
4+
const app = new Elysia()
5+
.use(html({ autoDetect: true }))
6+
.get('/a', ({ html }) => html(`<h1>Hello World</h1>`))
7+
.compile()
8+
9+
console.log(app.routes[0]?.composed?.toString())
10+
11+
app.handle(new Request('http://localhost:8080/a'))
12+
.then((x) => x.text())
13+
.then(console.log)

package.json

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
11
{
2-
"name": "@elysiajs/html",
3-
"version": "0.8.0-rc.1",
4-
"description": "Plugin for Elysia that add support for returning html",
5-
"author": {
6-
"name": "saltyAom",
7-
"url": "https://github.com/SaltyAom",
8-
"email": "saltyaom@gmail.com"
2+
"name": "@elysiajs/html",
3+
"version": "0.8.0-rc.0",
4+
"description": "Plugin for Elysia that add support for returning html",
5+
"author": {
6+
"name": "saltyAom",
7+
"url": "https://github.com/SaltyAom",
8+
"email": "saltyaom@gmail.com"
9+
},
10+
"main": "./dist/index.js",
11+
"exports": {
12+
".": {
13+
"bun": "./dist/index.js",
14+
"node": "./dist/cjs/index.js",
15+
"require": "./dist/cjs/index.js",
16+
"import": "./dist/index.js",
17+
"default": "./dist/index.js"
918
},
10-
"main": "./dist/index.js",
11-
"exports": {
12-
".": {
13-
"bun": "./dist/index.js",
14-
"node": "./dist/cjs/index.js",
15-
"require": "./dist/cjs/index.js",
16-
"import": "./dist/index.js",
17-
"default": "./dist/index.js"
18-
},
19-
"./htmx": {
20-
"bun": "./dist/html.js",
21-
"node": "./dist/cjs/htmx.js",
22-
"require": "./dist/cjs/htmx.js",
23-
"import": "./dist/htmx.js",
24-
"default": "./dist/htmx.js"
25-
},
26-
"./hotwire": {
27-
"bun": "./dist/hotwire.js",
28-
"node": "./dist/cjs/hotwire.js",
29-
"require": "./dist/cjs/hotwire.js",
30-
"import": "./dist/hotwire.js",
31-
"default": "./dist/hotwire.js"
32-
}
19+
"./htmx": {
20+
"bun": "./dist/html.js",
21+
"node": "./dist/cjs/htmx.js",
22+
"require": "./dist/cjs/htmx.js",
23+
"import": "./dist/htmx.js",
24+
"default": "./dist/htmx.js"
3325
},
34-
"types": "./src/index.ts",
35-
"keywords": [
36-
"elysia",
37-
"html"
38-
],
39-
"homepage": "https://github.com/elysiajs/elysia-html",
40-
"repository": {
41-
"type": "git",
42-
"url": "https://github.com/elysiajs/elysia-html"
43-
},
44-
"bugs": "https://github.com/elysiajs/elysia-html/issues",
45-
"license": "MIT",
46-
"scripts": {
47-
"dev": "bun run --watch example/index.tsx",
48-
"test": "bun test && npm run test:node",
49-
"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",
50-
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
51-
"release": "npm run build && npm run test && npm publish --access public",
52-
"format": "prettier --write ."
53-
},
54-
"peerDependencies": {
55-
"elysia": ">= 0.8.0-rc.0"
56-
},
57-
"devDependencies": {
58-
"@elysiajs/stream": "^0.7.2",
59-
"@types/node": "^20.7.2",
60-
"bun-types": "^1.0.3",
61-
"elysia": "0.8.0-rc.0",
62-
"eslint": "^8.50.0",
63-
"rimraf": "^5.0.5",
64-
"typescript": "^5.2.2"
65-
},
66-
"dependencies": {
67-
"@kitajs/html": "^3.0.2",
68-
"@kitajs/ts-html-plugin": "^1.2.0"
26+
"./hotwire": {
27+
"bun": "./dist/hotwire.js",
28+
"node": "./dist/cjs/hotwire.js",
29+
"require": "./dist/cjs/hotwire.js",
30+
"import": "./dist/hotwire.js",
31+
"default": "./dist/hotwire.js"
32+
}
33+
},
34+
"types": "./src/index.ts",
35+
"keywords": [
36+
"elysia",
37+
"html"
38+
],
39+
"homepage": "https://github.com/elysiajs/elysia-html",
40+
"repository": {
41+
"type": "git",
42+
"url": "https://github.com/elysiajs/elysia-html"
43+
},
44+
"bugs": "https://github.com/elysiajs/elysia-html/issues",
45+
"license": "MIT",
46+
"scripts": {
47+
"dev": "bun run --watch example/index.tsx",
48+
"test": "bun test && npm run test:node",
49+
"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",
50+
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
51+
"release": "npm run build && npm run test && npm publish --access public",
52+
"format": "prettier --write ."
53+
},
54+
"peerDependencies": {
55+
"elysia": ">= 0.8.0-rc.0"
56+
},
57+
"devDependencies": {
58+
"@elysiajs/stream": "^0.7.2",
59+
"@types/node": "^20.7.2",
60+
"bun-types": "^1.0.3",
61+
"elysia": "0.8.0-rc.2",
62+
"eslint": "^8.50.0",
63+
"rimraf": "^5.0.5",
64+
"typescript": "^5.2.2"
65+
},
66+
"dependencies": {
67+
"@kitajs/html": "^3.0.2",
68+
"@kitajs/ts-html-plugin": "^1.2.0"
69+
},
70+
"peerDependenciesMeta": {
71+
"@kitajs/html": {
72+
"optional": true
6973
},
70-
"peerDependenciesMeta": {
71-
"@kitajs/html": {
72-
"optional": true
73-
},
74-
"@kitajs/ts-html-plugin": {
75-
"optional": true
76-
}
74+
"@kitajs/ts-html-plugin": {
75+
"optional": true
7776
}
77+
}
7878
}

src/handler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ export function handleHtml(
1919
isHtml(value) &&
2020
// Avoids double adding !doctype or adding to non root html tags.
2121
isTagHtml(value)
22-
) {
22+
)
2323
value = '<!doctype html>' + value
24-
}
2524

2625
return new Response(
2726
value,

src/html.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export function html(options: HtmlOptions = {}) {
5757

5858
if (response instanceof Response) return response
5959

60+
set.headers['content-type'] = options.contentType!
61+
6062
return new Response(response)
6163
}
6264

src/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
* @see https://stackoverflow.com/q/11229831
66
*/
77
export function isHtml(this: void, value?: any): value is string {
8-
if (typeof value !== 'string') {
8+
if (typeof value !== 'string')
99
return false
10-
}
1110

1211
value = value.trim()
1312
const length = value.length

0 commit comments

Comments
 (0)