pull/2005/head
Evan You 2 years ago
parent 78836522b8
commit ddb9020545

@ -25,7 +25,8 @@ export default defineConfig({
sidebar: { sidebar: {
'/guide/': sidebarGuide(), '/guide/': sidebarGuide(),
'/config/': sidebarConfig() '/config/': sidebarConfig(),
'/api/': sidebarGuide()
}, },
editLink: { editLink: {
@ -63,6 +64,11 @@ function nav() {
link: '/config/introduction', link: '/config/introduction',
activeMatch: '/config/' activeMatch: '/config/'
}, },
{
text: 'Runtime API',
link: '/api/',
activeMatch: '/api/'
},
{ {
text: pkg.version, text: pkg.version,
items: [ items: [
@ -89,38 +95,35 @@ function sidebarGuide() {
{ text: 'Getting Started', link: '/guide/getting-started' }, { text: 'Getting Started', link: '/guide/getting-started' },
{ text: 'Configuration', link: '/guide/configuration' }, { text: 'Configuration', link: '/guide/configuration' },
{ text: 'Routing', link: '/guide/routing' }, { text: 'Routing', link: '/guide/routing' },
{ text: 'Deploying', link: '/guide/deploying' }, { text: 'Deploying', link: '/guide/deploying' }
{ text: 'Internationalization', link: '/guide/i18n' }
] ]
}, },
{ {
text: 'Writing', text: 'Writing',
collapsed: false, collapsed: false,
items: [ items: [
{ text: 'Markdown', link: '/guide/markdown' }, { text: 'Markdown Extensions', link: '/guide/markdown' },
{ text: 'Asset Handling', link: '/guide/asset-handling' }, { text: 'Asset Handling', link: '/guide/asset-handling' },
{ text: 'Frontmatter', link: '/guide/frontmatter' }, { text: 'Frontmatter', link: '/guide/frontmatter' },
{ text: 'Using Vue in Markdown', link: '/guide/using-vue' }, { text: 'Using Vue in Markdown', link: '/guide/using-vue' },
{ text: 'API Reference', link: '/guide/api' } { text: 'Internationalization', link: '/guide/i18n' }
] ]
}, },
{ {
text: 'Theme', text: 'Customization',
collapsed: false, collapsed: false,
items: [ items: [
{ text: 'Introduction', link: '/guide/theme-introduction' }, { text: 'Default Theme', link: '/guide/default-theme' },
{ text: 'Nav', link: '/guide/theme-nav' }, {
{ text: 'Sidebar', link: '/guide/theme-sidebar' }, text: 'Extending the Default Theme',
{ text: 'Prev Next Link', link: '/guide/theme-prev-next-link' }, link: '/guide/customization-extending-default-theme'
{ text: 'Edit Link', link: '/guide/theme-edit-link' }, },
{ text: 'Last Updated', link: '/guide/theme-last-updated' }, { text: 'Building a Custom Theme', link: '/guide/customization-intro' },
{ text: 'Layout', link: '/guide/theme-layout' }, {
{ text: 'Home Page', link: '/guide/theme-home-page' }, text: 'Runtime API',
{ text: 'Team Page', link: '/guide/theme-team-page' }, link: '/api/'
{ text: 'Badge', link: '/guide/theme-badge' }, },
{ text: 'Footer', link: '/guide/theme-footer' }, { text: 'Build-Time Data Loading', link: '/guide/data-loading' }
{ text: 'Search', link: '/guide/theme-search' },
{ text: 'Carbon Ads', link: '/guide/theme-carbon-ads' }
] ]
}, },
{ {

@ -1,4 +1,4 @@
# API Reference # Runtime API Reference
VitePress offers several built-in APIs to let you access app data. VitePress also comes with a few built-in components that can be used globally. VitePress offers several built-in APIs to let you access app data. VitePress also comes with a few built-in components that can be used globally.
@ -66,11 +66,11 @@ interface Router {
- **Type**: `(path: string) => string` - **Type**: `(path: string) => string`
Appends the configured [`base`](../config/app-config#base) to a given URL path. Also see [Base URL](./asset-handling#base-url). Appends the configured [`base`](/config/app-config#base) to a given URL path. Also see [Base URL](/guide/asset-handling#base-url).
## `<Content />` ## `<Content />`
The `<Content />` component displays the rendered markdown contents. Useful [when creating your own theme](./theme-introduction). The `<Content />` component displays the rendered markdown contents. Useful [when creating your own theme](/guide/customization-intro).
```vue ```vue
<template> <template>

@ -45,7 +45,7 @@ However, if you are authoring a theme component that links to assets dynamically
<img :src="theme.logoPath" /> <img :src="theme.logoPath" />
``` ```
In this case it is recommended to wrap the path with the [`withBase` helper](./api#withbase) provided by VitePress: In this case it is recommended to wrap the path with the [`withBase` helper](/api/#withbase) provided by VitePress:
```vue ```vue
<script setup> <script setup>

@ -0,0 +1,49 @@
## Basic Usage
```js
export default {
load() {
return {
data: 'hello'
}
}
}
```
```js
export default {
async load() {
return (await fetch('...')).json()
}
}
```
## Generating Data Based On Local Files
```js
import { readDirSync } from 'node:fs'
export default {
watch: ['*.md'],
async load() {
//
}
}
```
## Typed Data
```ts
export interface Data {
// data type
}
declare const data: Data
export { data }
export default {
async load(): Promise<Data> {
// ...
}
}
```

@ -36,7 +36,7 @@ Directives also work:
### Access to Site & Page Data ### Access to Site & Page Data
You can use the [`useData` helper](./api#usedata) in a `<script>` block and expose the data to the page. You can use the [`useData` helper](/api/#usedata) in a `<script>` block and expose the data to the page.
**Input** **Input**
@ -104,7 +104,7 @@ This is a .md using a custom component
### Registering global components in the theme ### Registering global components in the theme
If the components are going to be used across several pages in the docs, they can be registered globally in the theme (or as part of extending the default VitePress theme). Check out the [Theming Guide](./theme-introduction) for more information. If the components are going to be used across several pages in the docs, they can be registered globally in the theme (or as part of extending the default VitePress theme). Check out the [Customization Guide](./customization-intro) for more information.
In `.vitepress/theme/index.js`, the `enhanceApp` function receives the Vue `app` instance so you can [register components](https://vuejs.org/guide/components/registration.html) as you would do in a regular Vue application. In `.vitepress/theme/index.js`, the `enhanceApp` function receives the Vue `app` instance so you can [register components](https://vuejs.org/guide/components/registration.html) as you would do in a regular Vue application.
@ -198,7 +198,7 @@ export default {
## Built-In Components ## Built-In Components
VitePress provides Built-In Vue Components like `ClientOnly`, check out the [Global Component Guide](./api) for more information. VitePress provides Built-In Vue Components like `ClientOnly`, check out the [Global Component Guide](/api/) for more information.
**Also see:** **Also see:**

@ -11,7 +11,7 @@ hero:
actions: actions:
- theme: brand - theme: brand
text: Get Started text: Get Started
link: /guide/getting-started link: /guide/what-is-vitepress
- theme: alt - theme: alt
text: View on GitHub text: View on GitHub
link: https://github.com/vuejs/vitepress link: https://github.com/vuejs/vitepress

Loading…
Cancel
Save