Skip to content

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": {
    "src": "/logo.svg",
    "width": 24,
    "height": 24
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/better-try"
    },
    {
      "icon": "twitter",
      "link": "https://twitter.com/trybetterapp"
    },
    {
      "icon": "discord",
      "link": "https://github.com/better-try"
    },
    {
      "icon": "youtube",
      "link": "https://youtube.com/@trybetterapp"
    }
  ],
  "nav": [
    {
      "text": "Products",
      "link": "/products/index",
      "activeMatch": "/products/"
    },
    {
      "text": "Store",
      "link": "/store/index",
      "activeMatch": "/store/"
    },
    {
      "text": "Guide",
      "link": "/guide/index"
    }
  ],
  "sidebar": {
    "/guide/": {
      "base": "/guide/",
      "items": [
        {
          "text": "GeekClock",
          "collapsed": false,
          "items": [
            {
              "text": "What is GeekClock?",
              "base": "/guide/",
              "link": "product1/api-examples"
            }
          ]
        },
        {
          "text": "VisaPal",
          "collapsed": false,
          "items": [
            {
              "text": "What is VisaPal?",
              "base": "/guide/",
              "link": "product2/markdown-examples"
            }
          ]
        }
      ]
    },
    "/reference/": {
      "base": "/reference/",
      "items": [
        {
          "text": "Reference",
          "items": [
            {
              "text": "Site Config",
              "link": "site-config"
            },
            {
              "text": "Frontmatter Config",
              "link": "frontmatter-config"
            },
            {
              "text": "Runtime API",
              "link": "runtime-api"
            },
            {
              "text": "CLI",
              "link": "cli"
            },
            {
              "text": "Default Theme",
              "base": "/reference/default-theme-",
              "items": [
                {
                  "text": "Overview",
                  "link": "config"
                },
                {
                  "text": "Nav",
                  "link": "nav"
                },
                {
                  "text": "Sidebar",
                  "link": "sidebar"
                },
                {
                  "text": "Home Page",
                  "link": "home-page"
                },
                {
                  "text": "Footer",
                  "link": "footer"
                },
                {
                  "text": "Layout",
                  "link": "layout"
                },
                {
                  "text": "Badge",
                  "link": "badge"
                },
                {
                  "text": "Team Page",
                  "link": "team-page"
                },
                {
                  "text": "Prev / Next Links",
                  "link": "prev-next-links"
                },
                {
                  "text": "Edit Link",
                  "link": "edit-link"
                },
                {
                  "text": "Last Updated Timestamp",
                  "link": "last-updated"
                },
                {
                  "text": "Search",
                  "link": "search"
                },
                {
                  "text": "Carbon Ads",
                  "link": "carbon-ads"
                }
              ]
            }
          ]
        }
      ]
    }
  },
  "editLink": {
    "pattern": "https://github.com/better-ts/vitepress-tempate/edit/main/packages/:path",
    "text": "Edit this page on GitHub"
  },
  "footer": {
    "copyright": "Copyright © 2023-2024 TryBetterApp."
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "guide/product1/api-examples.md",
  "filePath": "guide/product1/api-examples.md",
  "lastUpdated": 1713856214000
}

Page Frontmatter

{
  "outline": "deep"
}

More

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