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

{
  "search": {
    "provider": "local"
  },
  "editLink": {
    "pattern": "https://github.com/atshelchin/blog.shelchin.com/edit/master/docs/:path",
    "text": "Edit this page on GitHub"
  },
  "lastUpdated": {
    "text": "Updated at",
    "formatOptions": {
      "dateStyle": "medium",
      "timeStyle": "medium"
    }
  },
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "English",
      "link": "/en/how-to-deploy-safe-wallet-on-new-blockchain"
    },
    {
      "text": "汉字",
      "link": "/zh/seo-guide"
    }
  ],
  "sidebar": {
    "/zh/": [
      {
        "text": "汉字区",
        "items": [
          {
            "text": "SEO 优化怎么做",
            "link": "/zh/seo-guide"
          },
          {
            "text": "Solidity 语法掌握检查清单",
            "link": "/zh/solidity-checklist"
          },
          {
            "text": "用好 Git ,让软件历史更清晰易懂",
            "link": "/zh/git-history"
          },
          {
            "text": "设置一台新的 Postgres 服务器",
            "link": "/zh/setup-postgres"
          },
          {
            "text": "设置一台新的 Redis 服务器",
            "link": "/zh/setup-redis"
          }
        ]
      }
    ],
    "/en": [
      {
        "text": "English",
        "items": [
          {
            "text": "How to deploy Safe Wallet on a new blockchain",
            "link": "/en/how-to-deploy-safe-wallet-on-new-blockchain"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/atshelchin/blog.shelchin.com"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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