mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
docs(ComponentExample): automatically read code (#789)
This commit is contained in:
19
docs/server/api/content-examples-code.get.ts
Normal file
19
docs/server/api/content-examples-code.get.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { defineEventHandler, createError, appendHeader } from 'h3'
|
||||
import { pascalCase } from 'scule'
|
||||
// @ts-expect-error
|
||||
import components from '#content-examples-code/nitro'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
appendHeader(event, 'Access-Control-Allow-Origin', '*')
|
||||
const componentName = (event.context.params['component?'] || '').replace(/\.json$/, '')
|
||||
if (componentName) {
|
||||
const component = components[pascalCase(componentName)]
|
||||
if (!component) {
|
||||
throw createError({
|
||||
statusMessage: 'Examples not found!',
|
||||
statusCode: 404
|
||||
})
|
||||
}
|
||||
return component
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user