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": [
    4,
    5
  ],
  "logo": "/images/cuo-logo.png",
  "editLink": {
    "text": "Edit this page on GitHub",
    "pattern": "https://github.com/ClassicUO/classicuo-web/edit/main/site/:path"
  },
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "About",
      "link": "/about"
    },
    {
      "text": "Scripting",
      "link": "/scripting/globals"
    }
  ],
  "sidebar": [
    {
      "text": "Home",
      "items": [
        {
          "text": "About",
          "link": "/about"
        }
      ]
    },
    {
      "text": "Players",
      "items": [
        {
          "text": "FAQ",
          "link": "/players/faq.md"
        },
        {
          "text": "FAQ (sanctioned)",
          "link": "/players/faq-sanctioned.md"
        },
        {
          "text": "Features",
          "items": [
            {
              "text": "Action Bar",
              "link": "/features/action-bar.md"
            },
            {
              "text": "Autoloot",
              "link": "/features/autoloot.md"
            },
            {
              "text": "Chat",
              "link": "/features/chat.md"
            },
            {
              "text": "Game Profiles",
              "link": "/features/game-profiles.md"
            },
            {
              "text": "Game Options",
              "link": "/features/game-options.md"
            },
            {
              "text": "Grid Containers",
              "link": "/features/grid-containers.md"
            },
            {
              "text": "Tooltips",
              "link": "/features/tooltips.md"
            }
          ]
        }
      ]
    },
    {
      "text": "Shard Owners",
      "items": [
        {
          "text": "FAQ",
          "link": "/shard-owners/faq.md"
        },
        {
          "text": "Patching",
          "link": "/shard-owners/patching.md"
        },
        {
          "text": "Shard Rules",
          "link": "/shard-owners/shard-rules.md"
        }
      ]
    },
    {
      "text": "Scripting",
      "items": [
        {
          "text": "Globals",
          "link": "/scripting/globals"
        },
        {
          "text": "Functions",
          "collapsed": false,
          "items": [
            {
              "text": "exit",
              "link": "/scripting/functions/exit.md"
            },
            {
              "text": "log",
              "link": "/scripting/functions/log.md"
            },
            {
              "text": "sleep",
              "link": "/scripting/functions/sleep.md"
            }
          ]
        },
        {
          "text": "References",
          "collapsed": false,
          "items": [
            {
              "text": "Client",
              "link": "/scripting/namespaces/Client/"
            },
            {
              "text": "Entity",
              "link": "/scripting/namespaces/Entity/"
            },
            {
              "text": "GameObject",
              "link": "/scripting/namespaces/GameObject/"
            },
            {
              "text": "Gump",
              "link": "/scripting/namespaces/Gump/"
            },
            {
              "text": "IgnoreList",
              "link": "/scripting/namespaces/IgnoreList/"
            },
            {
              "text": "Item",
              "link": "/scripting/namespaces/Item/"
            },
            {
              "text": "Journal",
              "link": "/scripting/namespaces/Journal/"
            },
            {
              "text": "Mobile",
              "link": "/scripting/namespaces/Mobile/"
            },
            {
              "text": "Player",
              "link": "/scripting/namespaces/Player/"
            },
            {
              "text": "PopupMenu",
              "link": "/scripting/namespaces/PopupMenu/"
            },
            {
              "text": "Prompt",
              "link": "/scripting/namespaces/Prompt/"
            },
            {
              "text": "Skill",
              "link": "/scripting/namespaces/Skill/"
            },
            {
              "text": "Target",
              "link": "/scripting/namespaces/Target/"
            },
            {
              "text": "enums",
              "link": "/scripting/namespaces/enums/"
            }
          ]
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/ClassicUO/ClassicUO"
    },
    {
      "icon": "discord",
      "link": "https://discord.com/invite/VdyCpjQ"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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