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

{
  "nav": [
    {
      "text": "Portfolio",
      "link": "/Portfolio"
    },
    {
      "text": "Public notes",
      "link": "/Notes"
    }
  ],
  "i18nRouting": true,
  "lastUpdated": true,
  "search": {
    "provider": "local"
  },
  "sidebar": [
    {
      "text": "Examples",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": {
        "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 258 230\"> <path d=\"m35.2 0h92.9c86.4 0 93.2 0.1 96.6 1.8 2 0.9 7.3 5.3 11.7 9.7 4.5 4.4 10.2 10.7 12.7 14 2.6 3.3 5.7 8 6.9 10.5 2.1 3.9 2.3 5.5 1.8 12.5-0.4 5.8-1.2 9.4-3 13-1.4 2.8-4.6 6.9-7.2 9.3-3 2.7-6.4 4.7-9.9 5.7-3.1 0.9-6.6 1.3-8.7 0.9-1.9-0.4-5.4-1.5-7.8-2.6-2.3-1-5.7-3.3-7.6-5-1.9-1.8-4.3-5.3-7.5-12.3l-1.9 4.5c-1.1 2.5-3.7 6.1-5.8 8.2-2.2 2-5.7 4.4-7.9 5.3-2.2 0.9-6.5 1.7-9.5 1.7-3.5 0.1-7.3-0.7-10.5-2-2.8-1.2-6.2-3.4-7.7-4.9-1.4-1.6-3.8-4.9-7.8-12.3l-1.3 3.3c-0.7 1.7-2.9 5-4.9 7.2-1.9 2.2-5.9 5.1-8.9 6.4-3.6 1.6-7.3 2.4-10.9 2.4-3.5 0-7.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-6.5-6.5-8.4-1.9-1.8-5.1-4.2-7.2-5.2-2.8-1.4-5.9-1.9-12-1.9-5.8 0-9.4 0.6-12.2 1.9-2.2 1-5.5 3-7.3 4.5l-3.2 2.6h-46c-5.1-4.1-8.3-6.1-10.5-7.1-2.9-1.3-6.4-1.8-12.5-1.8-6.3 0-9.5 0.5-12 1.8-2 1-5.1 3.4-7 5.2zm64.9 16.9c0.8 0 7.1 5.6 13.8 12.5 6.7 6.9 12.1 13.1 11.9 13.8-0.2 0.8-2.6 1.3-12.6 1.7v5c0 2.8-0.3 5.7-0.5 6.5-0.4 1.2-2.8 1.5-12.5 1.5-9.8 0-12.1-0.3-12.5-1.5-0.3-0.8-0.5-3.7-0.5-11.5h-6.5c-5.2 0-6.6-0.3-6.7-1.6-0.1-0.9 5.4-7.2 12.2-14 6.7-6.8 13-12.4 13.9-12.4z\"></svg>"
      },
      "link": "https://nph.itch.io/"
    },
    {
      "icon": {
        "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 176\"> <path d=\"m9.1 1.9c-1.9 1-4.5 3.4-5.8 5.3-1.3 1.8-2.3 4.2-2.1 5.2 0.2 1.3 21.2 15.6 63 43.2 34.6 22.8 63.2 41.4 63.8 41.4 0.6 0 29.2-18.6 63.8-41.4 41.8-27.6 62.8-41.9 63-43.2 0.2-1-0.7-3.4-2-5.3-1.3-1.9-3.9-4.2-5.8-5.3-3.4-1.7-8.4-1.8-119-1.8-111.7 0-115.6 0.1-118.9 1.9zm-9.1 86.6v55.5c66.6-42.2 85.6-54.8 85.2-55.2-0.4-0.4-19.5-13.1-42.4-28.2-23-15.2-42-27.6-42.3-27.6-0.3 0-0.5 25-0.5 55.5zm212.8-27.7c-22.9 15.3-41.9 27.9-42.2 28.2-0.3 0.3 18.8 12.8 42.4 27.8l43 27.2c0-86-0.3-111-0.8-110.9-0.4 0-19.5 12.5-42.4 27.7zm-161.8 69.7c-32.1 20.3-49.6 32-49.8 33.2-0.2 1 0.7 3.3 2 5.2 1.3 1.9 3.9 4.2 5.8 5.3 3.4 1.7 8.4 1.8 119 1.8 110.6 0 115.6-0.1 119-1.8 1.9-1.1 4.5-3.4 5.8-5.3 1.2-1.9 2.2-4.2 2.2-5.1 0-1.3-15.4-11.5-50.1-33.3l-50.2-31.5c-20.1 13.6-24.6 16-26.7 16-2.1 0-6.7-2.4-15-8-6.6-4.4-12.1-8-12.2-7.9-0.2 0-22.6 14.1-49.8 31.4z\"></svg>"
      },
      "link": "mailto:contact@noph.pro"
    },
    {
      "icon": "mastodon",
      "link": "https://mastodon.social/@Noph"
    },
    {
      "icon": {
        "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 2400 2800\"> <path d=\"M500,0L0,500v1800h600v500l500-500h400l900-900V0H500z M2200,1300l-400,400h-400l-350,350v-350H600V200h1600 V1300z\"></svg>"
      },
      "link": "https://www.twitch.tv/nophinou"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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