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

{
  "logo": "/img/logo.svg",
  "siteTitle": false,
  "outline": "deep",
  "darkModeSwitchLabel": "Toggle Dark Mode",
  "footer": {
    "message": "* In the unlikely event that <a href=\"/about/projects/appledore\"><b><i><u>Appledore</u></i></b></a> is offline, the traffic gets routed to a Linode instance to ensure availability.",
    "copyright": "Copyright © 2023-present Robin Biju Thomas"
  },
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "About",
      "items": [
        {
          "text": "$whoami",
          "link": "/about/whoami"
        },
        {
          "text": "Projects",
          "link": "/about/projects/"
        },
        {
          "text": "Services",
          "link": "/about/services"
        },
        {
          "text": "Pricing",
          "link": "/about/pricing"
        }
      ]
    },
    {
      "text": "Blog",
      "link": "/blog/"
    },
    {
      "text": "Get in touch",
      "link": "/social/connect"
    }
  ],
  "sidebar": [
    {
      "text": "Projects",
      "link": "/projects/"
    },
    {
      "text": "Services",
      "link": "/services/"
    },
    {
      "text": "Blog",
      "link": "/blog/"
    },
    {
      "text": "Get in touch",
      "link": "/connect"
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/teknicus/thomasrob.in-v2"
    },
    {
      "icon": "linkedin",
      "link": "https://www.linkedin.com/in/teknicus/"
    }
  ],
  "search": {
    "provider": "local"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

* In the unlikely event that Appledore is offline, the traffic gets routed to a Linode instance to ensure availability.