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": "Home",
      "link": "/"
    },
    {
      "text": "Lua Modding API",
      "link": "/lua-modding-api"
    },
    {
      "text": "Examples",
      "link": "/markdown-examples"
    }
  ],
  "sidebar": [
    {
      "text": "Getting Started",
      "collapsed": false,
      "items": [
        {
          "text": "Overview",
          "link": "/"
        },
        {
          "text": "1. Mod Structure",
          "link": "/lua-modding-api#mod-structure"
        },
        {
          "text": "2. Permissions",
          "link": "/lua-modding-api#permissions"
        },
        {
          "text": "3. Lifecycle & Hot Reload",
          "link": "/lua-modding-api#lifecycle-hot-reload"
        },
        {
          "text": "4. Mod Configuration",
          "link": "/lua-modding-api#mod-configuration"
        },
        {
          "text": "5. Event System",
          "link": "/lua-modding-api#event-system"
        }
      ]
    },
    {
      "text": "Client APIs",
      "collapsed": false,
      "items": [
        {
          "text": "6. Client",
          "link": "/lua-modding-api#client-api"
        },
        {
          "text": "7. Player",
          "link": "/lua-modding-api#player-api"
        },
        {
          "text": "8. Input",
          "link": "/lua-modding-api#input-api"
        },
        {
          "text": "9. UI",
          "link": "/lua-modding-api#ui-api"
        },
        {
          "text": "10. World",
          "link": "/lua-modding-api#world-api"
        }
      ]
    },
    {
      "text": "Network & Protocol",
      "collapsed": false,
      "items": [
        {
          "text": "11. Network",
          "link": "/lua-modding-api#network-api"
        },
        {
          "text": "12. Protocol Translators",
          "link": "/lua-modding-api#protocol-translators"
        }
      ]
    },
    {
      "text": "Rendering & Animation",
      "collapsed": false,
      "items": [
        {
          "text": "13. First-Person Animation",
          "link": "/lua-modding-api#first-person-animation"
        },
        {
          "text": "14. HUD Drawing",
          "link": "/lua-modding-api#hud-drawing"
        },
        {
          "text": "15. Render Events",
          "link": "/lua-modding-api#render-events"
        },
        {
          "text": "16. Resources",
          "link": "/lua-modding-api#resources-api"
        }
      ]
    },
    {
      "text": "Data & Diagnostics",
      "collapsed": false,
      "items": [
        {
          "text": "17. Storage",
          "link": "/lua-modding-api#storage-api"
        },
        {
          "text": "18. Logging",
          "link": "/lua-modding-api#logging"
        },
        {
          "text": "19. Lifecycle Events",
          "link": "/lua-modding-api#lifecycle-events"
        }
      ]
    },
    {
      "text": "Reference",
      "collapsed": false,
      "items": [
        {
          "text": "20. Event Reference",
          "link": "/lua-modding-api#event-reference"
        },
        {
          "text": "21. Safety & Limitations",
          "link": "/lua-modding-api#safety-limitations"
        },
        {
          "text": "22. Complete Mod",
          "link": "/lua-modding-api#complete-example"
        },
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "search": {
    "provider": "local"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/RustCraftMC/RustCraft"
    }
  ],
  "outline": {
    "label": "On this page",
    "level": "deep"
  },
  "lastUpdatedText": "Last updated",
  "docFooter": {
    "prev": "Previous page",
    "next": "Next page"
  },
  "langMenuLabel": "Change language"
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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