Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

chore: init docs #98

Merged
merged 15 commits into from
Apr 20, 2021
Prev Previous commit
Next Next commit
simplify content api
  • Loading branch information
pi0 committed Apr 20, 2021
commit 13269ecc3b173d80a8b6e8afe45e907665a82e10
4 changes: 2 additions & 2 deletions docs/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import { useContent } from '~/modules/content/runtime'

export default defineNuxtComponent({
setup () {
useHead({ title: 'Nuxt Documentation' })
const { data: menu } = useContent('/menu.json')

const { data: menu } = useContent('/menu', 'json')
useHead({ title: 'Nuxt Documentation' })

return {
menu
Expand Down
7 changes: 3 additions & 4 deletions docs/modules/content/runtime/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useQuery } from 'h3'
import unified from 'unified'
import remarkParse from 'remark-parse'
import remark2rehype from 'remark-rehype'
Expand All @@ -15,11 +14,11 @@ export default async (req) => {
.use(rehypeDoc)
.use(rehypeStringify)

const { slug, ext = 'md' } = useQuery(req)
const id = req.url

const data = await readAsset(`content${slug}.${ext}`) || `content not found: ${slug}.${ext}`
const data = await readAsset(`content${id}`) || `content not found: ${id}`

if (ext === 'md') {
if ((id as string).endsWith('.md')) {
return {
html: await markdown.process({ contents: data }).then(v => v.toString())
}
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/content/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { asyncData } from '@nuxt/app'

export { default as NuxtContent } from './content.vue'

export function useContent (slug, ext = 'md') {
return asyncData(`content:${slug}`, () => globalThis.$fetch(`/api/content?slug=${slug}&ext=${ext}`))
export function useContent (slug) {
return asyncData(`content:${slug}`, () => globalThis.$fetch(`/api/content${slug}`))
}
5 changes: 2 additions & 3 deletions docs/pages/docs/[cat]/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</template>

<script>
import { ref } from 'vue'
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { defineNuxtComponent } from '@nuxt/app'
import { useContent, NuxtContent } from '~/modules/content/runtime'
Expand All @@ -23,8 +23,7 @@ export default defineNuxtComponent({
const route = useRoute()

// Slug and page data
const slug = ref(route.fullPath)

const slug = computed(() => route.fullPath + '.md')
const { data: content } = useContent(slug.value)

return {
Expand Down