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>
<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": "/logo.png",
  "outline": [
    2,
    3
  ],
  "nav": [
    {
      "text": "Guide",
      "link": "/guide/",
      "activeMatch": "^/guide/"
    },
    {
      "text": "API",
      "link": "/api/",
      "activeMatch": "^/api/"
    },
    {
      "text": "Links",
      "items": [
        {
          "text": "Discussions",
          "link": "https://github.com/JuckZ/awesome-brain-manager/discussions"
        },
        {
          "text": "Changelog",
          "link": "https://github.com/JuckZ/awesome-brain-manager/blob/master/CHANGELOG.md"
        },
        {
          "text": "Roadmap",
          "link": "https://github.com/users/JuckZ/projects/2"
        }
      ]
    }
  ],
  "sidebar": {
    "/api/": [
      {
        "text": "packages",
        "items": [
          {
            "text": "core",
            "link": "/api/modules/core.html"
          },
          {
            "text": "pomodoro",
            "link": "/api/modules/pomodoro.html"
          },
          {
            "text": "ai",
            "link": "/api/modules/ai.html"
          },
          {
            "text": "obsidian",
            "link": "/api/modules/obsidian.html"
          },
          {
            "text": "utils",
            "link": "/api/modules/utils.html"
          },
          {
            "text": "ntfy",
            "link": "/api/modules/ntfy.html"
          },
          {
            "text": "browser",
            "link": "/api/modules/browser.html"
          }
        ]
      }
    ],
    "/": [
      {
        "text": "Introduction",
        "items": [
          {
            "text": "What is Awesome Brain Manager?",
            "link": "/introduction.html"
          },
          {
            "text": "Getting Started",
            "link": "/getting-started.html"
          }
        ]
      },
      {
        "text": "Core Feature",
        "items": [
          {
            "text": "Feature preview",
            "link": "/guide/"
          },
          {
            "text": "Pomodoro",
            "link": "/guide/pomodoro.html"
          },
          {
            "text": "Special Effects",
            "link": "/guide/special-effects.html"
          },
          {
            "text": "Utils",
            "link": "/guide/utils.html"
          }
        ]
      },
      {
        "text": "Cookbook",
        "collapsed": false,
        "items": [
          {
            "text": "Index",
            "link": "/cookbook/"
          },
          {
            "text": "Hot Module Replacement",
            "link": "/cookbook/hot-module-replacement.html"
          },
          {
            "text": "Testing",
            "link": "/cookbook/testing.html"
          },
          {
            "text": "Advanced",
            "link": "/cookbook/advanced.html"
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": {
        "svg": "rss"
      },
      "link": "/feed.rss"
    },
    {
      "icon": "github",
      "link": "https://github.com/JuckZ/awesome-brain-manager"
    }
  ],
  "footer": {
    "copyright": "Copyright © 2022-present Juck",
    "message": "Released under the MIT License."
  },
  "editLink": {
    "pattern": "https://github.com/JuckZ/awesome-brain-manager/edit/develop/docs/:path",
    "text": "Suggest changes to this page"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Released under the MIT License.