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

{
  "outline": {
    "level": [
      2,
      3
    ]
  },
  "nav": [
    {
      "text": "Home",
      "link": "/"
    }
  ],
  "sidebar": [
    {
      "text": "Project",
      "items": [
        {
          "text": "Roadmap in Reverse",
          "link": "/roadmap-in-reverse"
        }
      ]
    },
    {
      "text": "Essays and Guides",
      "items": [
        {
          "text": "How Can Two Peers Connect?",
          "link": "/how-peers-connect"
        },
        {
          "text": "Software Selections",
          "link": "/software-selections"
        },
        {
          "text": "Tracker Load",
          "link": "/tracker-load"
        },
        {
          "text": "Tuning for Load",
          "link": "/tuning-for-load"
        }
      ]
    },
    {
      "text": "Repository Documentation",
      "items": [
        {
          "text": "Repository Overview",
          "link": "https://github.com/zootella/ftorrent/blob/master/README.md"
        },
        {
          "text": "Dockerizing Aquatic",
          "link": "https://github.com/zootella/ftorrent/blob/master/open/README.md"
        },
        {
          "text": "Tracker Page",
          "link": "https://github.com/zootella/ftorrent/blob/master/open/page/README.md"
        },
        {
          "text": "Tracker Gauge",
          "link": "https://github.com/zootella/ftorrent/blob/master/open/gauge/README.md"
        },
        {
          "text": "Tracker Circuit Breaker",
          "link": "https://github.com/zootella/ftorrent/blob/master/open/breaker/README.md"
        },
        {
          "text": "DHT Bootstrap Node",
          "link": "https://github.com/zootella/ftorrent/blob/master/open/dht/README.md"
        },
        {
          "text": "Connection Checker",
          "link": "https://github.com/zootella/ftorrent/blob/master/good/README.md"
        },
        {
          "text": "Home Page",
          "link": "https://github.com/zootella/ftorrent/blob/master/site/README.md"
        },
        {
          "text": "Documentation Website",
          "link": "https://github.com/zootella/ftorrent/blob/master/docs/README.md"
        }
      ]
    },
    {
      "text": "Notes and Planning (TODO)",
      "items": [
        {
          "text": "Decentralized Infrastructure",
          "link": "/decentralized-infrastructure"
        },
        {
          "text": "Magnet Link User Guide",
          "link": "/magnet-link-user-guide"
        },
        {
          "text": "How the DHT Works",
          "link": "/how-the-dht-works"
        },
        {
          "text": "Desktop Client Planning",
          "link": "/desktop-client-planning"
        }
      ]
    },
    {
      "text": "Examples (TODO)",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/zootella/ftorrent"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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