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": "Test",
      "link": "/pages/tests/progress-tracking-test"
    },
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "User Guide",
      "link": "/pages/user-guide"
    },
    {
      "text": "Tracks",
      "link": "/pages/tracks/_index"
    },
    {
      "text": "Tutorials",
      "link": "/pages/tutorials/_index"
    }
  ],
  "sidebar": {
    "/pages/": [
      {
        "text": "Tracks",
        "items": [
          {
            "text": "3rd Person 3D Action RPG",
            "link": "/pages/tracks/3d-3rdp-action-rpg"
          }
        ]
      },
      {
        "text": "Tutorials",
        "items": [
          {
            "text": "Create your first project",
            "link": "/pages/tutorials/create-your-first-project"
          },
          {
            "text": "Create your initial 3D scene",
            "link": "/pages/tutorials/set-up-initial-3d-scene"
          },
          {
            "text": "3rd person 3D Character ",
            "link": "/pages/tutorials/character_controller_3d_3rdp"
          }
        ]
      }
    ],
    "/profile": [
      {
        "items": [
          {
            "text": "Dashboard",
            "link": "/profile"
          },
          {
            "text": "Bookmarks",
            "link": "/profile/bookmarks"
          },
          {
            "text": "Progress",
            "link": "/profile/progress"
          }
        ]
      }
    ]
  },
  "search": {
    "provider": "local"
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/Redot-Engine/redot-academy"
    }
  ]
}

Page Data ​

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [
    {
      "level": 1,
      "title": "Runtime API Examples",
      "slug": "runtime-api-examples",
      "link": "#runtime-api-examples",
      "children": [
        {
          "level": 2,
          "title": "Results",
          "slug": "results",
          "link": "#results",
          "children": [
            {
              "level": 3,
              "title": "Theme Data",
              "slug": "theme-data",
              "link": "#theme-data",
              "children": []
            },
            {
              "level": 3,
              "title": "Page Data",
              "slug": "page-data",
              "link": "#page-data",
              "children": []
            },
            {
              "level": 3,
              "title": "Page Frontmatter",
              "slug": "page-frontmatter",
              "link": "#page-frontmatter",
              "children": []
            }
          ]
        },
        {
          "level": 2,
          "title": "More",
          "slug": "more",
          "link": "#more",
          "children": []
        }
      ]
    }
  ],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md"
}

Page Frontmatter ​

{
  "outline": "deep"
}

More ​

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