Runtime API Examples
This page demonstrates usage of some of the runtime APIs provided by VitePress.
The main useData() API can be used to access site, theme, and page data for the current page. It works in both .md and .vue files:
md
<script setup>
import { useData } from 'vitepress'
const { theme, page, frontmatter } = useData()
</script>
## Results
### Theme Data
<pre>{{ theme }}</pre>
### Page Data
<pre>{{ page }}</pre>
### Page Frontmatter
<pre>{{ frontmatter }}</pre>Results
Theme Data
{
"search": {
"provider": "local"
},
"nav": [
{
"text": "Home",
"link": "/"
},
{
"text": "Articles",
"link": "/articles"
},
{
"text": "Who am I",
"link": "/who-am-i"
}
],
"sidebar": [
{
"text": "Rust",
"items": [
{
"text": "Everything about Rust ownership",
"link": "/rust/rust-ownership-explained"
}
]
},
{
"text": "Scala",
"items": [
{
"text": "Introduce to Cats-effect",
"link": "/scala/"
}
]
},
{
"text": "Data Engineering",
"items": [
{
"text": "Introduce to Apache Iceberg",
"link": "/rust"
},
{
"text": "Apache Hudi 101",
"link": "/scala"
}
]
},
{
"text": "Devops",
"items": [
{
"text": "Cross namespace configuration sharing in kubernetes",
"link": "/devops/cross-namespace-configuration-sharing-in-kubernetes/Cross-Namespace.md"
}
]
},
{
"text": "Interesting Projects",
"items": [
{
"text": "Golang rest framework - Hertz",
"link": "/rust"
}
]
}
],
"socialLinks": [
{
"icon": "github",
"link": "https://github.com/yuelirex"
}
]
}Page Data
{
"title": "Runtime API Examples",
"description": "",
"frontmatter": {
"layout": "doc"
},
"headers": [],
"relativePath": "who-am-i.md",
"filePath": "who-am-i.md"
}Page Frontmatter
{
"layout": "doc"
}More
Check out the documentation for the full list of runtime APIs.