mirror of https://github.com/vuejs/vitepress
parent
3d61619ec0
commit
0233972a2f
@ -0,0 +1,225 @@
|
||||
import { createRequire } from 'module'
|
||||
import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const pkg = require('vitepress/package.json')
|
||||
|
||||
export default defineAdditionalConfig({
|
||||
description: 'Vite と Vue による静的サイトジェネレーター',
|
||||
|
||||
themeConfig: {
|
||||
nav: nav(),
|
||||
|
||||
search: { options: searchOptions() },
|
||||
|
||||
sidebar: {
|
||||
'/ja/guide/': { base: '/ja/guide/', items: sidebarGuide() },
|
||||
'/ja/reference/': { base: '/ja/reference/', items: sidebarReference() }
|
||||
},
|
||||
|
||||
editLink: {
|
||||
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path',
|
||||
text: 'GitHub でこのページを編集'
|
||||
},
|
||||
|
||||
footer: {
|
||||
message: 'MIT ライセンスの下で公開されています。',
|
||||
copyright: 'Copyright © 2019-present Evan You'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function nav(): DefaultTheme.NavItem[] {
|
||||
return [
|
||||
{
|
||||
text: 'ガイド',
|
||||
link: '/ja/guide/what-is-vitepress',
|
||||
activeMatch: '/guide/'
|
||||
},
|
||||
{
|
||||
text: 'リファレンス',
|
||||
link: '/ja/reference/site-config',
|
||||
activeMatch: '/reference/'
|
||||
},
|
||||
{
|
||||
text: pkg.version,
|
||||
items: [
|
||||
{
|
||||
text: '1.6.4',
|
||||
link: 'https://vuejs.github.io/vitepress/v1/'
|
||||
},
|
||||
{
|
||||
text: '更新履歴',
|
||||
link: 'https://github.com/vuejs/vitepress/blob/main/CHANGELOG.md'
|
||||
},
|
||||
{
|
||||
text: 'コントリビュート方法',
|
||||
link: 'https://github.com/vuejs/vitepress/blob/main/.github/contributing.md'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
function sidebarGuide(): DefaultTheme.SidebarItem[] {
|
||||
return [
|
||||
{
|
||||
text: '導入',
|
||||
collapsed: false,
|
||||
items: [
|
||||
{ text: 'VitePress とは?', link: 'what-is-vitepress' },
|
||||
{ text: 'はじめに', link: 'getting-started' },
|
||||
{ text: 'ルーティング', link: 'routing' },
|
||||
{ text: 'デプロイ', link: 'deploy' }
|
||||
]
|
||||
},
|
||||
{
|
||||
text: '執筆',
|
||||
collapsed: false,
|
||||
items: [
|
||||
{ text: 'Markdown 拡張', link: 'markdown' },
|
||||
{ text: 'アセットの取り扱い', link: 'asset-handling' },
|
||||
{ text: 'フロントマター', link: 'frontmatter' },
|
||||
{ text: 'Markdown で Vue を使う', link: 'using-vue' },
|
||||
{ text: '多言語対応', link: 'i18n' }
|
||||
]
|
||||
},
|
||||
{
|
||||
text: 'カスタマイズ',
|
||||
collapsed: false,
|
||||
items: [
|
||||
{ text: 'カスタムテーマを使う', link: 'custom-theme' },
|
||||
{
|
||||
text: 'デフォルトテーマの拡張',
|
||||
link: 'extending-default-theme'
|
||||
},
|
||||
{ text: 'ビルド時のデータ読み込み', link: 'data-loading' },
|
||||
{ text: 'SSR 互換性', link: 'ssr-compat' },
|
||||
{ text: 'CMS との接続', link: 'cms' }
|
||||
]
|
||||
},
|
||||
{
|
||||
text: '実験的機能',
|
||||
collapsed: false,
|
||||
items: [
|
||||
{ text: 'MPA モード', link: 'mpa-mode' },
|
||||
{ text: 'サイトマップ生成', link: 'sitemap-generation' }
|
||||
]
|
||||
},
|
||||
{
|
||||
text: '設定 & API リファレンス',
|
||||
base: '/ja/reference/',
|
||||
link: 'site-config'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
function sidebarReference(): DefaultTheme.SidebarItem[] {
|
||||
return [
|
||||
{
|
||||
text: 'リファレンス',
|
||||
items: [
|
||||
{ text: 'サイト設定', link: 'site-config' },
|
||||
{ text: 'Frontmatter 設定', link: 'frontmatter-config' },
|
||||
{ text: 'ランタイム API', link: 'runtime-api' },
|
||||
{ text: 'CLI', link: 'cli' },
|
||||
{
|
||||
text: 'デフォルトテーマ',
|
||||
base: '/ja/reference/default-theme-',
|
||||
items: [
|
||||
{ text: '概要', link: 'config' },
|
||||
{ text: 'ナビゲーション', link: 'nav' },
|
||||
{ text: 'サイドバー', link: 'sidebar' },
|
||||
{ text: 'ホームページ', link: 'home-page' },
|
||||
{ text: 'フッター', link: 'footer' },
|
||||
{ text: 'レイアウト', link: 'layout' },
|
||||
{ text: 'バッジ', link: 'badge' },
|
||||
{ text: 'チームページ', link: 'team-page' },
|
||||
{ text: '前 / 次 リンク', link: 'prev-next-links' },
|
||||
{ text: '編集リンク', link: 'edit-link' },
|
||||
{ text: '最終更新日時', link: 'last-updated' },
|
||||
{ text: '検索', link: 'search' },
|
||||
{ text: 'Carbon 広告', link: 'carbon-ads' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
function searchOptions(): Partial<DefaultTheme.AlgoliaSearchOptions> {
|
||||
return {
|
||||
placeholder: 'ドキュメントを検索',
|
||||
translations: {
|
||||
button: {
|
||||
buttonText: '検索',
|
||||
buttonAriaLabel: '検索'
|
||||
},
|
||||
modal: {
|
||||
searchBox: {
|
||||
clearButtonTitle: '検索をクリア',
|
||||
clearButtonAriaLabel: '検索をクリア',
|
||||
closeButtonText: '閉じる',
|
||||
closeButtonAriaLabel: '閉じる',
|
||||
placeholderText: 'ドキュメントを検索',
|
||||
placeholderTextAskAi: 'AI に質問: ',
|
||||
placeholderTextAskAiStreaming: '回答を作成中...',
|
||||
searchInputLabel: '検索',
|
||||
backToKeywordSearchButtonText: 'キーワード検索に戻る',
|
||||
backToKeywordSearchButtonAriaLabel: 'キーワード検索に戻る'
|
||||
},
|
||||
startScreen: {
|
||||
recentSearchesTitle: '検索履歴',
|
||||
noRecentSearchesText: '最近の検索はありません',
|
||||
saveRecentSearchButtonTitle: '検索履歴に保存',
|
||||
removeRecentSearchButtonTitle: '検索履歴から削除',
|
||||
favoriteSearchesTitle: 'お気に入り',
|
||||
removeFavoriteSearchButtonTitle: 'お気に入りから削除',
|
||||
recentConversationsTitle: '最近の会話',
|
||||
removeRecentConversationButtonTitle: '会話履歴から削除'
|
||||
},
|
||||
errorScreen: {
|
||||
titleText: '結果を取得できません',
|
||||
helpText: 'ネットワーク接続を確認してください'
|
||||
},
|
||||
noResultsScreen: {
|
||||
noResultsText: '結果が見つかりません',
|
||||
suggestedQueryText: '別の検索語を試してください',
|
||||
reportMissingResultsText: '結果があるはずだと思いますか?',
|
||||
reportMissingResultsLinkText: 'フィードバックを送る'
|
||||
},
|
||||
resultsScreen: {
|
||||
askAiPlaceholder: 'AI に質問: '
|
||||
},
|
||||
askAiScreen: {
|
||||
disclaimerText:
|
||||
'AI が生成した回答には誤りが含まれる可能性があります。必ずご確認ください。',
|
||||
relatedSourcesText: '関連ソース',
|
||||
thinkingText: '考え中...',
|
||||
copyButtonText: 'コピー',
|
||||
copyButtonCopiedText: 'コピーしました!',
|
||||
copyButtonTitle: 'コピー',
|
||||
likeButtonTitle: 'いいね',
|
||||
dislikeButtonTitle: 'よくない',
|
||||
thanksForFeedbackText: 'フィードバックありがとうございます!',
|
||||
preToolCallText: '検索中...',
|
||||
duringToolCallText: '検索中 ',
|
||||
afterToolCallText: '検索完了',
|
||||
aggregatedToolCallText: '検索完了'
|
||||
},
|
||||
footer: {
|
||||
selectText: '選択',
|
||||
submitQuestionText: '質問を送信',
|
||||
selectKeyAriaLabel: 'Enter キー',
|
||||
navigateText: '移動',
|
||||
navigateUpKeyAriaLabel: '上矢印キー',
|
||||
navigateDownKeyAriaLabel: '下矢印キー',
|
||||
closeText: '閉じる',
|
||||
backToSearchText: '検索に戻る',
|
||||
closeKeyAriaLabel: 'Esc キー',
|
||||
poweredByText: '提供: '
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
# アセットの取り扱い
|
||||
|
||||
## 静的アセットの参照
|
||||
|
||||
すべての Markdown ファイルは Vue コンポーネントにコンパイルされ、[Vite](https://vitejs.dev/guide/assets.html) によって処理されます。Markdown 内では、相対 URL を使ってアセットを参照することが **推奨されます**。
|
||||
|
||||
```md
|
||||

|
||||
```
|
||||
|
||||
Markdown ファイル内、テーマの `*.vue` コンポーネント内、スタイルや通常の `.css` ファイル内でも、アセットはプロジェクトルートを基準とした絶対パス、またはファイルシステムを基準とした相対パスで参照できます。後者は Vite、Vue CLI、あるいは webpack の `file-loader` を使ったことがある場合に慣れ親しんだ挙動です。
|
||||
|
||||
一般的な画像、メディア、フォントファイルタイプは自動的にアセットとして検出され、含まれます。
|
||||
|
||||
::: tip リンクされたファイルはアセットとして扱われません
|
||||
Markdown ファイル内のリンクで参照された PDF やその他のドキュメントは、自動的にアセットとして扱われません。これらのリンクファイルにアクセスできるようにするには、手動でプロジェクトの [`public`](#the-public-directory) ディレクトリに配置する必要があります。
|
||||
:::
|
||||
|
||||
絶対パスを含むすべての参照されたアセットは、プロダクションビルド時にハッシュ化されたファイル名で出力ディレクトリにコピーされます。参照されないアセットはコピーされません。4kb 未満の画像アセットは base64 としてインライン化されます(これは [`vite`](../reference/site-config#vite) 設定オプションで変更可能です)。
|
||||
|
||||
すべての **静的な** パス参照(絶対パスを含む)は、作業ディレクトリの構造を基準にする必要があります。
|
||||
|
||||
## Public ディレクトリ
|
||||
|
||||
Markdown やテーマコンポーネントで直接参照されない静的アセットを提供する必要がある場合や、特定のファイルをオリジナルのファイル名のまま提供したい場合があります。
|
||||
例えば `robots.txt`、favicon、PWA 用アイコンなどです。
|
||||
|
||||
これらのファイルは [ソースディレクトリ](./routing#source-directory) 配下の `public` ディレクトリに配置できます。たとえばプロジェクトルートが `./docs` で、デフォルトのソースディレクトリを使用している場合、`public` ディレクトリは `./docs/public` になります。
|
||||
|
||||
`public` に配置されたアセットは、出力ディレクトリのルートにそのままコピーされます。
|
||||
|
||||
なお、`public` 内のファイルはルート絶対パスで参照する必要があります。例えば `public/icon.png` は常に `/icon.png` として参照しなければなりません。
|
||||
|
||||
## ベース URL
|
||||
|
||||
サイトをルート以外の URL にデプロイする場合、`.vitepress/config.js` で `base` オプションを設定する必要があります。
|
||||
例えば `https://foo.github.io/bar/` にデプロイする場合、`base` は `'/bar/'` と設定します(必ずスラッシュで開始・終了する必要があります)。
|
||||
|
||||
すべての静的アセットパスは `base` 設定値に応じて自動的に調整されます。
|
||||
例えば Markdown 内で `public` 配下のアセットを絶対参照した場合:
|
||||
|
||||
```md
|
||||

|
||||
```
|
||||
|
||||
この場合は `base` の設定値を変更しても、参照を修正する必要はありません。
|
||||
|
||||
ただし、テーマコンポーネントで動的にアセットをリンクする場合(例:テーマ設定値に基づいた画像の `src`)は注意が必要です。
|
||||
|
||||
```vue
|
||||
<img :src="theme.logoPath" />
|
||||
```
|
||||
|
||||
この場合は、VitePress が提供する [`withBase` ヘルパー](../reference/runtime-api#withbase) でパスをラップすることを推奨します。
|
||||
|
||||
```vue
|
||||
<script setup>
|
||||
import { withBase, useData } from 'vitepress'
|
||||
|
||||
const { theme } = useData()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<img :src="withBase(theme.logoPath)" />
|
||||
</template>
|
||||
```
|
||||
@ -0,0 +1,212 @@
|
||||
# カスタムテーマを使う
|
||||
|
||||
## テーマの解決
|
||||
|
||||
カスタムテーマを有効にするには、`.vitepress/theme/index.js` または `.vitepress/theme/index.ts` ファイル(「テーマエントリファイル」)を作成します。
|
||||
|
||||
```
|
||||
.
|
||||
├─ docs # プロジェクトルート
|
||||
│ ├─ .vitepress
|
||||
│ │ ├─ theme
|
||||
│ │ │ └─ index.js # テーマエントリ
|
||||
│ │ └─ config.js # 設定ファイル
|
||||
│ └─ index.md
|
||||
└─ package.json
|
||||
```
|
||||
|
||||
VitePress はテーマエントリファイルを検出すると、常にデフォルトテーマではなくカスタムテーマを使用します。ただし、[デフォルトテーマを拡張](./extending-default-theme) してその上で高度なカスタマイズを行うことも可能です。
|
||||
|
||||
## テーマインターフェース
|
||||
|
||||
VitePress のカスタムテーマは次のインターフェースを持つオブジェクトとして定義されます。
|
||||
|
||||
```ts
|
||||
interface Theme {
|
||||
/**
|
||||
* すべてのページに適用されるルートレイアウトコンポーネント
|
||||
* @required
|
||||
*/
|
||||
Layout: Component
|
||||
/**
|
||||
* Vue アプリインスタンスを拡張
|
||||
* @optional
|
||||
*/
|
||||
enhanceApp?: (ctx: EnhanceAppContext) => Awaitable<void>
|
||||
/**
|
||||
* 別のテーマを拡張し、そのテーマの `enhanceApp` を先に実行
|
||||
* @optional
|
||||
*/
|
||||
extends?: Theme
|
||||
}
|
||||
|
||||
interface EnhanceAppContext {
|
||||
app: App // Vue アプリインスタンス
|
||||
router: Router // VitePress のルーターインスタンス
|
||||
siteData: Ref<SiteData> // サイト全体のメタデータ
|
||||
}
|
||||
```
|
||||
|
||||
テーマエントリファイルでは、このテーマをデフォルトエクスポートとして公開します。
|
||||
|
||||
```js [.vitepress/theme/index.js]
|
||||
|
||||
// テーマエントリでは Vue ファイルを直接インポートできます
|
||||
// VitePress は @vitejs/plugin-vue をあらかじめ設定済みです
|
||||
import Layout from './Layout.vue'
|
||||
|
||||
export default {
|
||||
Layout,
|
||||
enhanceApp({ app, router, siteData }) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
デフォルトエクスポートはカスタムテーマにおける唯一の契約であり、必須なのは `Layout` プロパティだけです。つまり、VitePress のテーマは単一の Vue コンポーネントでも成り立ちます。
|
||||
|
||||
レイアウトコンポーネントの内部は通常の Vite + Vue 3 アプリケーションと同じように動作します。なお、テーマは [SSR 対応](./ssr-compat) である必要があります。
|
||||
|
||||
## レイアウトの構築
|
||||
|
||||
最も基本的なレイアウトコンポーネントには [`<Content />`](../reference/runtime-api#content) コンポーネントを含める必要があります。
|
||||
|
||||
```vue [.vitepress/theme/Layout.vue]
|
||||
<template>
|
||||
<h1>Custom Layout!</h1>
|
||||
|
||||
<!-- この部分に markdown コンテンツが描画されます -->
|
||||
<Content />
|
||||
</template>
|
||||
```
|
||||
|
||||
上記のレイアウトは、すべてのページの Markdown を単純に HTML として描画します。最初の改善点として 404 エラー処理を追加できます。
|
||||
|
||||
```vue{1-4,9-12}
|
||||
<script setup>
|
||||
import { useData } from 'vitepress'
|
||||
const { page } = useData()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>Custom Layout!</h1>
|
||||
|
||||
<div v-if="page.isNotFound">
|
||||
Custom 404 page!
|
||||
</div>
|
||||
<Content v-else />
|
||||
</template>
|
||||
```
|
||||
|
||||
[`useData()`](../reference/runtime-api#usedata) ヘルパーを使うと、条件によってレイアウトを切り替えるために必要なすべてのランタイムデータを取得できます。アクセスできるデータのひとつにフロントマターがあります。これを利用すると、ページごとにレイアウトを制御できます。例えば、ユーザーが特別なホームページレイアウトを使いたい場合は以下のように記述します。
|
||||
|
||||
```md
|
||||
---
|
||||
layout: home
|
||||
---
|
||||
```
|
||||
|
||||
テーマ側を次のように調整します。
|
||||
|
||||
```vue{3,12-14}
|
||||
<script setup>
|
||||
import { useData } from 'vitepress'
|
||||
const { page, frontmatter } = useData()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>Custom Layout!</h1>
|
||||
|
||||
<div v-if="page.isNotFound">
|
||||
Custom 404 page!
|
||||
</div>
|
||||
<div v-if="frontmatter.layout === 'home'">
|
||||
Custom home page!
|
||||
</div>
|
||||
<Content v-else />
|
||||
</template>
|
||||
```
|
||||
|
||||
もちろんレイアウトをさらにコンポーネントに分割することもできます。
|
||||
|
||||
```vue{3-5,12-15}
|
||||
<script setup>
|
||||
import { useData } from 'vitepress'
|
||||
import NotFound from './NotFound.vue'
|
||||
import Home from './Home.vue'
|
||||
import Page from './Page.vue'
|
||||
|
||||
const { page, frontmatter } = useData()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>Custom Layout!</h1>
|
||||
|
||||
<NotFound v-if="page.isNotFound" />
|
||||
<Home v-if="frontmatter.layout === 'home'" />
|
||||
<Page v-else /> <!-- <Page /> が <Content /> を描画 -->
|
||||
</template>
|
||||
```
|
||||
|
||||
利用可能なすべての機能は [Runtime API リファレンス](../reference/runtime-api) を参照してください。さらに [ビルド時データ読み込み](./data-loading) を活用すれば、ブログ記事一覧ページのようなデータ駆動型のレイアウトも実現できます。
|
||||
|
||||
## カスタムテーマの配布
|
||||
|
||||
最も簡単な配布方法は [GitHub のテンプレートリポジトリ](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-template-repository) として提供することです。
|
||||
|
||||
npm パッケージとして配布する場合は、次の手順を踏みます。
|
||||
|
||||
1. パッケージエントリでテーマオブジェクトをデフォルトエクスポートとして公開する。
|
||||
2. 必要であればテーマ設定の型定義を `ThemeConfig` として公開する。
|
||||
3. テーマが VitePress 設定の調整を必要とする場合は、パッケージのサブパス(例:`my-theme/config`)としてその設定を公開し、ユーザーが拡張できるようにする。
|
||||
4. 設定ファイルやフロントマターを通じて、テーマ設定オプションを文書化する。
|
||||
5. テーマの利用方法を明確に説明する(以下を参照)。
|
||||
|
||||
## カスタムテーマの利用
|
||||
|
||||
外部テーマを利用するには、カスタムテーマエントリからインポートして再エクスポートします。
|
||||
|
||||
```js [.vitepress/theme/index.js]
|
||||
import Theme from 'awesome-vitepress-theme'
|
||||
|
||||
export default Theme
|
||||
```
|
||||
|
||||
テーマを拡張する必要がある場合:
|
||||
|
||||
```js [.vitepress/theme/index.js]
|
||||
import Theme from 'awesome-vitepress-theme'
|
||||
|
||||
export default {
|
||||
extends: Theme,
|
||||
enhanceApp(ctx) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
テーマが特別な VitePress 設定を必要とする場合は、設定ファイルも拡張する必要があります。
|
||||
|
||||
```ts [.vitepress/config.ts]
|
||||
import baseConfig from 'awesome-vitepress-theme/config'
|
||||
|
||||
export default {
|
||||
// 必要に応じてテーマの基本設定を拡張
|
||||
extends: baseConfig
|
||||
}
|
||||
```
|
||||
|
||||
テーマがテーマ設定用の型を提供している場合:
|
||||
|
||||
```ts [.vitepress/config.ts]
|
||||
import baseConfig from 'awesome-vitepress-theme/config'
|
||||
import { defineConfigWithTheme } from 'vitepress'
|
||||
import type { ThemeConfig } from 'awesome-vitepress-theme'
|
||||
|
||||
export default defineConfigWithTheme<ThemeConfig>({
|
||||
extends: baseConfig,
|
||||
themeConfig: {
|
||||
// 型は `ThemeConfig`
|
||||
}
|
||||
})
|
||||
```
|
||||
@ -0,0 +1,48 @@
|
||||
# フロントマター
|
||||
|
||||
## 使い方
|
||||
|
||||
VitePress はすべての Markdown ファイルで YAML フロントマターをサポートしており、[gray-matter](https://github.com/jonschlinkert/gray-matter) で解析します。フロントマターは Markdown ファイルの先頭(`<script>` タグを含むあらゆる要素より前)に配置し、三本のハイフンで囲まれた **有効な YAML** 形式で記述します。例:
|
||||
|
||||
```md
|
||||
---
|
||||
title: Docs with VitePress
|
||||
editLink: true
|
||||
---
|
||||
```
|
||||
|
||||
サイトやデフォルトテーマの多くの設定オプションには、フロントマター上で対応するオプションがあります。フロントマターを使うことで、**そのページに限って** 特定の振る舞いを上書きできます。詳細は [Frontmatter Config Reference](../reference/frontmatter-config) を参照してください。
|
||||
|
||||
また、独自のカスタムフロントマターデータを定義し、ページ上の動的な Vue 式で利用することもできます。
|
||||
|
||||
## フロントマターデータへのアクセス
|
||||
|
||||
フロントマターデータは特別なグローバル変数 `$frontmatter` で参照できます。
|
||||
|
||||
Markdown ファイル内での使用例:
|
||||
|
||||
```md
|
||||
---
|
||||
title: Docs with VitePress
|
||||
editLink: true
|
||||
---
|
||||
|
||||
# {{ $frontmatter.title }}
|
||||
|
||||
Guide content
|
||||
```
|
||||
|
||||
[`useData()`](../reference/runtime-api#usedata) ヘルパーを使えば、`<script setup>` 内からも現在のページのフロントマターデータにアクセスできます。
|
||||
|
||||
## 代替フロントマター形式
|
||||
|
||||
VitePress は JSON フロントマター構文もサポートしています。中括弧で開始・終了する形式です。
|
||||
|
||||
```json
|
||||
---
|
||||
{
|
||||
"title": "Blogging Like a Hacker",
|
||||
"editLink": true
|
||||
}
|
||||
---
|
||||
```
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,33 @@
|
||||
# VuePress からの移行
|
||||
|
||||
## 設定
|
||||
|
||||
### サイドバー
|
||||
|
||||
サイドバーはフロントマターから自動生成されなくなりました。サイドバーを動的に生成するには、[自分でフロントマターを読み取り](https://github.com/vuejs/vitepress/issues/572#issuecomment-1170116225)、項目を構築してください。将来的に、[この用途のユーティリティ](https://github.com/vuejs/vitepress/issues/96) が提供される可能性があります。
|
||||
|
||||
## Markdown
|
||||
|
||||
### 画像
|
||||
|
||||
VuePress と異なり、VitePress では静的画像を使用する場合、設定の [`base`](./asset-handling#base-url) を自動的に処理します。
|
||||
|
||||
そのため、`img` タグを使わずに画像をレンダリングできます。
|
||||
|
||||
```diff
|
||||
- <img :src="$withBase('/foo.png')" alt="foo">
|
||||
+ 
|
||||
```
|
||||
|
||||
::: warning
|
||||
動的な画像については、[ベース URL のガイド](./asset-handling#base-url) にあるとおり、引き続き `withBase` が必要です。
|
||||
:::
|
||||
|
||||
すべての `img` タグを `` 構文へ置換するには、次の正規表現を使って `` に置き換えてください。
|
||||
|
||||
- 検索:`<img.*withBase\('(.*)'\).*alt="([^"]*)".*>`
|
||||
- 置換:``
|
||||
|
||||
---
|
||||
|
||||
続きは今後追加予定です…
|
||||
@ -0,0 +1,58 @@
|
||||
# サイトマップ生成
|
||||
|
||||
VitePress には、サイト用の `sitemap.xml` を生成する機能が標準で用意されています。有効化するには、`.vitepress/config.js` に次を追加します。
|
||||
|
||||
```ts
|
||||
export default {
|
||||
sitemap: {
|
||||
hostname: 'https://example.com'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`siteamp.xml` に `<lastmod>` タグを含めるには、[`lastUpdated`](../reference/default-theme-last-updated) オプションを有効にします。
|
||||
|
||||
## オプション
|
||||
|
||||
サイトマップ生成は [`sitemap`](https://www.npmjs.com/package/sitemap) モジュールで行われます。設定ファイルの `sitemap` に、このモジュールがサポートする任意のオプションを渡せます。指定した値はそのまま `SitemapStream` コンストラクタに渡されます。詳しくは [`sitemap` のドキュメント](https://www.npmjs.com/package/sitemap#options-you-can-pass) を参照してください。例:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
sitemap: {
|
||||
hostname: 'https://example.com',
|
||||
lastmodDateOnly: false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
設定で `base` を使っている場合は、`hostname` にもそれを付与してください:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
base: '/my-site/',
|
||||
sitemap: {
|
||||
hostname: 'https://example.com/my-site/'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## `transformItems` フック
|
||||
|
||||
`siteamp.xml` に書き出す直前にサイトマップ項目を加工するには、`sitemap.transformItems` フックを使います。このフックはサイトマップ項目の配列を受け取り、配列を返す必要があります。例:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
sitemap: {
|
||||
hostname: 'https://example.com',
|
||||
transformItems: (items) => {
|
||||
// 既存項目の追加・変更・フィルタリングが可能
|
||||
items.push({
|
||||
url: '/extra-page',
|
||||
changefreq: 'monthly',
|
||||
priority: 0.8
|
||||
})
|
||||
return items
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -0,0 +1,35 @@
|
||||
---
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: VitePress
|
||||
text: Vite & Vue をベースにした静的サイトジェネレーター
|
||||
tagline: Markdown から美しいドキュメントを数分で
|
||||
actions:
|
||||
- theme: brand
|
||||
text: VitePress とは?
|
||||
link: /guide/what-is-vitepress
|
||||
- theme: alt
|
||||
text: クイックスタート
|
||||
link: /guide/getting-started
|
||||
- theme: alt
|
||||
text: GitHub
|
||||
link: https://github.com/vuejs/vitepress
|
||||
image:
|
||||
src: /vitepress-logo-large.svg
|
||||
alt: VitePress
|
||||
|
||||
features:
|
||||
- icon: 📝
|
||||
title: コンテンツに集中
|
||||
details: Markdown だけで、美しいドキュメントサイトを簡単に作成できます。
|
||||
- icon: <svg xmlns="http://www.w3.org/2000/svg" width="30" viewBox="0 0 256 256.32"><defs><linearGradient id="a" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"/><stop offset="100%" stop-color="#BD34FE"/></linearGradient><linearGradient id="b" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"/><stop offset="8.333%" stop-color="#FFDD35"/><stop offset="100%" stop-color="#FFA800"/></linearGradient></defs><path fill="url(#a)" d="M255.153 37.938 134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"/><path fill="url(#b)" d="M185.432.063 96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028 72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"/></svg>
|
||||
title: Vite の開発体験を享受
|
||||
details: 即時サーバー起動、超高速ホットリロード、そして Vite エコシステムのプラグイン活用。
|
||||
- icon: <svg xmlns="http://www.w3.org/2000/svg" width="30" viewBox="0 0 256 220.8"><path fill="#41B883" d="M204.8 0H256L128 220.8 0 0h97.92L128 51.2 157.44 0h47.36Z"/><path fill="#41B883" d="m0 0 128 220.8L256 0h-51.2L128 132.48 50.56 0H0Z"/><path fill="#35495E" d="M50.56 0 128 133.12 204.8 0h-47.36L128 51.2 97.92 0H50.56Z"/></svg>
|
||||
title: Vue でカスタマイズ
|
||||
details: Markdown 内で直接 Vue 構文やコンポーネントを利用したり、Vue で独自テーマを構築できます。
|
||||
- icon: 🚀
|
||||
title: 高速サイトを公開
|
||||
details: 静的 HTML による高速初期ロードと、クライアントサイドルーティングによる快適なページ遷移。
|
||||
---
|
||||
@ -0,0 +1,73 @@
|
||||
# Command Line Interface
|
||||
|
||||
## `vitepress dev`
|
||||
|
||||
Start VitePress dev server using designated directory as root. Defaults to current directory. The `dev` command can also be omitted when running in current directory.
|
||||
|
||||
### Usage
|
||||
|
||||
```sh
|
||||
# start in current directory, omitting `dev`
|
||||
vitepress
|
||||
|
||||
# start in sub directory
|
||||
vitepress dev [root]
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Description |
|
||||
| --------------- | ----------------------------------------------------------------- |
|
||||
| `--open [path]` | Open browser on startup (`boolean \| string`) |
|
||||
| `--port <port>` | Specify port (`number`) |
|
||||
| `--base <path>` | Public base path (default: `/`) (`string`) |
|
||||
| `--cors` | Enable CORS |
|
||||
| `--strictPort` | Exit if specified port is already in use (`boolean`) |
|
||||
| `--force` | Force the optimizer to ignore the cache and re-bundle (`boolean`) |
|
||||
|
||||
## `vitepress build`
|
||||
|
||||
Build the VitePress site for production.
|
||||
|
||||
### Usage
|
||||
|
||||
```sh
|
||||
vitepress build [root]
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Description |
|
||||
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- |
|
||||
| `--mpa` (experimental) | Build in [MPA mode](../guide/mpa-mode) without client-side hydration (`boolean`) |
|
||||
| `--base <path>` | Public base path (default: `/`) (`string`) |
|
||||
| `--target <target>` | Transpile target (default: `"modules"`) (`string`) |
|
||||
| `--outDir <dir>` | Output directory relative to **cwd** (default: `<root>/.vitepress/dist`) (`string`) |
|
||||
| `--assetsInlineLimit <number>` | Static asset base64 inline threshold in bytes (default: `4096`) (`number`) |
|
||||
|
||||
## `vitepress preview`
|
||||
|
||||
Locally preview the production build.
|
||||
|
||||
### Usage
|
||||
|
||||
```sh
|
||||
vitepress preview [root]
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Description |
|
||||
| --------------- | ------------------------------------------ |
|
||||
| `--base <path>` | Public base path (default: `/`) (`string`) |
|
||||
| `--port <port>` | Specify port (`number`) |
|
||||
|
||||
## `vitepress init`
|
||||
|
||||
Start the [Setup Wizard](../guide/getting-started#setup-wizard) in current directory.
|
||||
|
||||
### Usage
|
||||
|
||||
```sh
|
||||
vitepress init
|
||||
```
|
||||
@ -0,0 +1,69 @@
|
||||
# Badge
|
||||
|
||||
The badge lets you add status to your headers. For example, it could be useful to specify the section's type, or supported version.
|
||||
|
||||
## Usage
|
||||
|
||||
You may use the `Badge` component which is globally available.
|
||||
|
||||
```html
|
||||
### Title <Badge type="info" text="default" />
|
||||
### Title <Badge type="tip" text="^1.9.0" />
|
||||
### Title <Badge type="warning" text="beta" />
|
||||
### Title <Badge type="danger" text="caution" />
|
||||
```
|
||||
|
||||
Code above renders like:
|
||||
|
||||
### Title <Badge type="info" text="default" />
|
||||
### Title <Badge type="tip" text="^1.9.0" />
|
||||
### Title <Badge type="warning" text="beta" />
|
||||
### Title <Badge type="danger" text="caution" />
|
||||
|
||||
## Custom Children
|
||||
|
||||
`<Badge>` accept `children`, which will be displayed in the badge.
|
||||
|
||||
```html
|
||||
### Title <Badge type="info">custom element</Badge>
|
||||
```
|
||||
|
||||
### Title <Badge type="info">custom element</Badge>
|
||||
|
||||
## Customize Type Color
|
||||
|
||||
You can customize the style of badges by overriding css variables. The following are the default values:
|
||||
|
||||
```css
|
||||
:root {
|
||||
--vp-badge-info-border: transparent;
|
||||
--vp-badge-info-text: var(--vp-c-text-2);
|
||||
--vp-badge-info-bg: var(--vp-c-default-soft);
|
||||
|
||||
--vp-badge-tip-border: transparent;
|
||||
--vp-badge-tip-text: var(--vp-c-brand-1);
|
||||
--vp-badge-tip-bg: var(--vp-c-brand-soft);
|
||||
|
||||
--vp-badge-warning-border: transparent;
|
||||
--vp-badge-warning-text: var(--vp-c-warning-1);
|
||||
--vp-badge-warning-bg: var(--vp-c-warning-soft);
|
||||
|
||||
--vp-badge-danger-border: transparent;
|
||||
--vp-badge-danger-text: var(--vp-c-danger-1);
|
||||
--vp-badge-danger-bg: var(--vp-c-danger-soft);
|
||||
}
|
||||
```
|
||||
|
||||
## `<Badge>`
|
||||
|
||||
`<Badge>` component accepts following props:
|
||||
|
||||
```ts
|
||||
interface Props {
|
||||
// When `<slot>` is passed, this value gets ignored.
|
||||
text?: string
|
||||
|
||||
// Defaults to `tip`.
|
||||
type?: 'info' | 'tip' | 'warning' | 'danger'
|
||||
}
|
||||
```
|
||||
@ -0,0 +1,22 @@
|
||||
# Carbon Ads
|
||||
|
||||
VitePress has built in native support for [Carbon Ads](https://www.carbonads.net/). By defining the Carbon Ads credentials in config, VitePress will display ads on the page.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
carbonAds: {
|
||||
code: 'your-carbon-code',
|
||||
placement: 'your-carbon-placement'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
These values are used to call carbon CDN script as shown below.
|
||||
|
||||
```js
|
||||
`//cdn.carbonads.com/carbon.js?serve=${code}&placement=${placement}`
|
||||
```
|
||||
|
||||
To learn more about Carbon Ads configuration, please visit [Carbon Ads website](https://www.carbonads.net/).
|
||||
@ -0,0 +1,494 @@
|
||||
# Default Theme Config
|
||||
|
||||
Theme config lets you customize your theme. You can define theme config via the `themeConfig` option in the config file:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
lang: 'en-US',
|
||||
title: 'VitePress',
|
||||
description: 'Vite & Vue powered static site generator.',
|
||||
|
||||
// Theme related configurations.
|
||||
themeConfig: {
|
||||
logo: '/logo.svg',
|
||||
nav: [...],
|
||||
sidebar: { ... }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**The options documented on this page only apply to the default theme.** Different themes expect different theme config. When using a custom theme, the theme config object will be passed to the theme so the theme can define conditional behavior based on it.
|
||||
|
||||
## i18nRouting
|
||||
|
||||
- Type: `boolean`
|
||||
|
||||
Changing locale to say `zh` will change the URL from `/foo` (or `/en/foo/`) to `/zh/foo`. You can disable this behavior by setting `themeConfig.i18nRouting` to `false`.
|
||||
|
||||
## logo
|
||||
|
||||
- Type: `ThemeableImage`
|
||||
|
||||
Logo file to display in nav bar, right before the site title. Accepts a path string, or an object to set a different logo for light/dark mode.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
logo: '/logo.svg'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
type ThemeableImage =
|
||||
| string
|
||||
| { src: string; alt?: string }
|
||||
| { light: string; dark: string; alt?: string }
|
||||
```
|
||||
|
||||
## siteTitle
|
||||
|
||||
- Type: `string | false`
|
||||
|
||||
You can customize this item to replace the default site title (`title` in app config) in nav. When set to `false`, title in nav will be disabled. Useful when you have `logo` that already contains the site title text.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
siteTitle: 'Hello World'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## nav
|
||||
|
||||
- Type: `NavItem`
|
||||
|
||||
The configuration for the nav menu item. More details in [Default Theme: Nav](./default-theme-nav#navigation-links).
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{ text: 'Guide', link: '/guide' },
|
||||
{
|
||||
text: 'Dropdown Menu',
|
||||
items: [
|
||||
{ text: 'Item A', link: '/item-1' },
|
||||
{ text: 'Item B', link: '/item-2' },
|
||||
{ text: 'Item C', link: '/item-3' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
type NavItem = NavItemWithLink | NavItemWithChildren
|
||||
|
||||
interface NavItemWithLink {
|
||||
text: string
|
||||
link: string | ((payload: PageData) => string)
|
||||
activeMatch?: string
|
||||
target?: string
|
||||
rel?: string
|
||||
noIcon?: boolean
|
||||
}
|
||||
|
||||
interface NavItemChildren {
|
||||
text?: string
|
||||
items: NavItemWithLink[]
|
||||
}
|
||||
|
||||
interface NavItemWithChildren {
|
||||
text?: string
|
||||
items: (NavItemChildren | NavItemWithLink)[]
|
||||
activeMatch?: string
|
||||
}
|
||||
```
|
||||
|
||||
## sidebar
|
||||
|
||||
- Type: `Sidebar`
|
||||
|
||||
The configuration for the sidebar menu item. More details in [Default Theme: Sidebar](./default-theme-sidebar).
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
sidebar: [
|
||||
{
|
||||
text: 'Guide',
|
||||
items: [
|
||||
{ text: 'Introduction', link: '/introduction' },
|
||||
{ text: 'Getting Started', link: '/getting-started' },
|
||||
...
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
export type Sidebar = SidebarItem[] | SidebarMulti
|
||||
|
||||
export interface SidebarMulti {
|
||||
[path: string]: SidebarItem[] | { items: SidebarItem[]; base: string }
|
||||
}
|
||||
|
||||
export type SidebarItem = {
|
||||
/**
|
||||
* The text label of the item.
|
||||
*/
|
||||
text?: string
|
||||
|
||||
/**
|
||||
* The link of the item.
|
||||
*/
|
||||
link?: string
|
||||
|
||||
/**
|
||||
* The children of the item.
|
||||
*/
|
||||
items?: SidebarItem[]
|
||||
|
||||
/**
|
||||
* If not specified, group is not collapsible.
|
||||
*
|
||||
* If `true`, group is collapsible and collapsed by default
|
||||
*
|
||||
* If `false`, group is collapsible but expanded by default
|
||||
*/
|
||||
collapsed?: boolean
|
||||
|
||||
/**
|
||||
* Base path for the children items.
|
||||
*/
|
||||
base?: string
|
||||
|
||||
/**
|
||||
* Customize text that appears on the footer of previous/next page.
|
||||
*/
|
||||
docFooterText?: string
|
||||
|
||||
rel?: string
|
||||
target?: string
|
||||
}
|
||||
```
|
||||
|
||||
## aside
|
||||
|
||||
- Type: `boolean | 'left'`
|
||||
- Default: `true`
|
||||
- Can be overridden per page via [frontmatter](./frontmatter-config#aside)
|
||||
|
||||
Setting this value to `false` prevents rendering of aside container.\
|
||||
Setting this value to `true` renders the aside to the right.\
|
||||
Setting this value to `left` renders the aside to the left.
|
||||
|
||||
If you want to disable it for all viewports, you should use `outline: false` instead.
|
||||
|
||||
## outline
|
||||
|
||||
- Type: `Outline | Outline['level'] | false`
|
||||
- Level can be overridden per page via [frontmatter](./frontmatter-config#outline)
|
||||
|
||||
Setting this value to `false` prevents rendering of outline container. Refer this interface for more details:
|
||||
|
||||
```ts
|
||||
interface Outline {
|
||||
/**
|
||||
* The levels of headings to be displayed in the outline.
|
||||
* Single number means only headings of that level will be displayed.
|
||||
* If a tuple is passed, the first number is the minimum level and the second number is the maximum level.
|
||||
* `'deep'` is same as `[2, 6]`, which means all headings from `<h2>` to `<h6>` will be displayed.
|
||||
*
|
||||
* @default 2
|
||||
*/
|
||||
level?: number | [number, number] | 'deep'
|
||||
|
||||
/**
|
||||
* The title to be displayed on the outline.
|
||||
*
|
||||
* @default 'On this page'
|
||||
*/
|
||||
label?: string
|
||||
}
|
||||
```
|
||||
|
||||
## socialLinks
|
||||
|
||||
- Type: `SocialLink[]`
|
||||
|
||||
You may define this option to show your social account links with icons in nav.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
socialLinks: [
|
||||
// You can add any icon from simple-icons (https://simpleicons.org/):
|
||||
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
|
||||
{ icon: 'twitter', link: '...' },
|
||||
// You can also add custom icons by passing SVG as string:
|
||||
{
|
||||
icon: {
|
||||
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Dribbble</title><path d="M12...6.38z"/></svg>'
|
||||
},
|
||||
link: '...',
|
||||
// You can include a custom label for accessibility too (optional but recommended):
|
||||
ariaLabel: 'cool link'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
interface SocialLink {
|
||||
icon: string | { svg: string }
|
||||
link: string
|
||||
ariaLabel?: string
|
||||
}
|
||||
```
|
||||
|
||||
## footer
|
||||
|
||||
- Type: `Footer`
|
||||
- Can be overridden per page via [frontmatter](./frontmatter-config#footer)
|
||||
|
||||
Footer configuration. You can add a message or copyright text on the footer, however, it will only be displayed when the page doesn't contain a sidebar. This is due to design concerns.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
footer: {
|
||||
message: 'Released under the MIT License.',
|
||||
copyright: 'Copyright © 2019-present Evan You'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
export interface Footer {
|
||||
message?: string
|
||||
copyright?: string
|
||||
}
|
||||
```
|
||||
|
||||
## editLink
|
||||
|
||||
- Type: `EditLink`
|
||||
- Can be overridden per page via [frontmatter](./frontmatter-config#editlink)
|
||||
|
||||
Edit Link lets you display a link to edit the page on Git management services such as GitHub, or GitLab. See [Default Theme: Edit Link](./default-theme-edit-link) for more details.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
editLink: {
|
||||
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path',
|
||||
text: 'Edit this page on GitHub'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
export interface EditLink {
|
||||
pattern: string
|
||||
text?: string
|
||||
}
|
||||
```
|
||||
|
||||
## lastUpdated
|
||||
|
||||
- Type: `LastUpdatedOptions`
|
||||
|
||||
Allows customization for the last updated text and date format.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
lastUpdated: {
|
||||
text: 'Updated at',
|
||||
formatOptions: {
|
||||
dateStyle: 'full',
|
||||
timeStyle: 'medium'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
export interface LastUpdatedOptions {
|
||||
/**
|
||||
* @default 'Last updated'
|
||||
*/
|
||||
text?: string
|
||||
|
||||
/**
|
||||
* @default
|
||||
* { dateStyle: 'short', timeStyle: 'short' }
|
||||
*/
|
||||
formatOptions?: Intl.DateTimeFormatOptions & { forceLocale?: boolean }
|
||||
}
|
||||
```
|
||||
|
||||
## algolia
|
||||
|
||||
- Type: `AlgoliaSearch`
|
||||
|
||||
An option to support searching your docs site using [Algolia DocSearch](https://docsearch.algolia.com/docs/what-is-docsearch). Learn more in [Default Theme: Search](./default-theme-search)
|
||||
|
||||
```ts
|
||||
export interface AlgoliaSearchOptions extends DocSearchProps {
|
||||
locales?: Record<string, Partial<DocSearchProps>>
|
||||
}
|
||||
```
|
||||
|
||||
View full options [here](https://github.com/vuejs/vitepress/blob/main/types/docsearch.d.ts).
|
||||
|
||||
## carbonAds {#carbon-ads}
|
||||
|
||||
- Type: `CarbonAdsOptions`
|
||||
|
||||
An option to display [Carbon Ads](https://www.carbonads.net/).
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
carbonAds: {
|
||||
code: 'your-carbon-code',
|
||||
placement: 'your-carbon-placement'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
export interface CarbonAdsOptions {
|
||||
code: string
|
||||
placement: string
|
||||
}
|
||||
```
|
||||
|
||||
Learn more in [Default Theme: Carbon Ads](./default-theme-carbon-ads)
|
||||
|
||||
## docFooter
|
||||
|
||||
- Type: `DocFooter`
|
||||
|
||||
Can be used to customize text appearing above previous and next links. Helpful if not writing docs in English. Also can be used to disable prev/next links globally. If you want to selectively enable/disable prev/next links, you can use [frontmatter](./default-theme-prev-next-links).
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
docFooter: {
|
||||
prev: 'Pagina prior',
|
||||
next: 'Proxima pagina'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
export interface DocFooter {
|
||||
prev?: string | false
|
||||
next?: string | false
|
||||
}
|
||||
```
|
||||
|
||||
## darkModeSwitchLabel
|
||||
|
||||
- Type: `string`
|
||||
- Default: `Appearance`
|
||||
|
||||
Can be used to customize the dark mode switch label. This label is only displayed in the mobile view.
|
||||
|
||||
## lightModeSwitchTitle
|
||||
|
||||
- Type: `string`
|
||||
- Default: `Switch to light theme`
|
||||
|
||||
Can be used to customize the light mode switch title that appears on hovering.
|
||||
|
||||
## darkModeSwitchTitle
|
||||
|
||||
- Type: `string`
|
||||
- Default: `Switch to dark theme`
|
||||
|
||||
Can be used to customize the dark mode switch title that appears on hovering.
|
||||
|
||||
## sidebarMenuLabel
|
||||
|
||||
- Type: `string`
|
||||
- Default: `Menu`
|
||||
|
||||
Can be used to customize the sidebar menu label. This label is only displayed in the mobile view.
|
||||
|
||||
## returnToTopLabel
|
||||
|
||||
- Type: `string`
|
||||
- Default: `Return to top`
|
||||
|
||||
Can be used to customize the label of the return to top button. This label is only displayed in the mobile view.
|
||||
|
||||
## langMenuLabel
|
||||
|
||||
- Type: `string`
|
||||
- Default: `Change language`
|
||||
|
||||
Can be used to customize the aria-label of the language toggle button in navbar. This is only used if you're using [i18n](../guide/i18n).
|
||||
|
||||
## skipToContentLabel
|
||||
|
||||
- Type: `string`
|
||||
- Default: `Skip to content`
|
||||
|
||||
Can be used to customize the label of the skip to content link. This link is shown when the user is navigating the site using a keyboard.
|
||||
|
||||
## externalLinkIcon
|
||||
|
||||
- Type: `boolean`
|
||||
- Default: `false`
|
||||
|
||||
Whether to show an external link icon next to external links in markdown.
|
||||
|
||||
## `useLayout` <Badge type="info" text="composable" />
|
||||
|
||||
Returns layout-related data. The returned object has the following type:
|
||||
|
||||
```ts
|
||||
interface {
|
||||
isHome: ComputedRef<boolean>
|
||||
|
||||
sidebar: Readonly<ShallowRef<DefaultTheme.SidebarItem[]>>
|
||||
sidebarGroups: ComputedRef<DefaultTheme.SidebarItem[]>
|
||||
hasSidebar: ComputedRef<boolean>
|
||||
isSidebarEnabled: ComputedRef<boolean>
|
||||
|
||||
hasAside: ComputedRef<boolean>
|
||||
leftAside: ComputedRef<boolean>
|
||||
|
||||
headers: Readonly<ShallowRef<DefaultTheme.OutlineItem[]>>
|
||||
hasLocalNav: ComputedRef<boolean>
|
||||
}
|
||||
```
|
||||
|
||||
**Example:**
|
||||
|
||||
```vue
|
||||
<script setup>
|
||||
import { useLayout } from 'vitepress/theme'
|
||||
|
||||
const { hasSidebar } = useLayout()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="hasSidebar">Only show when sidebar exists</div>
|
||||
</template>
|
||||
```
|
||||
@ -0,0 +1,60 @@
|
||||
# Edit Link
|
||||
|
||||
## Site-Level Config
|
||||
|
||||
Edit Link lets you display a link to edit the page on Git management services such as GitHub, or GitLab. To enable it, add `themeConfig.editLink` options to your config.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
editLink: {
|
||||
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `pattern` option defines the URL structure for the link, and `:path` is going to be replaced with the page path.
|
||||
|
||||
You can also put a pure function that accepts [`PageData`](./runtime-api#usedata) as the argument and returns the URL string.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
editLink: {
|
||||
pattern: ({ filePath }) => {
|
||||
if (filePath.startsWith('packages/')) {
|
||||
return `https://github.com/acme/monorepo/edit/main/${filePath}`
|
||||
} else {
|
||||
return `https://github.com/acme/monorepo/edit/main/docs/${filePath}`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
It should not have side-effects nor access anything outside of its scope since it will be serialized and executed in the browser.
|
||||
|
||||
By default, this will add the link text "Edit this page" at the bottom of the doc page. You may customize this text by defining the `text` option.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
editLink: {
|
||||
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path',
|
||||
text: 'Edit this page on GitHub'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Frontmatter Config
|
||||
|
||||
This can be disabled per-page using the `editLink` option on frontmatter:
|
||||
|
||||
```yaml
|
||||
---
|
||||
editLink: false
|
||||
---
|
||||
```
|
||||
@ -0,0 +1,53 @@
|
||||
# Footer
|
||||
|
||||
VitePress will display global footer at the bottom of the page when `themeConfig.footer` is present.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
footer: {
|
||||
message: 'Released under the MIT License.',
|
||||
copyright: 'Copyright © 2019-present Evan You'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
export interface Footer {
|
||||
// The message shown right before copyright.
|
||||
message?: string
|
||||
|
||||
// The actual copyright text.
|
||||
copyright?: string
|
||||
}
|
||||
```
|
||||
|
||||
The above configuration also supports HTML strings. So, for example, if you want to configure footer text to have some links, you can adjust the configuration as follows:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
themeConfig: {
|
||||
footer: {
|
||||
message: 'Released under the <a href="https://github.com/vuejs/vitepress/blob/main/LICENSE">MIT License</a>.',
|
||||
copyright: 'Copyright © 2019-present <a href="https://github.com/yyx990803">Evan You</a>'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
::: warning
|
||||
Only inline elements can be used in `message` and `copyright` as they are rendered inside a `<p>` element. If you want to add block elements, consider using [`layout-bottom`](../guide/extending-default-theme#layout-slots) slot instead.
|
||||
:::
|
||||
|
||||
Note that footer will not be displayed when the [SideBar](./default-theme-sidebar) is visible.
|
||||
|
||||
## Frontmatter Config
|
||||
|
||||
This can be disabled per-page using the `footer` option on frontmatter:
|
||||
|
||||
```yaml
|
||||
---
|
||||
footer: false
|
||||
---
|
||||
```
|
||||
@ -0,0 +1,195 @@
|
||||
# Home Page
|
||||
|
||||
VitePress default theme provides a homepage layout, which you can also see used on [the homepage of this site](../). You may use it on any of your pages by specifying `layout: home` in the [frontmatter](./frontmatter-config).
|
||||
|
||||
```yaml
|
||||
---
|
||||
layout: home
|
||||
---
|
||||
```
|
||||
|
||||
However, this option alone wouldn't do much. You can add several different pre templated "sections" to the homepage by setting additional other options such as `hero` and `features`.
|
||||
|
||||
## Hero Section
|
||||
|
||||
The Hero section comes at the top of the homepage. Here's how you can configure the Hero section.
|
||||
|
||||
```yaml
|
||||
---
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: VitePress
|
||||
text: Vite & Vue powered static site generator.
|
||||
tagline: Lorem ipsum...
|
||||
image:
|
||||
src: /logo.png
|
||||
alt: VitePress
|
||||
actions:
|
||||
- theme: brand
|
||||
text: Get Started
|
||||
link: /guide/what-is-vitepress
|
||||
- theme: alt
|
||||
text: View on GitHub
|
||||
link: https://github.com/vuejs/vitepress
|
||||
---
|
||||
```
|
||||
|
||||
```ts
|
||||
interface Hero {
|
||||
// The string shown top of `text`. Comes with brand color
|
||||
// and expected to be short, such as product name.
|
||||
name?: string
|
||||
|
||||
// The main text for the hero section. This will be defined
|
||||
// as `h1` tag.
|
||||
text: string
|
||||
|
||||
// Tagline displayed below `text`.
|
||||
tagline?: string
|
||||
|
||||
// The image is displayed next to the text and tagline area.
|
||||
image?: ThemeableImage
|
||||
|
||||
// Action buttons to display in home hero section.
|
||||
actions?: HeroAction[]
|
||||
}
|
||||
|
||||
type ThemeableImage =
|
||||
| string
|
||||
| { src: string; alt?: string }
|
||||
| { light: string; dark: string; alt?: string }
|
||||
|
||||
interface HeroAction {
|
||||
// Color theme of the button. Defaults to `brand`.
|
||||
theme?: 'brand' | 'alt'
|
||||
|
||||
// Label of the button.
|
||||
text: string
|
||||
|
||||
// Destination link of the button.
|
||||
link: string
|
||||
|
||||
// Link target attribute.
|
||||
target?: string
|
||||
|
||||
// Link rel attribute.
|
||||
rel?: string
|
||||
}
|
||||
```
|
||||
|
||||
### Customizing the name color
|
||||
|
||||
VitePress uses the brand color (`--vp-c-brand-1`) for the `name`. However, you may customize this color by overriding `--vp-home-hero-name-color` variable.
|
||||
|
||||
```css
|
||||
:root {
|
||||
--vp-home-hero-name-color: blue;
|
||||
}
|
||||
```
|
||||
|
||||
Also you may customize it further by combining `--vp-home-hero-name-background` to give the `name` gradient color.
|
||||
|
||||
```css
|
||||
:root {
|
||||
--vp-home-hero-name-color: transparent;
|
||||
--vp-home-hero-name-background: -webkit-linear-gradient(120deg, #bd34fe, #41d1ff);
|
||||
}
|
||||
```
|
||||
|
||||
## Features Section
|
||||
|
||||
In Features section, you can list any number of features you would like to show right after the Hero section. To configure it, pass `features` option to the frontmatter.
|
||||
|
||||
You can provide an icon for each feature, which can be an emoji or any type of image. When the configured icon is an image (svg, png, jpeg...), you must provide the icon with the proper width and height; you can also provide the description, its intrinsic size as well as its variants for dark and light theme when required.
|
||||
|
||||
```yaml
|
||||
---
|
||||
layout: home
|
||||
|
||||
features:
|
||||
- icon: 🛠️
|
||||
title: Simple and minimal, always
|
||||
details: Lorem ipsum...
|
||||
- icon:
|
||||
src: /cool-feature-icon.svg
|
||||
title: Another cool feature
|
||||
details: Lorem ipsum...
|
||||
- icon:
|
||||
dark: /dark-feature-icon.svg
|
||||
light: /light-feature-icon.svg
|
||||
title: Another cool feature
|
||||
details: Lorem ipsum...
|
||||
---
|
||||
```
|
||||
|
||||
```ts
|
||||
interface Feature {
|
||||
// Show icon on each feature box.
|
||||
icon?: FeatureIcon
|
||||
|
||||
// Title of the feature.
|
||||
title: string
|
||||
|
||||
// Details of the feature.
|
||||
details: string
|
||||
|
||||
// Link when clicked on feature component. The link can
|
||||
// be both internal or external.
|
||||
//
|
||||
// e.g. `guide/reference/default-theme-home-page` or `https://example.com`
|
||||
link?: string
|
||||
|
||||
// Link text to be shown inside feature component. Best
|
||||
// used with `link` option.
|
||||
//
|
||||
// e.g. `Learn more`, `Visit page`, etc.
|
||||
linkText?: string
|
||||
|
||||
// Link rel attribute for the `link` option.
|
||||
//
|
||||
// e.g. `external`
|
||||
rel?: string
|
||||
|
||||
// Link target attribute for the `link` option.
|
||||
target?: string
|
||||
}
|
||||
|
||||
type FeatureIcon =
|
||||
| string
|
||||
| { src: string; alt?: string; width?: string; height: string }
|
||||
| {
|
||||
light: string
|
||||
dark: string
|
||||
alt?: string
|
||||
width?: string
|
||||
height: string
|
||||
}
|
||||
```
|
||||
|
||||
## Markdown Content
|
||||
|
||||
You can add additional content to your site's homepage just by adding Markdown below the `---` frontmatter divider.
|
||||
|
||||
````md
|
||||
---
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: VitePress
|
||||
text: Vite & Vue powered static site generator.
|
||||
---
|
||||
|
||||
## Getting Started
|
||||
|
||||
You can get started using VitePress right away using `npx`!
|
||||
|
||||
```sh
|
||||
npm init
|
||||
npx vitepress init
|
||||
```
|
||||
````
|
||||
|
||||
::: info
|
||||
VitePress didn't always auto-style the extra content of the `layout: home` page. To revert to older behavior, you can add `markdownStyles: false` to the frontmatter.
|
||||
:::
|
||||
@ -0,0 +1,46 @@
|
||||
# Last Updated
|
||||
|
||||
The update time of the last content will be displayed in the lower right corner of the page. To enable it, add `lastUpdated` options to your config.
|
||||
|
||||
::: info
|
||||
VitePress displays the "last updated" time using the timestamp of the most recent Git commit for each file. To enable this, the Markdown file must be committed to Git.
|
||||
|
||||
Internally, VitePress runs `git log -1 --pretty="%ai"` on each file to retrieve its timestamp. If all pages show the same update time, it's likely due to shallow cloning (common in CI environments), which limits Git history.
|
||||
|
||||
To fix this in **GitHub Actions**, use the following in your workflow:
|
||||
|
||||
```yaml{4}
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
```
|
||||
|
||||
Other CI/CD platforms have similar settings.
|
||||
|
||||
If such options aren't available, you can prepend the `docs:build` command in your `package.json` with a manual fetch:
|
||||
|
||||
```json
|
||||
"docs:build": "git fetch --unshallow && vitepress build docs"
|
||||
```
|
||||
:::
|
||||
|
||||
## Site-Level Config
|
||||
|
||||
```js
|
||||
export default {
|
||||
lastUpdated: true
|
||||
}
|
||||
```
|
||||
|
||||
## Frontmatter Config
|
||||
|
||||
This can be disabled per-page using the `lastUpdated` option on frontmatter:
|
||||
|
||||
```yaml
|
||||
---
|
||||
lastUpdated: false
|
||||
---
|
||||
```
|
||||
|
||||
Also refer [Default Theme: Last Updated](./default-theme-config#lastupdated) for more details. Any truthy value at theme-level will also enable the feature unless explicitly disabled at site or page level.
|
||||
@ -0,0 +1,62 @@
|
||||
# Layout
|
||||
|
||||
You may choose the page layout by setting `layout` option to the page [frontmatter](./frontmatter-config). There are 3 layout options, `doc`, `page`, and `home`. If nothing is specified, then the page is treated as `doc` page.
|
||||
|
||||
```yaml
|
||||
---
|
||||
layout: doc
|
||||
---
|
||||
```
|
||||
|
||||
## Doc Layout
|
||||
|
||||
Option `doc` is the default layout and it styles the whole Markdown content into "documentation" look. It works by wrapping whole content within `vp-doc` css class, and applying styles to elements underneath it.
|
||||
|
||||
Almost all generic elements such as `p`, or `h2` get special styling. Therefore, keep in mind that if you add any custom HTML inside a Markdown content, those will get affected by those styles as well.
|
||||
|
||||
It also provides documentation specific features listed below. These features are only enabled in this layout.
|
||||
|
||||
- Edit Link
|
||||
- Prev Next Link
|
||||
- Outline
|
||||
- [Carbon Ads](./default-theme-carbon-ads)
|
||||
|
||||
## Page Layout
|
||||
|
||||
Option `page` is treated as "blank page". The Markdown will still be parsed, and all of the [Markdown Extensions](../guide/markdown) work as same as `doc` layout, but it wouldn't get any default stylings.
|
||||
|
||||
The page layout will let you style everything by you without VitePress theme affecting the markup. This is useful when you want to create your own custom page.
|
||||
|
||||
Note that even in this layout, sidebar will still show up if the page has a matching sidebar config.
|
||||
|
||||
## Home Layout
|
||||
|
||||
Option `home` will generate templated "Homepage". In this layout, you can set extra options such as `hero` and `features` to customize the content further. Please visit [Default Theme: Home Page](./default-theme-home-page) for more details.
|
||||
|
||||
## No Layout
|
||||
|
||||
If you don't want any layout, you can pass `layout: false` through frontmatter. This option is helpful if you want a fully-customizable landing page (without any sidebar, navbar, or footer by default).
|
||||
|
||||
## Custom Layout
|
||||
|
||||
You can also use a custom layout:
|
||||
|
||||
```md
|
||||
---
|
||||
layout: foo
|
||||
---
|
||||
```
|
||||
|
||||
This will look for a component named `foo` registered in context. For example, you can register your component globally in `.vitepress/theme/index.ts`:
|
||||
|
||||
```ts
|
||||
import DefaultTheme from 'vitepress/theme'
|
||||
import Foo from './Foo.vue'
|
||||
|
||||
export default {
|
||||
extends: DefaultTheme,
|
||||
enhanceApp({ app }) {
|
||||
app.component('foo', Foo)
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -0,0 +1,216 @@
|
||||
# Nav
|
||||
|
||||
The Nav is the navigation bar displayed on top of the page. It contains the site title, global menu links, etc.
|
||||
|
||||
## Site Title and Logo
|
||||
|
||||
By default, nav shows the title of the site referencing [`config.title`](./site-config#title) value. If you would like to change what's displayed on nav, you may define custom text in `themeConfig.siteTitle` option.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
siteTitle: 'My Custom Title'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If you have a logo for your site, you can display it by passing in the path to the image. You should place the logo within `public` directly, and define the absolute path to it.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
logo: '/my-logo.svg'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
When adding a logo, it gets displayed along with the site title. If your logo is all you need and if you would like to hide the site title text, set `false` to the `siteTitle` option.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
logo: '/my-logo.svg',
|
||||
siteTitle: false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can also pass an object as logo if you want to add `alt` attribute or customize it based on dark/light mode. Refer [`themeConfig.logo`](./default-theme-config#logo) for details.
|
||||
|
||||
## Navigation Links
|
||||
|
||||
You may define `themeConfig.nav` option to add links to your nav.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{ text: 'Guide', link: '/guide' },
|
||||
{ text: 'Config', link: '/config' },
|
||||
{ text: 'Changelog', link: 'https://github.com/...' }
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `text` is the actual text displayed in nav, and the `link` is the link that will be navigated to when the text is clicked. For the link, set path to the actual file without `.md` prefix, and always start with `/`.
|
||||
|
||||
The `link` can also be a function that accepts [`PageData`](./runtime-api#usedata) as the argument and returns the path.
|
||||
|
||||
Nav links can also be dropdown menus. To do this, set `items` key on link option.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{ text: 'Guide', link: '/guide' },
|
||||
{
|
||||
text: 'Dropdown Menu',
|
||||
items: [
|
||||
{ text: 'Item A', link: '/item-1' },
|
||||
{ text: 'Item B', link: '/item-2' },
|
||||
{ text: 'Item C', link: '/item-3' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note that dropdown menu title (`Dropdown Menu` in the above example) can not have `link` property since it becomes a button to open dropdown dialog.
|
||||
|
||||
You may further add "sections" to the dropdown menu items as well by passing in more nested items.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{ text: 'Guide', link: '/guide' },
|
||||
{
|
||||
text: 'Dropdown Menu',
|
||||
items: [
|
||||
{
|
||||
// Title for the section.
|
||||
text: 'Section A Title',
|
||||
items: [
|
||||
{ text: 'Section A Item A', link: '...' },
|
||||
{ text: 'Section B Item B', link: '...' }
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
text: 'Dropdown Menu',
|
||||
items: [
|
||||
{
|
||||
// You may also omit the title.
|
||||
items: [
|
||||
{ text: 'Section A Item A', link: '...' },
|
||||
{ text: 'Section B Item B', link: '...' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Customize link's "active" state
|
||||
|
||||
Nav menu items will be highlighted when the current page is under the matching path. if you would like to customize the path to be matched, define `activeMatch` property and regex as a string value.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
nav: [
|
||||
// This link gets active state when the user is
|
||||
// on `/config/` path.
|
||||
{
|
||||
text: 'Guide',
|
||||
link: '/guide',
|
||||
activeMatch: '/config/'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
::: warning
|
||||
`activeMatch` is expected to be a regex string, but you must define it as a string. We can't use actual RegExp object here because it isn't serializable during the build time.
|
||||
:::
|
||||
|
||||
### Customize link's "target" and "rel" attributes
|
||||
|
||||
By default, VitePress automatically determines `target` and `rel` attributes based on whether the link is an external link. But if you want, you can customize them too.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{
|
||||
text: 'Merchandise',
|
||||
link: 'https://www.thegithubshop.com/',
|
||||
target: '_self',
|
||||
rel: 'sponsored'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Social Links
|
||||
|
||||
Refer [`socialLinks`](./default-theme-config#sociallinks).
|
||||
|
||||
## Custom Components
|
||||
|
||||
You can include custom components in the navigation bar by using the `component` option. The `component` key should be the Vue component name, and must be registered globally using [Theme.enhanceApp](../guide/custom-theme#theme-interface).
|
||||
|
||||
```js [.vitepress/config.js]
|
||||
export default {
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{
|
||||
text: 'My Menu',
|
||||
items: [
|
||||
{
|
||||
component: 'MyCustomComponent',
|
||||
// Optional props to pass to the component
|
||||
props: {
|
||||
title: 'My Custom Component'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
component: 'AnotherCustomComponent'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then, you need to register the component globally:
|
||||
|
||||
```js [.vitepress/theme/index.js]
|
||||
import DefaultTheme from 'vitepress/theme'
|
||||
|
||||
import MyCustomComponent from './components/MyCustomComponent.vue'
|
||||
import AnotherCustomComponent from './components/AnotherCustomComponent.vue'
|
||||
|
||||
/** @type {import('vitepress').Theme} */
|
||||
export default {
|
||||
extends: DefaultTheme,
|
||||
enhanceApp({ app }) {
|
||||
app.component('MyCustomComponent', MyCustomComponent)
|
||||
app.component('AnotherCustomComponent', AnotherCustomComponent)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Your component will be rendered in the navigation bar. VitePress will provide the following additional props to the component:
|
||||
|
||||
- `screenMenu`: an optional boolean indicating whether the component is inside mobile navigation menu
|
||||
|
||||
You can check an example in the e2e tests [here](https://github.com/vuejs/vitepress/tree/main/__tests__/e2e/.vitepress).
|
||||
@ -0,0 +1,43 @@
|
||||
# Prev Next Links
|
||||
|
||||
You can customize the text and link for the previous and next pages (shown at doc footer). This is helpful if you want a different text there than what you have on your sidebar. Additionally, you may find it useful to disable the footer or link to a page that is not included in your sidebar.
|
||||
|
||||
## prev
|
||||
|
||||
- Type: `string | false | { text?: string; link?: string }`
|
||||
|
||||
- Details:
|
||||
|
||||
Specifies the text/link to show on the link to the previous page. If you don't set this in frontmatter, the text/link will be inferred from the sidebar config.
|
||||
|
||||
- Examples:
|
||||
|
||||
- To customize only the text:
|
||||
|
||||
```yaml
|
||||
---
|
||||
prev: 'Get Started | Markdown'
|
||||
---
|
||||
```
|
||||
|
||||
- To customize both text and link:
|
||||
|
||||
```yaml
|
||||
---
|
||||
prev:
|
||||
text: 'Markdown'
|
||||
link: '/guide/markdown'
|
||||
---
|
||||
```
|
||||
|
||||
- To hide previous page:
|
||||
|
||||
```yaml
|
||||
---
|
||||
prev: false
|
||||
---
|
||||
```
|
||||
|
||||
## next
|
||||
|
||||
Same as `prev` but for the next page.
|
||||
@ -0,0 +1,182 @@
|
||||
# Sidebar
|
||||
|
||||
The sidebar is the main navigation block for your documentation. You can configure the sidebar menu in [`themeConfig.sidebar`](./default-theme-config#sidebar).
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
sidebar: [
|
||||
{
|
||||
text: 'Guide',
|
||||
items: [
|
||||
{ text: 'Introduction', link: '/introduction' },
|
||||
{ text: 'Getting Started', link: '/getting-started' },
|
||||
...
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## The Basics
|
||||
|
||||
The simplest form of the sidebar menu is passing in a single array of links. The first level item defines the "section" for the sidebar. It should contain `text`, which is the title of the section, and `items` which are the actual navigation links.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
sidebar: [
|
||||
{
|
||||
text: 'Section Title A',
|
||||
items: [
|
||||
{ text: 'Item A', link: '/item-a' },
|
||||
{ text: 'Item B', link: '/item-b' },
|
||||
...
|
||||
]
|
||||
},
|
||||
{
|
||||
text: 'Section Title B',
|
||||
items: [
|
||||
{ text: 'Item C', link: '/item-c' },
|
||||
{ text: 'Item D', link: '/item-d' },
|
||||
...
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Each `link` should specify the path to the actual file starting with `/`. If you add trailing slash to the end of link, it will show `index.md` of the corresponding directory.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
sidebar: [
|
||||
{
|
||||
text: 'Guide',
|
||||
items: [
|
||||
// This shows `/guide/index.md` page.
|
||||
{ text: 'Introduction', link: '/guide/' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You may further nest the sidebar items up to 6 level deep counting up from the root level. Note that deeper than 6 level of nested items gets ignored and will not be displayed on the sidebar.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
sidebar: [
|
||||
{
|
||||
text: 'Level 1',
|
||||
items: [
|
||||
{
|
||||
text: 'Level 2',
|
||||
items: [
|
||||
{
|
||||
text: 'Level 3',
|
||||
items: [
|
||||
...
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Multiple Sidebars
|
||||
|
||||
You may show different sidebar depending on the page path. For example, as shown on this site, you might want to create a separate sections of content in your documentation like "Guide" page and "Config" page.
|
||||
|
||||
To do so, first organize your pages into directories for each desired section:
|
||||
|
||||
```
|
||||
.
|
||||
├─ guide/
|
||||
│ ├─ index.md
|
||||
│ ├─ one.md
|
||||
│ └─ two.md
|
||||
└─ config/
|
||||
├─ index.md
|
||||
├─ three.md
|
||||
└─ four.md
|
||||
```
|
||||
|
||||
Then, update your configuration to define your sidebar for each section. This time, you should pass an object instead of an array.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
sidebar: {
|
||||
// This sidebar gets displayed when a user
|
||||
// is on `guide` directory.
|
||||
'/guide/': [
|
||||
{
|
||||
text: 'Guide',
|
||||
items: [
|
||||
{ text: 'Index', link: '/guide/' },
|
||||
{ text: 'One', link: '/guide/one' },
|
||||
{ text: 'Two', link: '/guide/two' }
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
// This sidebar gets displayed when a user
|
||||
// is on `config` directory.
|
||||
'/config/': [
|
||||
{
|
||||
text: 'Config',
|
||||
items: [
|
||||
{ text: 'Index', link: '/config/' },
|
||||
{ text: 'Three', link: '/config/three' },
|
||||
{ text: 'Four', link: '/config/four' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Collapsible Sidebar Groups
|
||||
|
||||
By adding `collapsed` option to the sidebar group, it shows a toggle button to hide/show each section.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
sidebar: [
|
||||
{
|
||||
text: 'Section Title A',
|
||||
collapsed: false,
|
||||
items: [...]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
All sections are "open" by default. If you would like them to be "closed" on initial page load, set `collapsed` option to `true`.
|
||||
|
||||
```js
|
||||
export default {
|
||||
themeConfig: {
|
||||
sidebar: [
|
||||
{
|
||||
text: 'Section Title A',
|
||||
collapsed: true,
|
||||
items: [...]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -0,0 +1,256 @@
|
||||
<script setup>
|
||||
import { VPTeamMembers } from 'vitepress/theme'
|
||||
|
||||
const members = [
|
||||
{
|
||||
avatar: 'https://github.com/yyx990803.png',
|
||||
name: 'Evan You',
|
||||
title: 'Creator',
|
||||
links: [
|
||||
{ icon: 'github', link: 'https://github.com/yyx990803' },
|
||||
{ icon: 'twitter', link: 'https://twitter.com/youyuxi' }
|
||||
]
|
||||
},
|
||||
{
|
||||
avatar: 'https://github.com/kiaking.png',
|
||||
name: 'Kia King Ishii',
|
||||
title: 'Developer',
|
||||
links: [
|
||||
{ icon: 'github', link: 'https://github.com/kiaking' },
|
||||
{ icon: 'twitter', link: 'https://twitter.com/KiaKing85' }
|
||||
]
|
||||
}
|
||||
]
|
||||
</script>
|
||||
|
||||
# Team Page
|
||||
|
||||
If you would like to introduce your team, you may use Team components to construct the Team Page. There are two ways of using these components. One is to embed it in doc page, and another is to create a full Team Page.
|
||||
|
||||
## Show team members in a page
|
||||
|
||||
You may use `<VPTeamMembers>` component exposed from `vitepress/theme` to display a list of team members on any page.
|
||||
|
||||
```html
|
||||
<script setup>
|
||||
import { VPTeamMembers } from 'vitepress/theme'
|
||||
|
||||
const members = [
|
||||
{
|
||||
avatar: 'https://www.github.com/yyx990803.png',
|
||||
name: 'Evan You',
|
||||
title: 'Creator',
|
||||
links: [
|
||||
{ icon: 'github', link: 'https://github.com/yyx990803' },
|
||||
{ icon: 'twitter', link: 'https://twitter.com/youyuxi' }
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
</script>
|
||||
|
||||
# Our Team
|
||||
|
||||
Say hello to our awesome team.
|
||||
|
||||
<VPTeamMembers size="small" :members />
|
||||
```
|
||||
|
||||
The above will display a team member in card looking element. It should display something similar to below.
|
||||
|
||||
<VPTeamMembers size="small" :members />
|
||||
|
||||
`<VPTeamMembers>` component comes in 2 different sizes, `small` and `medium`. While it boils down to your preference, usually `small` size should fit better when used in doc page. Also, you may add more properties to each member such as adding "description" or "sponsor" button. Learn more about it in [`<VPTeamMembers>`](#vpteammembers).
|
||||
|
||||
Embedding team members in doc page is good for small size team where having dedicated full team page might be too much, or introducing partial members as a reference to documentation context.
|
||||
|
||||
If you have large number of members, or simply would like to have more space to show team members, consider [creating a full team page](#create-a-full-team-page).
|
||||
|
||||
## Create a full Team Page
|
||||
|
||||
Instead of adding team members to doc page, you may also create a full Team Page, similar to how you can create a custom [Home Page](./default-theme-home-page).
|
||||
|
||||
To create a team page, first, create a new md file. The file name doesn't matter, but here lets call it `team.md`. In this file, set frontmatter option `layout: page`, and then you may compose your page structure using `TeamPage` components.
|
||||
|
||||
```html
|
||||
---
|
||||
layout: page
|
||||
---
|
||||
<script setup>
|
||||
import {
|
||||
VPTeamPage,
|
||||
VPTeamPageTitle,
|
||||
VPTeamMembers
|
||||
} from 'vitepress/theme'
|
||||
|
||||
const members = [
|
||||
{
|
||||
avatar: 'https://www.github.com/yyx990803.png',
|
||||
name: 'Evan You',
|
||||
title: 'Creator',
|
||||
links: [
|
||||
{ icon: 'github', link: 'https://github.com/yyx990803' },
|
||||
{ icon: 'twitter', link: 'https://twitter.com/youyuxi' }
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
</script>
|
||||
|
||||
<VPTeamPage>
|
||||
<VPTeamPageTitle>
|
||||
<template #title>
|
||||
Our Team
|
||||
</template>
|
||||
<template #lead>
|
||||
The development of VitePress is guided by an international
|
||||
team, some of whom have chosen to be featured below.
|
||||
</template>
|
||||
</VPTeamPageTitle>
|
||||
<VPTeamMembers :members />
|
||||
</VPTeamPage>
|
||||
```
|
||||
|
||||
When creating a full team page, remember to wrap all components with `<VPTeamPage>` component. This component will ensure all nested team related components get the proper layout structure like spacings.
|
||||
|
||||
`<VPPageTitle>` component adds the page title section. The title being `<h1>` heading. Use `#title` and `#lead` slot to document about your team.
|
||||
|
||||
`<VPMembers>` works as same as when used in a doc page. It will display list of members.
|
||||
|
||||
### Add sections to divide team members
|
||||
|
||||
You may add "sections" to the team page. For example, you may have different types of team members such as Core Team Members and Community Partners. You can divide these members into sections to better explain the roles of each group.
|
||||
|
||||
To do so, add `<VPTeamPageSection>` component to the `team.md` file we created previously.
|
||||
|
||||
```html
|
||||
---
|
||||
layout: page
|
||||
---
|
||||
<script setup>
|
||||
import {
|
||||
VPTeamPage,
|
||||
VPTeamPageTitle,
|
||||
VPTeamMembers,
|
||||
VPTeamPageSection
|
||||
} from 'vitepress/theme'
|
||||
|
||||
const coreMembers = [...]
|
||||
const partners = [...]
|
||||
</script>
|
||||
|
||||
<VPTeamPage>
|
||||
<VPTeamPageTitle>
|
||||
<template #title>Our Team</template>
|
||||
<template #lead>...</template>
|
||||
</VPTeamPageTitle>
|
||||
<VPTeamMembers size="medium" :members="coreMembers" />
|
||||
<VPTeamPageSection>
|
||||
<template #title>Partners</template>
|
||||
<template #lead>...</template>
|
||||
<template #members>
|
||||
<VPTeamMembers size="small" :members="partners" />
|
||||
</template>
|
||||
</VPTeamPageSection>
|
||||
</VPTeamPage>
|
||||
```
|
||||
|
||||
The `<VPTeamPageSection>` component can have `#title` and `#lead` slot similar to `VPTeamPageTitle` component, and also `#members` slot for displaying team members.
|
||||
|
||||
Remember to put in `<VPTeamMembers>` component within `#members` slot.
|
||||
|
||||
## `<VPTeamMembers>`
|
||||
|
||||
The `<VPTeamMembers>` component displays a given list of members.
|
||||
|
||||
```html
|
||||
<VPTeamMembers
|
||||
size="medium"
|
||||
:members="[
|
||||
{ avatar: '...', name: '...' },
|
||||
{ avatar: '...', name: '...' },
|
||||
...
|
||||
]"
|
||||
/>
|
||||
```
|
||||
|
||||
```ts
|
||||
interface Props {
|
||||
// Size of each members. Defaults to `medium`.
|
||||
size?: 'small' | 'medium'
|
||||
|
||||
// List of members to display.
|
||||
members: TeamMember[]
|
||||
}
|
||||
|
||||
interface TeamMember {
|
||||
// Avatar image for the member.
|
||||
avatar: string
|
||||
|
||||
// Name of the member.
|
||||
name: string
|
||||
|
||||
// Title to be shown below member's name.
|
||||
// e.g. Developer, Software Engineer, etc.
|
||||
title?: string
|
||||
|
||||
// Organization that the member belongs.
|
||||
org?: string
|
||||
|
||||
// URL for the organization.
|
||||
orgLink?: string
|
||||
|
||||
// Description for the member.
|
||||
desc?: string
|
||||
|
||||
// Social links. e.g. GitHub, Twitter, etc. You may pass in
|
||||
// the Social Links object here.
|
||||
// See: https://vitepress.dev/reference/default-theme-config.html#sociallinks
|
||||
links?: SocialLink[]
|
||||
|
||||
// URL for the sponsor page for the member.
|
||||
sponsor?: string
|
||||
|
||||
// Text for the sponsor link. Defaults to 'Sponsor'.
|
||||
actionText?: string
|
||||
}
|
||||
```
|
||||
|
||||
## `<VPTeamPage>`
|
||||
|
||||
The root component when creating a full team page. It only accepts a single slot. It will style all passed in team related components.
|
||||
|
||||
## `<VPTeamPageTitle>`
|
||||
|
||||
Adds "title" section of the page. Best use at the very beginning under `<VPTeamPage>`. It accepts `#title` and `#lead` slot.
|
||||
|
||||
```html
|
||||
<VPTeamPage>
|
||||
<VPTeamPageTitle>
|
||||
<template #title>
|
||||
Our Team
|
||||
</template>
|
||||
<template #lead>
|
||||
The development of VitePress is guided by an international
|
||||
team, some of whom have chosen to be featured below.
|
||||
</template>
|
||||
</VPTeamPageTitle>
|
||||
</VPTeamPage>
|
||||
```
|
||||
|
||||
## `<VPTeamPageSection>`
|
||||
|
||||
Creates a "section" with in team page. It accepts `#title`, `#lead`, and `#members` slot. You may add as many sections as you like inside `<VPTeamPage>`.
|
||||
|
||||
```html
|
||||
<VPTeamPage>
|
||||
...
|
||||
<VPTeamPageSection>
|
||||
<template #title>Partners</template>
|
||||
<template #lead>Lorem ipsum...</template>
|
||||
<template #members>
|
||||
<VPTeamMembers :members="data" />
|
||||
</template>
|
||||
</VPTeamPageSection>
|
||||
</VPTeamPage>
|
||||
```
|
||||
@ -0,0 +1,240 @@
|
||||
---
|
||||
outline: deep
|
||||
---
|
||||
|
||||
# Frontmatter Config
|
||||
|
||||
Frontmatter enables page based configuration. In every markdown file, you can use frontmatter config to override site-level or theme-level config options. Also, there are config options which you can only define in frontmatter.
|
||||
|
||||
Example usage:
|
||||
|
||||
```md
|
||||
---
|
||||
title: Docs with VitePress
|
||||
editLink: true
|
||||
---
|
||||
```
|
||||
|
||||
You can access frontmatter data via the `$frontmatter` global in Vue expressions:
|
||||
|
||||
```md
|
||||
{{ $frontmatter.title }}
|
||||
```
|
||||
|
||||
## title
|
||||
|
||||
- Type: `string`
|
||||
|
||||
Title for the page. It's same as [config.title](./site-config#title), and it overrides the site-level config.
|
||||
|
||||
```yaml
|
||||
---
|
||||
title: VitePress
|
||||
---
|
||||
```
|
||||
|
||||
## titleTemplate
|
||||
|
||||
- Type: `string | boolean`
|
||||
|
||||
The suffix for the title. It's same as [config.titleTemplate](./site-config#titletemplate), and it overrides the site-level config.
|
||||
|
||||
```yaml
|
||||
---
|
||||
title: VitePress
|
||||
titleTemplate: Vite & Vue powered static site generator
|
||||
---
|
||||
```
|
||||
|
||||
## description
|
||||
|
||||
- Type: `string`
|
||||
|
||||
Description for the page. It's same as [config.description](./site-config#description), and it overrides the site-level config.
|
||||
|
||||
```yaml
|
||||
---
|
||||
description: VitePress
|
||||
---
|
||||
```
|
||||
|
||||
## head
|
||||
|
||||
- Type: `HeadConfig[]`
|
||||
|
||||
Specify extra head tags to be injected for the current page. Will be appended after head tags injected by site-level config.
|
||||
|
||||
```yaml
|
||||
---
|
||||
head:
|
||||
- - meta
|
||||
- name: description
|
||||
content: hello
|
||||
- - meta
|
||||
- name: keywords
|
||||
content: super duper SEO
|
||||
---
|
||||
```
|
||||
|
||||
```ts
|
||||
type HeadConfig =
|
||||
| [string, Record<string, string>]
|
||||
| [string, Record<string, string>, string]
|
||||
```
|
||||
|
||||
## Default Theme Only
|
||||
|
||||
The following frontmatter options are only applicable when using the default theme.
|
||||
|
||||
### layout
|
||||
|
||||
- Type: `doc | home | page`
|
||||
- Default: `doc`
|
||||
|
||||
Determines the layout of the page.
|
||||
|
||||
- `doc` - It applies default documentation styles to the markdown content.
|
||||
- `home` - Special layout for "Home Page". You may add extra options such as `hero` and `features` to rapidly create beautiful landing page.
|
||||
- `page` - Behave similar to `doc` but it applies no styles to the content. Useful when you want to create a fully custom page.
|
||||
|
||||
```yaml
|
||||
---
|
||||
layout: doc
|
||||
---
|
||||
```
|
||||
|
||||
### hero <Badge type="info" text="home page only" />
|
||||
|
||||
Defines contents of home hero section when `layout` is set to `home`. More details in [Default Theme: Home Page](./default-theme-home-page).
|
||||
|
||||
### features <Badge type="info" text="home page only" />
|
||||
|
||||
Defines items to display in features section when `layout` is set to `home`. More details in [Default Theme: Home Page](./default-theme-home-page).
|
||||
|
||||
### navbar
|
||||
|
||||
- Type: `boolean`
|
||||
- Default: `true`
|
||||
|
||||
Whether to display [navbar](./default-theme-nav).
|
||||
|
||||
```yaml
|
||||
---
|
||||
navbar: false
|
||||
---
|
||||
```
|
||||
|
||||
### sidebar
|
||||
|
||||
- Type: `boolean`
|
||||
- Default: `true`
|
||||
|
||||
Whether to display [sidebar](./default-theme-sidebar).
|
||||
|
||||
```yaml
|
||||
---
|
||||
sidebar: false
|
||||
---
|
||||
```
|
||||
|
||||
### aside
|
||||
|
||||
- Type: `boolean | 'left'`
|
||||
- Default: `true`
|
||||
|
||||
Defines the location of the aside component in the `doc` layout.
|
||||
|
||||
Setting this value to `false` prevents rendering of aside container.\
|
||||
Setting this value to `true` renders the aside to the right.\
|
||||
Setting this value to `'left'` renders the aside to the left.
|
||||
|
||||
```yaml
|
||||
---
|
||||
aside: false
|
||||
---
|
||||
```
|
||||
|
||||
### outline
|
||||
|
||||
- Type: `number | [number, number] | 'deep' | false`
|
||||
- Default: `2`
|
||||
|
||||
The levels of header in the outline to display for the page. It's same as [config.themeConfig.outline.level](./default-theme-config#outline), and it overrides the value set in site-level config.
|
||||
|
||||
```yaml
|
||||
---
|
||||
outline: [2, 4]
|
||||
---
|
||||
```
|
||||
|
||||
### lastUpdated
|
||||
|
||||
- Type: `boolean | Date`
|
||||
- Default: `true`
|
||||
|
||||
Whether to display [last updated](./default-theme-last-updated) text in the footer of the current page. If a datetime is specified, it will be displayed instead of the last git modified timestamp.
|
||||
|
||||
```yaml
|
||||
---
|
||||
lastUpdated: false
|
||||
---
|
||||
```
|
||||
|
||||
### editLink
|
||||
|
||||
- Type: `boolean`
|
||||
- Default: `true`
|
||||
|
||||
Whether to display [edit link](./default-theme-edit-link) in the footer of the current page.
|
||||
|
||||
```yaml
|
||||
---
|
||||
editLink: false
|
||||
---
|
||||
```
|
||||
|
||||
### footer
|
||||
|
||||
- Type: `boolean`
|
||||
- Default: `true`
|
||||
|
||||
Whether to display [footer](./default-theme-footer).
|
||||
|
||||
```yaml
|
||||
---
|
||||
footer: false
|
||||
---
|
||||
```
|
||||
|
||||
### pageClass
|
||||
|
||||
- Type: `string`
|
||||
|
||||
Add extra class name to a specific page.
|
||||
|
||||
```yaml
|
||||
---
|
||||
pageClass: custom-page-class
|
||||
---
|
||||
```
|
||||
|
||||
Then you can customize styles of this specific page in `.vitepress/theme/custom.css` file:
|
||||
|
||||
```css
|
||||
.custom-page-class {
|
||||
/* page-specific styles */
|
||||
}
|
||||
```
|
||||
|
||||
### isHome
|
||||
|
||||
- Type: `boolean`
|
||||
|
||||
The default theme relies on checks like `frontmatter.layout === 'home'` to determine if the current page is the home page.\
|
||||
This is useful when you want to force show the home page elements in a custom layout.
|
||||
|
||||
```yaml
|
||||
---
|
||||
isHome: true
|
||||
---
|
||||
```
|
||||
@ -0,0 +1,173 @@
|
||||
# Runtime API
|
||||
|
||||
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.
|
||||
|
||||
The helper methods are globally importable from `vitepress` and are typically used in custom theme Vue components. However, they are also usable inside `.md` pages because markdown files are compiled into Vue [Single-File Components](https://vuejs.org/guide/scaling-up/sfc.html).
|
||||
|
||||
Methods that start with `use*` indicates that it is a [Vue 3 Composition API](https://vuejs.org/guide/introduction.html#composition-api) function ("Composable") that can only be used inside `setup()` or `<script setup>`.
|
||||
|
||||
## `useData` <Badge type="info" text="composable" />
|
||||
|
||||
Returns page-specific data. The returned object has the following type:
|
||||
|
||||
```ts
|
||||
interface VitePressData<T = any> {
|
||||
/**
|
||||
* Site-level metadata
|
||||
*/
|
||||
site: Ref<SiteData<T>>
|
||||
/**
|
||||
* themeConfig from .vitepress/config.js
|
||||
*/
|
||||
theme: Ref<T>
|
||||
/**
|
||||
* Page-level metadata
|
||||
*/
|
||||
page: Ref<PageData>
|
||||
/**
|
||||
* Page frontmatter
|
||||
*/
|
||||
frontmatter: Ref<PageData['frontmatter']>
|
||||
/**
|
||||
* Dynamic route params
|
||||
*/
|
||||
params: Ref<PageData['params']>
|
||||
title: Ref<string>
|
||||
description: Ref<string>
|
||||
lang: Ref<string>
|
||||
isDark: Ref<boolean>
|
||||
dir: Ref<string>
|
||||
localeIndex: Ref<string>
|
||||
/**
|
||||
* Current location hash
|
||||
*/
|
||||
hash: Ref<string>
|
||||
}
|
||||
|
||||
interface PageData {
|
||||
title: string
|
||||
titleTemplate?: string | boolean
|
||||
description: string
|
||||
relativePath: string
|
||||
filePath: string,
|
||||
headers: Header[]
|
||||
frontmatter: Record<string, any>
|
||||
params?: Record<string, any>
|
||||
isNotFound?: boolean
|
||||
lastUpdated?: number
|
||||
}
|
||||
```
|
||||
|
||||
**Example:**
|
||||
|
||||
```vue
|
||||
<script setup>
|
||||
import { useData } from 'vitepress'
|
||||
|
||||
const { theme } = useData()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>{{ theme.footer.copyright }}</h1>
|
||||
</template>
|
||||
```
|
||||
|
||||
## `useRoute` <Badge type="info" text="composable" />
|
||||
|
||||
Returns the current route object with the following type:
|
||||
|
||||
```ts
|
||||
interface Route {
|
||||
path: string
|
||||
data: PageData
|
||||
component: Component | null
|
||||
}
|
||||
```
|
||||
|
||||
## `useRouter` <Badge type="info" text="composable" />
|
||||
|
||||
Returns the VitePress router instance so you can programmatically navigate to another page.
|
||||
|
||||
```ts
|
||||
interface Router {
|
||||
/**
|
||||
* Current route.
|
||||
*/
|
||||
route: Route
|
||||
/**
|
||||
* Navigate to a new URL.
|
||||
*/
|
||||
go: (to?: string) => Promise<void>
|
||||
/**
|
||||
* Called before the route changes. Return `false` to cancel the navigation.
|
||||
*/
|
||||
onBeforeRouteChange?: (to: string) => Awaitable<void | boolean>
|
||||
/**
|
||||
* Called before the page component is loaded (after the history state is updated).
|
||||
* Return `false` to cancel the navigation.
|
||||
*/
|
||||
onBeforePageLoad?: (to: string) => Awaitable<void | boolean>
|
||||
/**
|
||||
* Called after the page component is loaded (before the page component is updated).
|
||||
*/
|
||||
onAfterPageLoad?: (to: string) => Awaitable<void>
|
||||
/**
|
||||
* Called after the route changes.
|
||||
*/
|
||||
onAfterRouteChange?: (to: string) => Awaitable<void>
|
||||
}
|
||||
```
|
||||
|
||||
## `withBase` <Badge type="info" text="helper" />
|
||||
|
||||
- **Type**: `(path: string) => string`
|
||||
|
||||
Appends the configured [`base`](./site-config#base) to a given URL path. Also see [Base URL](../guide/asset-handling#base-url).
|
||||
|
||||
## `<Content />` <Badge type="info" text="component" />
|
||||
|
||||
The `<Content />` component displays the rendered markdown contents. Useful [when creating your own theme](../guide/custom-theme).
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<h1>Custom Layout!</h1>
|
||||
<Content />
|
||||
</template>
|
||||
```
|
||||
|
||||
## `<ClientOnly />` <Badge type="info" text="component" />
|
||||
|
||||
The `<ClientOnly />` component renders its slot only at client side.
|
||||
|
||||
Because VitePress applications are server-rendered in Node.js when generating static builds, any Vue usage must conform to the universal code requirements. In short, make sure to only access Browser / DOM APIs in beforeMount or mounted hooks.
|
||||
|
||||
If you are using or demoing components that are not SSR-friendly (for example, contain custom directives), you can wrap them inside the `ClientOnly` component.
|
||||
|
||||
```vue-html
|
||||
<ClientOnly>
|
||||
<NonSSRFriendlyComponent />
|
||||
</ClientOnly>
|
||||
```
|
||||
|
||||
- Related: [SSR Compatibility](../guide/ssr-compat)
|
||||
|
||||
## `$frontmatter` <Badge type="info" text="template global" />
|
||||
|
||||
Directly access current page's [frontmatter](../guide/frontmatter) data in Vue expressions.
|
||||
|
||||
```md
|
||||
---
|
||||
title: Hello
|
||||
---
|
||||
|
||||
# {{ $frontmatter.title }}
|
||||
```
|
||||
|
||||
## `$params` <Badge type="info" text="template global" />
|
||||
|
||||
Directly access current page's [dynamic route params](../guide/routing#dynamic-routes) in Vue expressions.
|
||||
|
||||
```md
|
||||
- package name: {{ $params.pkg }}
|
||||
- version: {{ $params.version }}
|
||||
```
|
||||
@ -0,0 +1,722 @@
|
||||
---
|
||||
outline: deep
|
||||
---
|
||||
|
||||
# Site Config
|
||||
|
||||
Site config is where you can define the global settings of the site. App config options define settings that apply to every VitePress site, regardless of what theme it is using. For example, the base directory or the title of the site.
|
||||
|
||||
## Overview
|
||||
|
||||
### Config Resolution
|
||||
|
||||
The config file is always resolved from `<root>/.vitepress/config.[ext]`, where `<root>` is your VitePress [project root](../guide/routing#root-and-source-directory), and `[ext]` is one of the supported file extensions. TypeScript is supported out of the box. Supported extensions include `.js`, `.ts`, `.mjs`, and `.mts`.
|
||||
|
||||
It is recommended to use ES modules syntax in config files. The config file should default export an object:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
// app level config options
|
||||
lang: 'en-US',
|
||||
title: 'VitePress',
|
||||
description: 'Vite & Vue powered static site generator.',
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
::: details Dynamic (Async) Config
|
||||
|
||||
If you need to dynamically generate the config, you can also default export a function. For example:
|
||||
|
||||
```ts
|
||||
import { defineConfig } from 'vitepress'
|
||||
|
||||
export default async () => {
|
||||
const posts = await (await fetch('https://my-cms.com/blog-posts')).json()
|
||||
|
||||
return defineConfig({
|
||||
// app level config options
|
||||
lang: 'en-US',
|
||||
title: 'VitePress',
|
||||
description: 'Vite & Vue powered static site generator.',
|
||||
|
||||
// theme level config options
|
||||
themeConfig: {
|
||||
sidebar: [
|
||||
...posts.map((post) => ({
|
||||
text: post.name,
|
||||
link: `/posts/${post.name}`
|
||||
}))
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
You can also use top-level `await`. For example:
|
||||
|
||||
```ts
|
||||
import { defineConfig } from 'vitepress'
|
||||
|
||||
const posts = await (await fetch('https://my-cms.com/blog-posts')).json()
|
||||
|
||||
export default defineConfig({
|
||||
// app level config options
|
||||
lang: 'en-US',
|
||||
title: 'VitePress',
|
||||
description: 'Vite & Vue powered static site generator.',
|
||||
|
||||
// theme level config options
|
||||
themeConfig: {
|
||||
sidebar: [
|
||||
...posts.map((post) => ({
|
||||
text: post.name,
|
||||
link: `/posts/${post.name}`
|
||||
}))
|
||||
]
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
### Config Intellisense
|
||||
|
||||
Using the `defineConfig` helper will provide TypeScript-powered intellisense for config options. Assuming your IDE supports it, this should work in both JavaScript and TypeScript.
|
||||
|
||||
```js
|
||||
import { defineConfig } from 'vitepress'
|
||||
|
||||
export default defineConfig({
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
||||
### Typed Theme Config
|
||||
|
||||
By default, `defineConfig` helper expects the theme config type from default theme:
|
||||
|
||||
```ts
|
||||
import { defineConfig } from 'vitepress'
|
||||
|
||||
export default defineConfig({
|
||||
themeConfig: {
|
||||
// Type is `DefaultTheme.Config`
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
If you use a custom theme and want type checks for the theme config, you'll need to use `defineConfigWithTheme` instead, and pass the config type for your custom theme via a generic argument:
|
||||
|
||||
```ts
|
||||
import { defineConfigWithTheme } from 'vitepress'
|
||||
import type { ThemeConfig } from 'your-theme'
|
||||
|
||||
export default defineConfigWithTheme<ThemeConfig>({
|
||||
themeConfig: {
|
||||
// Type is `ThemeConfig`
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Vite, Vue & Markdown Config
|
||||
|
||||
- **Vite**
|
||||
|
||||
You can configure the underlying Vite instance using the [vite](#vite) option in your VitePress config. No need to create a separate Vite config file.
|
||||
|
||||
- **Vue**
|
||||
|
||||
VitePress already includes the official Vue plugin for Vite ([@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue)). You can configure its options using the [vue](#vue) option in your VitePress config.
|
||||
|
||||
- **Markdown**
|
||||
|
||||
You can configure the underlying [Markdown-It](https://github.com/markdown-it/markdown-it) instance using the [markdown](#markdown) option in your VitePress config.
|
||||
|
||||
## Site Metadata
|
||||
|
||||
### title
|
||||
|
||||
- Type: `string`
|
||||
- Default: `VitePress`
|
||||
- Can be overridden per page via [frontmatter](./frontmatter-config#title)
|
||||
|
||||
Title for the site. When using the default theme, this will be displayed in the nav bar.
|
||||
|
||||
It will also be used as the default suffix for all individual page titles, unless [`titleTemplate`](#titletemplate) is defined. An individual page's final title will be the text content of its first `<h1>` header, combined with the global `title` as the suffix. For example with the following config and page content:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
title: 'My Awesome Site'
|
||||
}
|
||||
```
|
||||
|
||||
```md
|
||||
# Hello
|
||||
```
|
||||
|
||||
The title of the page will be `Hello | My Awesome Site`.
|
||||
|
||||
### titleTemplate
|
||||
|
||||
- Type: `string | boolean`
|
||||
- Can be overridden per page via [frontmatter](./frontmatter-config#titletemplate)
|
||||
|
||||
Allows customizing each page's title suffix or the entire title. For example:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
title: 'My Awesome Site',
|
||||
titleTemplate: 'Custom Suffix'
|
||||
}
|
||||
```
|
||||
|
||||
```md
|
||||
# Hello
|
||||
```
|
||||
|
||||
The title of the page will be `Hello | Custom Suffix`.
|
||||
|
||||
To completely customize how the title should be rendered, you can use the `:title` symbol in `titleTemplate`:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
titleTemplate: ':title - Custom Suffix'
|
||||
}
|
||||
```
|
||||
|
||||
Here `:title` will be replaced with the text inferred from the page's first `<h1>` header. The title of the previous example page will be `Hello - Custom Suffix`.
|
||||
|
||||
The option can be set to `false` to disable title suffixes.
|
||||
|
||||
### description
|
||||
|
||||
- Type: `string`
|
||||
- Default: `A VitePress site`
|
||||
- Can be overridden per page via [frontmatter](./frontmatter-config#description)
|
||||
|
||||
Description for the site. This will render as a `<meta>` tag in the page HTML.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
description: 'A VitePress site'
|
||||
}
|
||||
```
|
||||
|
||||
### head
|
||||
|
||||
- Type: `HeadConfig[]`
|
||||
- Default: `[]`
|
||||
- Can be appended per page via [frontmatter](./frontmatter-config#head)
|
||||
|
||||
Additional elements to render in the `<head>` tag in the page HTML. The user-added tags are rendered before the closing `head` tag, after VitePress tags.
|
||||
|
||||
```ts
|
||||
type HeadConfig =
|
||||
| [string, Record<string, string>]
|
||||
| [string, Record<string, string>, string]
|
||||
```
|
||||
|
||||
#### Example: Adding a favicon
|
||||
|
||||
```ts
|
||||
export default {
|
||||
head: [['link', { rel: 'icon', href: '/favicon.ico' }]]
|
||||
} // put favicon.ico in public directory, if base is set, use /base/favicon.ico
|
||||
|
||||
/* Would render:
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
*/
|
||||
```
|
||||
|
||||
#### Example: Adding Google Fonts
|
||||
|
||||
```ts
|
||||
export default {
|
||||
head: [
|
||||
[
|
||||
'link',
|
||||
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' }
|
||||
],
|
||||
[
|
||||
'link',
|
||||
{ rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: '' }
|
||||
],
|
||||
[
|
||||
'link',
|
||||
{ href: 'https://fonts.googleapis.com/css2?family=Roboto&display=swap', rel: 'stylesheet' }
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
/* Would render:
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
|
||||
*/
|
||||
```
|
||||
|
||||
#### Example: Registering a service worker
|
||||
|
||||
```ts
|
||||
export default {
|
||||
head: [
|
||||
[
|
||||
'script',
|
||||
{ id: 'register-sw' },
|
||||
`;(() => {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('/sw.js')
|
||||
}
|
||||
})()`
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
/* Would render:
|
||||
<script id="register-sw">
|
||||
;(() => {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('/sw.js')
|
||||
}
|
||||
})()
|
||||
</script>
|
||||
*/
|
||||
```
|
||||
|
||||
#### Example: Using Google Analytics
|
||||
|
||||
```ts
|
||||
export default {
|
||||
head: [
|
||||
[
|
||||
'script',
|
||||
{ async: '', src: 'https://www.googletagmanager.com/gtag/js?id=TAG_ID' }
|
||||
],
|
||||
[
|
||||
'script',
|
||||
{},
|
||||
`window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', 'TAG_ID');`
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
/* Would render:
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', 'TAG_ID');
|
||||
</script>
|
||||
*/
|
||||
```
|
||||
|
||||
### lang
|
||||
|
||||
- Type: `string`
|
||||
- Default: `en-US`
|
||||
|
||||
The lang attribute for the site. This will render as a `<html lang="en-US">` tag in the page HTML.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
lang: 'en-US'
|
||||
}
|
||||
```
|
||||
|
||||
### base
|
||||
|
||||
- Type: `string`
|
||||
- Default: `/`
|
||||
|
||||
The base URL the site will be deployed at. You will need to set this if you plan to deploy your site under a sub path, for example, GitHub pages. If you plan to deploy your site to `https://foo.github.io/bar/`, then you should set base to `'/bar/'`. It should always start and end with a slash.
|
||||
|
||||
The base is automatically prepended to all the URLs that start with / in other options, so you only need to specify it once.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
base: '/base/'
|
||||
}
|
||||
```
|
||||
|
||||
## Routing
|
||||
|
||||
### cleanUrls
|
||||
|
||||
- Type: `boolean`
|
||||
- Default: `false`
|
||||
|
||||
When set to `true`, VitePress will remove the trailing `.html` from URLs. Also see [Generating Clean URL](../guide/routing#generating-clean-url).
|
||||
|
||||
::: warning Server Support Required
|
||||
Enabling this may require additional configuration on your hosting platform. For it to work, your server must be able to serve `/foo.html` when visiting `/foo` **without a redirect**.
|
||||
:::
|
||||
|
||||
### rewrites
|
||||
|
||||
- Type: `Record<string, string>`
|
||||
|
||||
Defines custom directory <-> URL mappings. See [Routing: Route Rewrites](../guide/routing#route-rewrites) for more details.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
rewrites: {
|
||||
'source/:page': 'destination/:page'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
### srcDir
|
||||
|
||||
- Type: `string`
|
||||
- Default: `.`
|
||||
|
||||
The directory where your markdown pages are stored, relative to project root. Also see [Root and Source Directory](../guide/routing#root-and-source-directory).
|
||||
|
||||
```ts
|
||||
export default {
|
||||
srcDir: './src'
|
||||
}
|
||||
```
|
||||
|
||||
### srcExclude
|
||||
|
||||
- Type: `string[]`
|
||||
- Default: `undefined`
|
||||
|
||||
A [glob pattern](https://github.com/mrmlnc/fast-glob#pattern-syntax) for matching markdown files that should be excluded as source content.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
srcExclude: ['**/README.md', '**/TODO.md']
|
||||
}
|
||||
```
|
||||
|
||||
### outDir
|
||||
|
||||
- Type: `string`
|
||||
- Default: `./.vitepress/dist`
|
||||
|
||||
The build output location for the site, relative to [project root](../guide/routing#root-and-source-directory).
|
||||
|
||||
```ts
|
||||
export default {
|
||||
outDir: '../public'
|
||||
}
|
||||
```
|
||||
|
||||
### assetsDir
|
||||
|
||||
- Type: `string`
|
||||
- Default: `assets`
|
||||
|
||||
Specify the directory to nest generated assets under. The path should be inside [`outDir`](#outdir) and is resolved relative to it.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
assetsDir: 'static'
|
||||
}
|
||||
```
|
||||
|
||||
### cacheDir
|
||||
|
||||
- Type: `string`
|
||||
- Default: `./.vitepress/cache`
|
||||
|
||||
The directory for cache files, relative to [project root](../guide/routing#root-and-source-directory). See also: [cacheDir](https://vitejs.dev/config/shared-options.html#cachedir).
|
||||
|
||||
```ts
|
||||
export default {
|
||||
cacheDir: './.vitepress/.vite'
|
||||
}
|
||||
```
|
||||
|
||||
### ignoreDeadLinks
|
||||
|
||||
- Type: `boolean | 'localhostLinks' | (string | RegExp | ((link: string, source: string) => boolean))[]`
|
||||
- Default: `false`
|
||||
|
||||
When set to `true`, VitePress will not fail builds due to dead links.
|
||||
|
||||
When set to `'localhostLinks'`, the build will fail on dead links, but won't check `localhost` links.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
ignoreDeadLinks: true
|
||||
}
|
||||
```
|
||||
|
||||
It can also be an array of exact url string, regex patterns, or custom filter functions.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
ignoreDeadLinks: [
|
||||
// ignore exact url "/playground"
|
||||
'/playground',
|
||||
// ignore all localhost links
|
||||
/^https?:\/\/localhost/,
|
||||
// ignore all links include "/repl/""
|
||||
/\/repl\//,
|
||||
// custom function, ignore all links include "ignore"
|
||||
(url) => {
|
||||
return url.toLowerCase().includes('ignore')
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### metaChunk <Badge type="warning" text="experimental" />
|
||||
|
||||
- Type: `boolean`
|
||||
- Default: `false`
|
||||
|
||||
When set to `true`, extract pages metadata to a separate JavaScript chunk instead of inlining it in the initial HTML. This makes each page's HTML payload smaller and makes the pages metadata cacheable, thus reducing server bandwidth when you have many pages in the site.
|
||||
|
||||
### mpa <Badge type="warning" text="experimental" />
|
||||
|
||||
- Type: `boolean`
|
||||
- Default: `false`
|
||||
|
||||
When set to `true`, the production app will be built in [MPA Mode](../guide/mpa-mode). MPA mode ships 0kb JavaScript by default, at the cost of disabling client-side navigation and requires explicit opt-in for interactivity.
|
||||
|
||||
## Theming
|
||||
|
||||
### appearance
|
||||
|
||||
- Type: `boolean | 'dark' | 'force-dark' | 'force-auto' | import('@vueuse/core').UseDarkOptions`
|
||||
- Default: `true`
|
||||
|
||||
Whether to enable dark mode (by adding the `.dark` class to the `<html>` element).
|
||||
|
||||
- If the option is set to `true`, the default theme will be determined by the user's preferred color scheme.
|
||||
- If the option is set to `dark`, the theme will be dark by default, unless the user manually toggles it.
|
||||
- If the option is set to `false`, users will not be able to toggle the theme.
|
||||
- If the option is set to `'force-dark'`, the theme will always be dark and users will not be able to toggle it.
|
||||
- If the option is set to `'force-auto'`, the theme will always be determined by the user's preferred color scheme and users will not be able to toggle it.
|
||||
|
||||
This option injects an inline script that restores users settings from local storage using the `vitepress-theme-appearance` key. This ensures the `.dark` class is applied before the page is rendered to avoid flickering.
|
||||
|
||||
`appearance.initialValue` can only be `'dark' | undefined`. Refs or getters are not supported.
|
||||
|
||||
### lastUpdated
|
||||
|
||||
- Type: `boolean`
|
||||
- Default: `false`
|
||||
|
||||
Whether to get the last updated timestamp for each page using Git. The timestamp will be included in each page's page data, accessible via [`useData`](./runtime-api#usedata).
|
||||
|
||||
When using the default theme, enabling this option will display each page's last updated time. You can customize the text via [`themeConfig.lastUpdatedText`](./default-theme-config#lastupdatedtext) option.
|
||||
|
||||
## Customization
|
||||
|
||||
### markdown
|
||||
|
||||
- Type: `MarkdownOption`
|
||||
|
||||
Configure Markdown parser options. VitePress uses [Markdown-it](https://github.com/markdown-it/markdown-it) as the parser, and [Shiki](https://github.com/shikijs/shiki) to highlight language syntax. Inside this option, you may pass various Markdown related options to fit your needs.
|
||||
|
||||
```js
|
||||
export default {
|
||||
markdown: {...}
|
||||
}
|
||||
```
|
||||
|
||||
Check the [type declaration and jsdocs](https://github.com/vuejs/vitepress/blob/main/src/node/markdown/markdown.ts) for all the options available.
|
||||
|
||||
### vite
|
||||
|
||||
- Type: `import('vite').UserConfig`
|
||||
|
||||
Pass raw [Vite Config](https://vitejs.dev/config/) to internal Vite dev server / bundler.
|
||||
|
||||
```js
|
||||
export default {
|
||||
vite: {
|
||||
// Vite config options
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### vue
|
||||
|
||||
- Type: `import('@vitejs/plugin-vue').Options`
|
||||
|
||||
Pass raw [`@vitejs/plugin-vue` options](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue#options) to the internal plugin instance.
|
||||
|
||||
```js
|
||||
export default {
|
||||
vue: {
|
||||
// @vitejs/plugin-vue options
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Build Hooks
|
||||
|
||||
VitePress build hooks allow you to add new functionality and behaviors to your website:
|
||||
|
||||
- Sitemap
|
||||
- Search Indexing
|
||||
- PWA
|
||||
- Teleports
|
||||
|
||||
### buildEnd
|
||||
|
||||
- Type: `(siteConfig: SiteConfig) => Awaitable<void>`
|
||||
|
||||
`buildEnd` is a build CLI hook, it will run after build (SSG) finish but before VitePress CLI process exits.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
async buildEnd(siteConfig) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### postRender
|
||||
|
||||
- Type: `(context: SSGContext) => Awaitable<SSGContext | void>`
|
||||
|
||||
`postRender` is a build hook, called when SSG rendering is done. It will allow you to handle the teleports content during SSG.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
async postRender(context) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
interface SSGContext {
|
||||
content: string
|
||||
teleports?: Record<string, string>
|
||||
[key: string]: any
|
||||
}
|
||||
```
|
||||
|
||||
### transformHead
|
||||
|
||||
- Type: `(context: TransformContext) => Awaitable<HeadConfig[]>`
|
||||
|
||||
`transformHead` is a build hook to transform the head before generating each page. It will allow you to add head entries that cannot be statically added to your VitePress config. You only need to return extra entries, they will be merged automatically with the existing ones.
|
||||
|
||||
::: warning
|
||||
Don't mutate anything inside the `context`.
|
||||
:::
|
||||
|
||||
```ts
|
||||
export default {
|
||||
async transformHead(context) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
interface TransformContext {
|
||||
page: string // e.g. index.md (relative to srcDir)
|
||||
assets: string[] // all non-js/css assets as fully resolved public URL
|
||||
siteConfig: SiteConfig
|
||||
siteData: SiteData
|
||||
pageData: PageData
|
||||
title: string
|
||||
description: string
|
||||
head: HeadConfig[]
|
||||
content: string
|
||||
}
|
||||
```
|
||||
|
||||
Note that this hook is only called when generating the site statically. It is not called during dev. If you need to add dynamic head entries during dev, you can use the [`transformPageData`](#transformpagedata) hook instead:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
transformPageData(pageData) {
|
||||
pageData.frontmatter.head ??= []
|
||||
pageData.frontmatter.head.push([
|
||||
'meta',
|
||||
{
|
||||
name: 'og:title',
|
||||
content:
|
||||
pageData.frontmatter.layout === 'home'
|
||||
? `VitePress`
|
||||
: `${pageData.title} | VitePress`
|
||||
}
|
||||
])
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Example: Adding a canonical URL `<link>`
|
||||
|
||||
```ts
|
||||
export default {
|
||||
transformPageData(pageData) {
|
||||
const canonicalUrl = `https://example.com/${pageData.relativePath}`
|
||||
.replace(/index\.md$/, '')
|
||||
.replace(/\.md$/, '.html')
|
||||
|
||||
pageData.frontmatter.head ??= []
|
||||
pageData.frontmatter.head.push([
|
||||
'link',
|
||||
{ rel: 'canonical', href: canonicalUrl }
|
||||
])
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### transformHtml
|
||||
|
||||
- Type: `(code: string, id: string, context: TransformContext) => Awaitable<string | void>`
|
||||
|
||||
`transformHtml` is a build hook to transform the content of each page before saving to disk.
|
||||
|
||||
::: warning
|
||||
Don't mutate anything inside the `context`. Also, modifying the html content may cause hydration problems in runtime.
|
||||
:::
|
||||
|
||||
```ts
|
||||
export default {
|
||||
async transformHtml(code, id, context) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### transformPageData
|
||||
|
||||
- Type: `(pageData: PageData, context: TransformPageContext) => Awaitable<Partial<PageData> | { [key: string]: any } | void>`
|
||||
|
||||
`transformPageData` is a hook to transform the `pageData` of each page. You can directly mutate `pageData` or return changed values which will be merged into the page data.
|
||||
|
||||
::: warning
|
||||
Don't mutate anything inside the `context` and be careful that this might impact the performance of dev server, especially if you have some network requests or heavy computations (like generating images) in the hook. You can check for `process.env.NODE_ENV === 'production'` for conditional logic.
|
||||
:::
|
||||
|
||||
```ts
|
||||
export default {
|
||||
async transformPageData(pageData, { siteConfig }) {
|
||||
pageData.contributors = await getPageContributors(pageData.relativePath)
|
||||
}
|
||||
|
||||
// or return data to be merged
|
||||
async transformPageData(pageData, { siteConfig }) {
|
||||
return {
|
||||
contributors: await getPageContributors(pageData.relativePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
interface TransformPageContext {
|
||||
siteConfig: SiteConfig
|
||||
}
|
||||
```
|
||||
Loading…
Reference in new issue