From bacbe8a27f6ed3c44bd399b1e5231f45db5c0f79 Mon Sep 17 00:00:00 2001 From: CHOYSEN Date: Sat, 4 Feb 2023 14:50:17 +0800 Subject: [PATCH] docs(api): use code snippet for type definition --- docs/guide/api.md | 30 +++--------------------------- src/client/app/data.ts | 2 ++ src/client/app/router.ts | 4 ++++ 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/docs/guide/api.md b/docs/guide/api.md index 244bb966..189d987d 100644 --- a/docs/guide/api.md +++ b/docs/guide/api.md @@ -10,20 +10,7 @@ Methods that start with `use*` indicates that it is a [Vue 3 Composition API](ht Returns page-specific data. The returned object has the following type: -```ts -interface VitePressData { - site: Ref> - page: Ref - theme: Ref // themeConfig from .vitepress/config.js - frontmatter: Ref - title: Ref - description: Ref - lang: Ref - isDark: Ref - dir: Ref - localeIndex: Ref -} -``` +<<< @/../src/client/app/data.ts#VitePressData **Example:** @@ -43,24 +30,13 @@ const { theme } = useData() Returns the current route object with the following type: -```ts -interface Route { - path: string - data: PageData - component: Component | null -} -``` +<<< @/../src/client/app/router.ts#Route ## `useRouter` Returns the VitePress router instance so you can programmatically navigate to another page. -```ts -interface Router { - route: Route - go: (href?: string) => Promise -} -``` +<<< @/../src/client/app/router.ts#Router ## `withBase` diff --git a/src/client/app/data.ts b/src/client/app/data.ts index d51ae001..389884e3 100644 --- a/src/client/app/data.ts +++ b/src/client/app/data.ts @@ -18,6 +18,7 @@ import { export const dataSymbol: InjectionKey = Symbol() +// #region VitePressData export interface VitePressData { site: Ref> page: Ref @@ -30,6 +31,7 @@ export interface VitePressData { dir: Ref localeIndex: Ref } +// #endregion VitePressData // site data is a singleton export const siteDataRef: Ref = shallowRef( diff --git a/src/client/app/router.ts b/src/client/app/router.ts index a89b3d08..28f335bc 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -5,18 +5,22 @@ import type { PageData, PageDataPayload, Awaitable } from '../shared.js' import { inBrowser, withBase } from './utils.js' import { siteDataRef } from './data.js' +// #region Route export interface Route { path: string data: PageData component: Component | null } +// #endregion Route +// #region Router export interface Router { route: Route go: (href?: string) => Promise onBeforeRouteChange?: (to: string) => Awaitable onAfterRouteChanged?: (to: string) => Awaitable } +// #endregion Router export const RouterSymbol: InjectionKey = Symbol()