Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update h3 usage #1603

Merged
merged 1 commit into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions playground/shared/server/api/parse.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineEventHandler, useBody } from 'h3'
import { defineEventHandler, readBody } from 'h3'
import { parseContent } from '#content/server'

export default defineEventHandler(async (event) => {
const body = await useBody(event)
const body = await readBody(event)

// @ts-ignore
const parsedContent = await parseContent(body.id || 'content:_file.md', body.content)
Expand Down
10 changes: 5 additions & 5 deletions src/runtime/server/api/highlight.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { /* createError, */defineLazyEventHandler, useBody } from 'h3'
import { /* createError, */defineEventHandler, readBody, lazyEventHandler } from 'h3'
import { getHighlighter, BUNDLED_LANGUAGES, BUNDLED_THEMES, Lang, Theme } from 'shiki-es'
import consola from 'consola'
import { HighlightParams, HighlightThemedToken } from '../../types'
Expand Down Expand Up @@ -57,7 +57,7 @@ const resolveBody = (body: Partial<HighlightParams>) => {
}
}

export default defineLazyEventHandler(async () => {
export default lazyEventHandler(async () => {
// Grab highlighter config from publicRuntimeConfig
const { theme, preload } = useRuntimeConfig().content.highlight

Expand Down Expand Up @@ -85,8 +85,8 @@ export default defineLazyEventHandler(async () => {
] as any[]
})

return async (event): Promise<HighlightThemedToken[][]> => {
const params = await useBody<Partial<HighlightParams>>(event)
return defineEventHandler(async (event): Promise<HighlightThemedToken[][]> => {
const params = await readBody<Partial<HighlightParams>>(event)

const { code, lang, theme = { default: highlighter.getTheme() } } = resolveBody(params)

Expand Down Expand Up @@ -142,7 +142,7 @@ export default defineLazyEventHandler(async () => {
}

return highlightedCode
}
})
})

interface HighlightThemedTokenLine {
Expand Down