When the document driven mode is enabled, useContent() is available everywhere in your app and gives access to a list of refs based on your content.
<script setup lang="ts">
const {
// Global references
globals,
navigation,
surround,
page,
// Computed properties from `page` key
excerpt,
toc,
type,
layout,
// Computed properties from `surround` key
next,
prev
} = useContent()
</script>
Rendering the current page becomes a bliss with this composable:
<script setup lang="ts">
const { page } = useContent()
</script>
<template>
<ContentRenderer :key="page._id" :value="page" />
</template>
<script setup lang="ts">
const { prev, next } = useContent()
</script>
<template>
<div>
<NuxtLink v-if="prev" :to="prev._path">{{ prev.title }}</NuxtLink>
<NuxtLink v-if="next" :to="next._path">{{ next.title }}</NuxtLink>
</div>
</template>
<script setup lang="ts">
const { toc } = useContent()
</script>
<template>
<div>
<ul v-if="toc && toc.links">
<li v-for="link in toc.links" :key="link.text">
<a :href="`#${link.id}`">
{{ link.text }}
</a>
</li>
</ul>
</div>
</template>
[
{
"title": "Introduction",
"path": "/content-v2/document-driven/introduction",
"stem": "content-v2/5.document-driven/1.introduction",
"description": "The Document-driven mode gives a lot more power to Markdown-based websites."
},
{
"title": "Hooks",
"path": "/content-v2/recipes/hooks",
"stem": "content-v2/6.recipes/1.hooks",
"description": "Nuxt Content exposes hooks to allow you to modify the content before it is parsed and after it is parsed."
}
]