shared.d.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. // types shared between server and client
  2. import type { UseDarkOptions } from '@vueuse/core'
  3. import type { SSRContext } from 'vue/server-renderer'
  4. export type { DefaultTheme } from './default-theme.js'
  5. export type Awaitable<T> = T | PromiseLike<T>
  6. type DeepPartial<T> =
  7. T extends Record<string, any>
  8. ? T extends
  9. | Date
  10. | RegExp
  11. | Function
  12. | ReadonlyMap<any, any>
  13. | ReadonlySet<any>
  14. | ReadonlyArray<any>
  15. ? T
  16. : { [P in keyof T]?: DeepPartial<T[P]> }
  17. : T
  18. export interface PageData {
  19. relativePath: string
  20. /**
  21. * differs from relativePath in case of path rewrites
  22. * empty string if the page is virtual (e.g. 404 page)
  23. */
  24. filePath: string
  25. title: string
  26. titleTemplate?: string | boolean
  27. description: string
  28. headers: Header[]
  29. frontmatter: Record<string, any>
  30. params?: Record<string, any>
  31. isNotFound?: boolean
  32. lastUpdated?: number
  33. }
  34. /**
  35. * SFC block extracted from markdown
  36. */
  37. export interface SfcBlock {
  38. /**
  39. * The type of the block
  40. */
  41. type: string
  42. /**
  43. * The content, including open-tag and close-tag
  44. */
  45. content: string
  46. /**
  47. * The content that stripped open-tag and close-tag off
  48. */
  49. contentStripped: string
  50. /**
  51. * The open-tag
  52. */
  53. tagOpen: string
  54. /**
  55. * The close-tag
  56. */
  57. tagClose: string
  58. }
  59. export interface MarkdownSfcBlocks {
  60. /**
  61. * The `<template>` block
  62. */
  63. template: SfcBlock | null
  64. /**
  65. * The common `<script>` block
  66. */
  67. script: SfcBlock | null
  68. /**
  69. * The `<script setup>` block
  70. */
  71. scriptSetup: SfcBlock | null
  72. /**
  73. * All `<script>` blocks.
  74. *
  75. * By default, SFC only allows one `<script>` block and one `<script setup>` block.
  76. * However, some tools may support different types of `<script>`s, so we keep all of them here.
  77. */
  78. scripts: SfcBlock[]
  79. /**
  80. * All `<style>` blocks.
  81. */
  82. styles: SfcBlock[]
  83. /**
  84. * All custom blocks.
  85. */
  86. customBlocks: SfcBlock[]
  87. }
  88. export interface Header {
  89. /**
  90. * The level of the header
  91. *
  92. * `1` to `6` for `<h1>` to `<h6>`
  93. */
  94. level: number
  95. /**
  96. * The title of the header
  97. */
  98. title: string
  99. /**
  100. * The slug of the header
  101. *
  102. * Typically the `id` attr of the header anchor
  103. */
  104. slug: string
  105. /**
  106. * Link of the header
  107. *
  108. * Typically using `#${slug}` as the anchor hash
  109. */
  110. link: string
  111. /**
  112. * The children of the header
  113. */
  114. children: Header[]
  115. }
  116. export interface SiteData<ThemeConfig = any> {
  117. base: string
  118. cleanUrls?: boolean
  119. lang: string
  120. dir: string
  121. title: string
  122. titleTemplate?: string | boolean
  123. description: string
  124. head: HeadConfig[]
  125. appearance:
  126. | boolean
  127. | 'dark'
  128. | 'force-dark'
  129. | 'force-auto'
  130. | (Omit<UseDarkOptions, 'initialValue'> & { initialValue?: 'dark' })
  131. themeConfig: ThemeConfig
  132. scrollOffset:
  133. | number
  134. | string
  135. | string[]
  136. | { selector: string | string[]; padding: number }
  137. locales: LocaleConfig<ThemeConfig>
  138. localeIndex?: string
  139. contentProps?: Record<string, any>
  140. router: {
  141. prefetchLinks: boolean
  142. }
  143. additionalConfig?:
  144. | AdditionalConfigDict<ThemeConfig>
  145. | AdditionalConfigLoader<ThemeConfig>
  146. }
  147. export type HeadConfig =
  148. | [string, Record<string, string>]
  149. | [string, Record<string, string>, string]
  150. export interface PageDataPayload {
  151. path: string
  152. pageData: PageData
  153. }
  154. export interface SSGContext extends SSRContext {
  155. content: string
  156. /** @experimental */
  157. vpSocialIcons: Set<string>
  158. }
  159. export interface LocaleSpecificConfig<ThemeConfig = any> {
  160. lang?: string
  161. dir?: string
  162. title?: string
  163. titleTemplate?: string | boolean
  164. description?: string
  165. head?: HeadConfig[]
  166. themeConfig?: DeepPartial<ThemeConfig>
  167. }
  168. export type LocaleConfig<ThemeConfig = any> = Record<
  169. string,
  170. LocaleSpecificConfig<ThemeConfig> & { label: string; link?: string }
  171. >
  172. export type AdditionalConfig<ThemeConfig = any> =
  173. LocaleSpecificConfig<ThemeConfig>
  174. export type AdditionalConfigDict<ThemeConfig = any> = Record<
  175. string,
  176. AdditionalConfig<ThemeConfig>
  177. >
  178. export type AdditionalConfigLoader<ThemeConfig = any> = (
  179. relativePath: string
  180. ) => AdditionalConfig<ThemeConfig>[]
  181. // Manually declaring all properties as rollup-plugin-dts
  182. // is unable to merge augmented module declarations
  183. export interface MarkdownEnv {
  184. /**
  185. * The raw Markdown content without frontmatter
  186. */
  187. content?: string
  188. /**
  189. * The excerpt that extracted by `@mdit-vue/plugin-frontmatter`
  190. *
  191. * - Would be the rendered HTML when `renderExcerpt` is enabled
  192. * - Would be the raw Markdown when `renderExcerpt` is disabled
  193. */
  194. excerpt?: string
  195. /**
  196. * The frontmatter that extracted by `@mdit-vue/plugin-frontmatter`
  197. */
  198. frontmatter?: Record<string, unknown>
  199. /**
  200. * The headers that extracted by `@mdit-vue/plugin-headers`
  201. */
  202. headers?: Header[]
  203. /**
  204. * SFC blocks that extracted by `@mdit-vue/plugin-sfc`
  205. */
  206. sfcBlocks?: MarkdownSfcBlocks
  207. /**
  208. * The title that extracted by `@mdit-vue/plugin-title`
  209. */
  210. title?: string
  211. path: string
  212. relativePath: string
  213. cleanUrls: boolean
  214. links?: string[]
  215. includes?: string[]
  216. realPath?: string
  217. localeIndex?: string
  218. }