Skip to content
On this page

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

{
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Blogs",
      "link": "/mindmap"
    }
  ],
  "sidebar": [
    {
      "text": "Blogs",
      "items": [
        {
          "text": "mindmap",
          "link": "/mindmap"
        },
        {
          "text": "后量子密码",
          "link": "/后量子密码"
        },
        {
          "text": "ZKP_Groth16",
          "link": "/ZKP_Groth16"
        },
        {
          "text": "ZKP_libsnark",
          "link": "/ZKP_libsnark"
        },
        {
          "text": "Floating Point",
          "link": "/Floating Point"
        },
        {
          "text": "C2",
          "link": "/C2"
        },
        {
          "text": "数据结构",
          "link": "/数据结构"
        },
        {
          "text": "library",
          "link": "/library"
        },
        {
          "text": "TLS",
          "link": "/TLS"
        },
        {
          "text": "CTF_tools",
          "link": "/CTF_tools"
        },
        {
          "text": "CTF_Misc_流量分析",
          "link": "/CTF_Misc_流量分析"
        },
        {
          "text": "CTF_Misc_lemminx",
          "link": "/CTF_Misc_lemminx"
        },
        {
          "text": "CTF_Web_EasyCleanup",
          "link": "/CTF_Web_EasyCleanup"
        },
        {
          "text": "CTF_Web_mysql_injection",
          "link": "/CTF_Web_mysql_injection"
        },
        {
          "text": "CTF_Web_pklovecloud",
          "link": "/CTF_Web_pklovecloud"
        },
        {
          "text": "CTF_Web_PNG图片转换器",
          "link": "/CTF_Web_PNG图片转换器"
        },
        {
          "text": "CTF_Web_rce",
          "link": "/CTF_Web_rce"
        },
        {
          "text": "CTF_Web_yeeclass",
          "link": "/CTF_Web_yeeclass"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/marsvillager/marsvillager.github.io"
    }
  ]
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "api-examples.md"
}

Page Frontmatter

{
  "outline": "deep"
}

More

Check out the documentation for the full list of runtime APIs.