Skip to content

Commit 5012a08

Browse files
committed
docs: api/file.get.ts
1 parent befc7ed commit 5012a08

File tree

7 files changed

+79
-47
lines changed

7 files changed

+79
-47
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"pnpm": "^7.13.2",
2828
"sass": "^1.55.0",
2929
"typescript": "^4.7.4",
30-
"vite": "^3.1.6",
30+
"vite": "^3.2.2",
3131
"vue-tsc": "^1.0.9"
3232
}
3333
}

packages/docs/components/content/CodeBlockFile.vue

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,15 @@ const props = defineProps<{
99
filename?: string
1010
}>()
1111
12-
// const modules = import.meta.glob('./*.vue', { as: 'raw' })
13-
14-
const modules = {
15-
'./Playground.vue': await import('./Playground.vue?raw'),
16-
}
12+
const { data } = await useFetch(`/api/file?path=${props.path}`)
13+
const content = prepareContent((data.value as any).content)
1714
1815
// console.log('modules → ', modules)
1916
2017
function prepareContent(content: string) {
2118
return `\`\`\`${props.language || ''}${props.filename ? ` [${props.filename}]` : ''}\n${content}\n\`\`\``
2219
}
2320
24-
const module = modules[props.path]
25-
if (!module)
26-
console.error('Component Not Found.')
27-
28-
// const content = prepareContent(await module() as any)
29-
const content = prepareContent(module.default as any)
30-
31-
// console.log(content)
32-
3321
const shiki = await useShiki()
3422
3523
const { data: doc } = await useAsyncData(`playground-${content}`, async () => {

packages/docs/components/content/Playground.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
2-
import type { TeleportProps, TransitionProps } from 'vue'
3-
import { ModalsContainer, VueFinalModal, useModal } from 'vue-final-modal'
2+
import type { TransitionProps } from 'vue'
3+
import { ModalsContainer, VueFinalModal } from 'vue-final-modal'
44
55
const initValues = {
66
teleportTo: 'body',

packages/docs/content/4.use-cases/1.playground.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@ head.title: 'Playground | Examples'
88
::code-block{label="Preview" preview}
99
:playground
1010
::
11-
12-
::code-block{label="Playground.vue"}
13-
:code-block-file{path="./Playground.vue" language="vue"}
14-
::
1511
::

packages/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
},
4141
"devDependencies": {
4242
"@nuxt-themes/docus": "npm:@nuxt-themes/docus-edge@latest",
43-
"@nuxt/content": "^2.1.1",
43+
"@nuxt/content": "^2.2.1",
4444
"monaco-editor-core": "^0.34.1",
4545
"nuxt": "3.0.0-rc.12"
4646
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import path from 'path'
2+
import fs from 'node:fs'
3+
4+
export default defineEventHandler(async (event) => {
5+
const query = getQuery(event)
6+
const _path = path.resolve(`./components/content/${query.path}`)
7+
8+
const content = fs.readFileSync(_path, 'utf-8')
9+
10+
return {
11+
content,
12+
}
13+
})

pnpm-lock.yaml

Lines changed: 60 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)