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

{
  "siteTitle": "VitePress Test",
  "logo": "/images/logo-sm.png",
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Examples",
      "link": "/markdown-examples"
    },
    {
      "text": "Links",
      "items": [
        {
          "text": "Zipline Android GitHub",
          "link": "https://github.com/cssnr/zipline-android"
        },
        {
          "text": "Documentation GitHub",
          "link": "https://github.com/cssnr/zipline-android-docs"
        },
        {
          "text": "Diced Zipline Server",
          "link": "https://github.com/diced/zipline"
        },
        {
          "text": "Developer Site",
          "link": "https://cssnr.github.io/"
        },
        {
          "text": "Contribute",
          "link": "https://ko-fi.com/cssnr"
        }
      ]
    }
  ],
  "sidebar": [
    {
      "text": "Examples",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/cssnr/zipline-android"
    },
    {
      "icon": "discord",
      "link": "https://discord.gg/wXy6m2X8wY"
    },
    {
      "icon": "kofi",
      "link": "https://ko-fi.com/cssnr"
    },
    {
      "icon": {
        "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" style=\"fill: none;\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"lucide lucide-globe\"><circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20\"/><path d=\"M2 12h20\"/></svg>"
      },
      "link": "https://cssnr.github.io/"
    }
  ],
  "editLink": {
    "pattern": "https://github.com/smashedr/vitepress-test/blob/master/docs/:path",
    "text": "View on GitHub"
  },
  "lastUpdated": {
    "text": "Updated at",
    "formatOptions": {
      "dateStyle": "medium",
      "timeStyle": "medium"
    }
  },
  "search": {
    "provider": "algolia",
    "options": {
      "appId": "CYR3HCDCK8",
      "apiKey": "2ebbec61f58bdaa0f89787848930815c",
      "indexName": "smashedr_github_io_vitepress_test"
    }
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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