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": "Documentation",
      "link": "/Intro"
    },
    {
      "text": "About",
      "link": "/about"
    },
    {
      "text": "Store",
      "link": "/stores"
    }
  ],
  "sidebar": [
    {
      "text": "Getting Started",
      "link": "/Intro"
    },
    {
      "text": "Solar",
      "collapsed": false,
      "items": [
        {
          "text": "Introduction",
          "link": "/solar-intro"
        },
        {
          "text": "Epever",
          "collapsed": true,
          "items": [
            {
              "text": "Getting Started",
              "link": "/epever-start"
            },
            {
              "text": "Flashing",
              "link": "/epever-flashing"
            },
            {
              "text": "Configuration",
              "link": "/epever-config"
            },
            {
              "text": "ESPHOME",
              "link": "/epever-ESPHOME"
            },
            {
              "text": "TroubleShooting",
              "link": "/epever-troubleshooting"
            }
          ]
        },
        {
          "text": "Solis",
          "collapsed": true,
          "items": [
            {
              "text": "Getting Started",
              "link": "/solis-start"
            },
            {
              "text": "ESPHOME",
              "link": "/solis-ESPHOME"
            },
            {
              "text": "TroubleShooting",
              "link": "/solis-troubleshooting"
            }
          ]
        },
        {
          "text": "Generic RS485 2pin",
          "collapsed": true,
          "items": [
            {
              "text": "Getting Started",
              "link": "/2pin-start"
            },
            {
              "text": "ESPHOME",
              "link": "/2pin-ESPHOME"
            },
            {
              "text": "TroubleShooting",
              "link": "/2pin-troubleshooting"
            }
          ]
        },
        {
          "text": "Other models",
          "link": "/api-examples"
        }
      ]
    },
    {
      "text": "USB KeepAlive",
      "collapsed": false,
      "items": [
        {
          "text": "SMD Fixed Version",
          "link": "/USBKeepAliveSMD"
        },
        {
          "text": "KIT version",
          "link": "/USBKeepAliveKIT"
        }
      ]
    },
    {
      "text": "Maker Prodcuts",
      "collapsed": false,
      "items": [
        {
          "text": "Brian Lough",
          "collapsed": false,
          "items": [
            {
              "text": "PowerBloughr",
              "link": "/PowerBloughr"
            },
            {
              "text": "D1 Mini TFT Shield",
              "link": "/D1-TFT"
            },
            {
              "text": "D1 Mini Nunchuck Shield",
              "link": "/D1-Nunchuck"
            },
            {
              "text": "ESP32 Debug Shields",
              "link": "/ESP32-debug"
            },
            {
              "text": "ESP32Matrix",
              "link": "/ESP32Matrix"
            },
            {
              "text": "D1MiniMatrix",
              "link": "/D1MiniMatrix"
            },
            {
              "text": "I2S Matrix",
              "link": "/I2S-Matrix"
            }
          ]
        },
        {
          "text": "Larry",
          "collapsed": true,
          "items": [
            {
              "text": "Item C",
              "link": "/item-c"
            },
            {
              "text": "Item D",
              "link": "/item-d"
            }
          ]
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/chickey"
    },
    {
      "icon": "twitter",
      "link": "https://twitter.com/eplop"
    },
    {
      "icon": "discord",
      "link": "https://discord.gg/J7GnxDRaHj"
    }
  ],
  "search": {
    "provider": "local"
  }
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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