vitepress 0.22.4 → 1.0.0-draft.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/client.d.ts +2 -3
  2. package/dist/client/app/components/ClientOnly.js +1 -1
  3. package/dist/client/app/index.js +1 -1
  4. package/dist/client/index.d.ts +5 -0
  5. package/dist/client/shared.js +1 -0
  6. package/dist/client/theme-default/Layout.vue +39 -180
  7. package/dist/client/theme-default/NotFound.vue +9 -8
  8. package/dist/client/theme-default/components/VPAlgoliaSearchBox.vue +127 -0
  9. package/dist/client/theme-default/components/VPBackdrop.vue +39 -0
  10. package/dist/client/theme-default/components/VPBox.vue +59 -0
  11. package/dist/client/theme-default/components/VPButton.vue +123 -0
  12. package/dist/client/theme-default/components/VPContent.vue +74 -0
  13. package/dist/client/theme-default/components/VPDoc.vue +173 -0
  14. package/dist/client/theme-default/components/VPDocFooter.vue +141 -0
  15. package/dist/client/theme-default/components/VPDocOutline.vue +108 -0
  16. package/dist/client/theme-default/components/VPFlyout.vue +149 -0
  17. package/dist/client/theme-default/components/VPFooter.vue +53 -0
  18. package/dist/client/theme-default/components/VPHero.vue +144 -0
  19. package/dist/client/theme-default/components/VPHome.vue +33 -0
  20. package/dist/client/theme-default/components/VPHomeFeatures.vue +96 -0
  21. package/dist/client/theme-default/components/VPHomeHero.vue +17 -0
  22. package/dist/client/theme-default/components/VPHomeSponsors.vue +93 -0
  23. package/dist/client/theme-default/components/VPLink.vue +37 -0
  24. package/dist/client/theme-default/components/VPLocalNav.vue +106 -0
  25. package/dist/client/theme-default/components/VPMenu.vue +79 -0
  26. package/dist/client/theme-default/components/VPMenuGroup.vue +35 -0
  27. package/dist/client/theme-default/components/VPMenuLink.vue +30 -0
  28. package/dist/client/theme-default/components/VPNav.vue +33 -0
  29. package/dist/client/theme-default/components/VPNavBar.vue +110 -0
  30. package/dist/client/theme-default/components/VPNavBarAppearance.vue +25 -0
  31. package/dist/client/theme-default/components/VPNavBarExtra.vue +107 -0
  32. package/dist/client/theme-default/components/VPNavBarHamburger.vue +79 -0
  33. package/dist/client/theme-default/components/VPNavBarMenu.vue +29 -0
  34. package/dist/client/theme-default/components/VPNavBarMenuGroup.vue +18 -0
  35. package/dist/client/theme-default/components/VPNavBarMenuLink.vue +56 -0
  36. package/dist/client/theme-default/components/VPNavBarSearch.vue +269 -0
  37. package/dist/client/theme-default/components/VPNavBarSocialLinks.vue +27 -0
  38. package/dist/client/theme-default/components/VPNavBarTitle.vue +57 -0
  39. package/dist/client/theme-default/components/VPNavBarTranslations.vue +74 -0
  40. package/dist/client/theme-default/components/VPNavScreen.vue +100 -0
  41. package/dist/client/theme-default/components/VPNavScreenAppearance.vue +33 -0
  42. package/dist/client/theme-default/components/VPNavScreenMenu.vue +24 -0
  43. package/dist/client/theme-default/components/VPNavScreenMenuGroup.vue +118 -0
  44. package/dist/client/theme-default/components/VPNavScreenMenuGroupLink.vue +33 -0
  45. package/dist/client/theme-default/components/VPNavScreenMenuGroupSection.vue +35 -0
  46. package/dist/client/theme-default/components/VPNavScreenMenuLink.vue +34 -0
  47. package/dist/client/theme-default/components/VPNavScreenSocialLinks.vue +14 -0
  48. package/dist/client/theme-default/components/VPNavScreenTranslations.vue +73 -0
  49. package/dist/client/theme-default/components/VPPage.vue +5 -0
  50. package/dist/client/theme-default/components/VPSidebar.vue +118 -0
  51. package/dist/client/theme-default/components/VPSidebarGroup.vue +44 -0
  52. package/dist/client/theme-default/components/VPSidebarLink.vue +57 -0
  53. package/dist/client/theme-default/components/VPSkipLink.vue +72 -0
  54. package/dist/client/theme-default/components/VPSocialLink.vue +63 -0
  55. package/dist/client/theme-default/components/VPSocialLinks.vue +27 -0
  56. package/dist/client/theme-default/components/VPSponsors.vue +77 -0
  57. package/dist/client/theme-default/components/VPSponsorsGrid.vue +32 -0
  58. package/dist/client/theme-default/components/VPSwitch.vue +66 -0
  59. package/dist/client/theme-default/components/VPSwitchAppearance.vue +74 -0
  60. package/dist/client/theme-default/components/icons/VPIconAlignJustify.vue +8 -0
  61. package/dist/client/theme-default/components/icons/VPIconAlignLeft.vue +8 -0
  62. package/dist/client/theme-default/components/icons/VPIconAlignRight.vue +8 -0
  63. package/dist/client/theme-default/components/icons/{ArrowLeft.vue → VPIconArrowLeft.vue} +0 -0
  64. package/dist/client/theme-default/components/icons/{ArrowRight.vue → VPIconArrowRight.vue} +0 -0
  65. package/dist/client/theme-default/components/icons/VPIconChevronDown.vue +5 -0
  66. package/dist/client/theme-default/components/icons/VPIconChevronLeft.vue +5 -0
  67. package/dist/client/theme-default/components/icons/VPIconChevronRight.vue +5 -0
  68. package/dist/client/theme-default/components/icons/VPIconChevronUp.vue +5 -0
  69. package/dist/client/theme-default/components/icons/VPIconDiscord.vue +5 -0
  70. package/dist/client/theme-default/components/icons/VPIconEdit.vue +6 -0
  71. package/dist/client/theme-default/components/icons/VPIconExternalLink.vue +13 -0
  72. package/dist/client/theme-default/components/icons/VPIconFacebook.vue +5 -0
  73. package/dist/client/theme-default/components/icons/VPIconGitHub.vue +5 -0
  74. package/dist/client/theme-default/components/icons/VPIconHeart.vue +5 -0
  75. package/dist/client/theme-default/components/icons/VPIconInstagram.vue +5 -0
  76. package/dist/client/theme-default/components/icons/VPIconLanguages.vue +9 -0
  77. package/dist/client/theme-default/components/icons/VPIconLinkedIn.vue +5 -0
  78. package/dist/client/theme-default/components/icons/VPIconMoon.vue +5 -0
  79. package/dist/client/theme-default/components/icons/VPIconMoreHorizontal.vue +7 -0
  80. package/dist/client/theme-default/components/icons/VPIconPlus.vue +5 -0
  81. package/dist/client/theme-default/components/icons/VPIconSlack.vue +5 -0
  82. package/dist/client/theme-default/components/icons/VPIconSun.vue +13 -0
  83. package/dist/client/theme-default/components/icons/VPIconTwitter.vue +5 -0
  84. package/dist/client/theme-default/components/icons/VPIconYouTube.vue +5 -0
  85. package/dist/client/theme-default/composables/edit-link.js +22 -0
  86. package/dist/client/theme-default/composables/flyout.js +40 -0
  87. package/dist/client/theme-default/composables/nav.js +27 -1
  88. package/dist/client/theme-default/composables/outline.js +112 -0
  89. package/dist/client/theme-default/composables/prev-next.js +18 -0
  90. package/dist/client/theme-default/composables/sidebar.js +57 -0
  91. package/dist/client/theme-default/composables/sponsor-grid.js +92 -0
  92. package/dist/client/theme-default/fonts/inter-cyrillic-ext.woff2 +0 -0
  93. package/dist/client/theme-default/fonts/inter-cyrillic.woff2 +0 -0
  94. package/dist/client/theme-default/fonts/inter-greek-ext.woff2 +0 -0
  95. package/dist/client/theme-default/fonts/inter-greek.woff2 +0 -0
  96. package/dist/client/theme-default/fonts/inter-latin-ext.woff2 +0 -0
  97. package/dist/client/theme-default/fonts/inter-latin.woff2 +0 -0
  98. package/dist/client/theme-default/fonts/inter-vietnamese.woff2 +0 -0
  99. package/dist/client/theme-default/index.js +8 -4
  100. package/dist/client/theme-default/styles/base.css +203 -0
  101. package/dist/client/theme-default/styles/fonts.css +67 -0
  102. package/dist/client/theme-default/styles/utils.css +9 -0
  103. package/dist/client/theme-default/styles/vars.css +291 -66
  104. package/dist/client/theme-default/styles/vp-doc.css +425 -0
  105. package/dist/client/theme-default/styles/vp-sponsor.css +86 -0
  106. package/dist/client/theme-default/support/sidebar.js +29 -0
  107. package/dist/client/theme-default/support/utils.js +62 -0
  108. package/dist/node/cli.js +3 -8
  109. package/dist/node/index.d.ts +121 -78
  110. package/dist/node/index.js +1 -1
  111. package/dist/node/{serve-3035f99b.js → serve-b5dc02b2.js} +11444 -1417
  112. package/package.json +24 -18
  113. package/types/default-theme.d.ts +114 -77
  114. package/types/shared.d.ts +11 -6
  115. package/dist/client/theme-default/components/AlgoliaSearchBox.vue +0 -188
  116. package/dist/client/theme-default/components/BuySellAds.vue +0 -152
  117. package/dist/client/theme-default/components/CarbonAds.vue +0 -99
  118. package/dist/client/theme-default/components/EditLink.vue +0 -38
  119. package/dist/client/theme-default/components/Home.vue +0 -31
  120. package/dist/client/theme-default/components/HomeFeatures.vue +0 -143
  121. package/dist/client/theme-default/components/HomeFooter.vue +0 -50
  122. package/dist/client/theme-default/components/HomeHero.vue +0 -161
  123. package/dist/client/theme-default/components/LastUpdated.vue +0 -60
  124. package/dist/client/theme-default/components/NavBar.vue +0 -60
  125. package/dist/client/theme-default/components/NavBarTitle.vue +0 -41
  126. package/dist/client/theme-default/components/NavDropdownLink.vue +0 -135
  127. package/dist/client/theme-default/components/NavDropdownLinkItem.vue +0 -76
  128. package/dist/client/theme-default/components/NavLink.vue +0 -61
  129. package/dist/client/theme-default/components/NavLinks.vue +0 -52
  130. package/dist/client/theme-default/components/NextAndPrevLinks.vue +0 -88
  131. package/dist/client/theme-default/components/Page.vue +0 -53
  132. package/dist/client/theme-default/components/PageFooter.vue +0 -44
  133. package/dist/client/theme-default/components/SideBar.vue +0 -60
  134. package/dist/client/theme-default/components/SideBarLink.js +0 -68
  135. package/dist/client/theme-default/components/SideBarLinks.vue +0 -12
  136. package/dist/client/theme-default/components/ToggleSideBarButton.vue +0 -46
  137. package/dist/client/theme-default/components/icons/OutboundLink.vue +0 -31
  138. package/dist/client/theme-default/composables/activeSidebarLink.js +0 -99
  139. package/dist/client/theme-default/composables/editLink.js +0 -49
  140. package/dist/client/theme-default/composables/navLink.js +0 -42
  141. package/dist/client/theme-default/composables/nextAndPrevLinks.js +0 -37
  142. package/dist/client/theme-default/composables/repo.js +0 -38
  143. package/dist/client/theme-default/composables/sideBar.js +0 -57
  144. package/dist/client/theme-default/styles/code.css +0 -299
  145. package/dist/client/theme-default/styles/custom-blocks.css +0 -76
  146. package/dist/client/theme-default/styles/layout.css +0 -236
  147. package/dist/client/theme-default/styles/sidebar-links.css +0 -107
  148. package/dist/client/theme-default/support/sideBar.js +0 -46
  149. package/dist/client/theme-default/utils.js +0 -63
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "vitepress",
3
- "version": "0.22.4",
3
+ "version": "1.0.0-draft.3",
4
+ "packageManager": "pnpm@7.0.1",
4
5
  "description": "Vite & Vue powered static site generator",
5
6
  "main": "dist/node/index.js",
6
7
  "typings": "types/index.d.ts",
@@ -14,20 +15,6 @@
14
15
  "client.d.ts",
15
16
  "theme.d.ts"
16
17
  ],
17
- "engines": {
18
- "node": ">=14.0.0"
19
- },
20
- "gitHooks": {
21
- "pre-commit": "lint-staged"
22
- },
23
- "lint-staged": {
24
- "*.js": [
25
- "prettier --write"
26
- ],
27
- "*.ts": [
28
- "prettier --parser=typescript --write"
29
- ]
30
- },
31
18
  "repository": {
32
19
  "type": "git",
33
20
  "url": "git+https://github.com/vuejs/vitepress.git"
@@ -39,17 +26,33 @@
39
26
  ],
40
27
  "author": "Evan You",
41
28
  "license": "MIT",
42
- "homepage": "https://github.com/vuejs/vitepress/tree/master/#readme",
29
+ "homepage": "https://github.com/vuejs/vitepress/tree/main/#readme",
43
30
  "bugs": {
44
31
  "url": "https://github.com/vuejs/vitepress/issues"
45
32
  },
33
+ "engines": {
34
+ "node": ">=14.0.0"
35
+ },
36
+ "gitHooks": {
37
+ "pre-commit": "lint-staged"
38
+ },
39
+ "lint-staged": {
40
+ "*.js": [
41
+ "prettier --write"
42
+ ],
43
+ "*.ts": [
44
+ "prettier --parser=typescript --write"
45
+ ]
46
+ },
46
47
  "dependencies": {
47
48
  "@docsearch/css": "^3.0.0",
48
49
  "@docsearch/js": "^3.0.0",
49
50
  "@vitejs/plugin-vue": "^2.3.2",
51
+ "@vueuse/core": "^8.5.0",
52
+ "body-scroll-lock": "^4.0.0-beta.0",
50
53
  "prismjs": "^1.25.0",
51
54
  "vite": "^2.9.7",
52
- "vue": "^3.2.33"
55
+ "vue": "3.2.33"
53
56
  },
54
57
  "devDependencies": {
55
58
  "@microsoft/api-extractor": "^7.23.1",
@@ -57,6 +60,7 @@
57
60
  "@rollup/plugin-commonjs": "^20.0.0",
58
61
  "@rollup/plugin-json": "^4.1.0",
59
62
  "@rollup/plugin-node-resolve": "^13.0.4",
63
+ "@types/body-scroll-lock": "^3.1.0",
60
64
  "@types/compression": "^1.7.0",
61
65
  "@types/cross-spawn": "^6.0.2",
62
66
  "@types/debug": "^4.1.7",
@@ -66,6 +70,7 @@
66
70
  "@types/lru-cache": "^5.1.0",
67
71
  "@types/markdown-it": "^12.0.1",
68
72
  "@types/micromatch": "^4.0.2",
73
+ "@types/minimist": "^1.2.2",
69
74
  "@types/node": "^15.6.1",
70
75
  "@types/polka": "^0.5.3",
71
76
  "chalk": "^4.1.1",
@@ -123,7 +128,8 @@
123
128
  "lint": "run-s lint:js lint:ts",
124
129
  "lint:js": "prettier --check --write \"{bin,docs,scripts,src}/**/*.js\"",
125
130
  "lint:ts": "prettier --check --write --parser typescript \"{__tests__,src,docs,types}/**/*.ts\"",
126
- "test": "vitest run __tests__ -c __tests__/vitest.config.js --globals",
131
+ "test": "vitest run __tests__ -c __tests__/vitest.config.js --global",
132
+ "test:all": "run-s lint test",
127
133
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
128
134
  "release": "node scripts/release.js",
129
135
  "docs": "run-p dev docs-dev",
@@ -1,125 +1,168 @@
1
1
  export namespace DefaultTheme {
2
2
  export interface Config {
3
- logo?: string
4
- nav?: NavItem[] | false
5
- sidebar?: SideBarConfig | MultiSideBarConfig
6
-
7
3
  /**
8
- * GitHub repository following the format <user>/<project>.
4
+ * The logo file of the site.
9
5
  *
10
- * @example `"vuejs/vue-next"`
6
+ * @example '/logo.svg'
11
7
  */
12
- repo?: string
8
+ logo?: string
13
9
 
14
10
  /**
15
- * Customize the header label. Defaults to GitHub/Gitlab/Bitbucket
16
- * depending on the provided repo.
17
- *
18
- * @example `"Contribute!"`
11
+ * The nav items.
19
12
  */
20
- repoLabel?: string
13
+ nav?: NavItem[]
21
14
 
22
15
  /**
23
- * If your docs are in a different repository from your main project.
24
- *
25
- * @example `"vuejs/docs-next"`
16
+ * The sidebar items.
26
17
  */
27
- docsRepo?: string
18
+ sidebar?: Sidebar
28
19
 
29
20
  /**
30
- * If your docs are not at the root of the repo.
31
- *
32
- * @example `"docs"`
21
+ * Info for the edit link. If it's undefined, the edit link feature will
22
+ * be disabled.
33
23
  */
34
- docsDir?: string
24
+ editLink?: EditLink
35
25
 
36
26
  /**
37
- * If your docs are in a different branch. Defaults to `master`.
38
- *
39
- * @example `"next"`
27
+ * The social links to be displayed at the end of the nav bar. Perfect for
28
+ * placing links to social services such as GitHub, Twitter, Facebook, etc.
40
29
  */
41
- docsBranch?: string
30
+ socialLinks?: SocialLink[]
42
31
 
43
32
  /**
44
- * Enable links to edit pages at the bottom of the page.
33
+ * The footer configuration.
45
34
  */
46
- editLinks?: boolean
35
+ footer?: Footer
47
36
 
48
37
  /**
49
- * Custom text for edit link. Defaults to "Edit this page".
38
+ * Adds locale menu to the nav. This option should be used when you have
39
+ * your translated sites outside of the project.
50
40
  */
51
- editLinkText?: string
41
+ localeLinks?: LocaleLinks
52
42
 
53
43
  /**
54
- * Show last updated time at the bottom of the page. Defaults to `false`.
55
- * If given a string, it will be displayed as a prefix (default value:
56
- * "Last Updated").
44
+ * The algolia options. Leave it undefined to disable the search feature.
57
45
  */
58
- lastUpdated?: string | boolean
59
-
60
- prevLinks?: boolean
61
- nextLinks?: boolean
62
-
63
- locales?: Record<string, LocaleConfig & Omit<Config, 'locales'>>
64
-
65
46
  algolia?: AlgoliaSearchOptions
66
47
 
67
- carbonAds?: {
68
- carbon: string
69
- custom?: string
70
- placement: string
71
- }
48
+ /**
49
+ * The carbon ads options. Leave it undefined to disable the ads feature.
50
+ */
51
+ carbonAds?: CarbonAdsOptions
72
52
  }
73
53
 
74
- // navbar --------------------------------------------------------------------
54
+ // nav -----------------------------------------------------------------------
75
55
 
76
56
  export type NavItem = NavItemWithLink | NavItemWithChildren
77
57
 
78
- export interface NavItemBase {
58
+ export type NavItemWithLink = {
79
59
  text: string
80
- target?: string
81
- rel?: string
82
- ariaLabel?: string
83
- activeMatch?: string
84
- }
85
-
86
- export interface NavItemWithLink extends NavItemBase {
87
60
  link: string
61
+
62
+ /**
63
+ * `activeMatch` is expected to be a regex string. We can't use actual
64
+ * RegExp object here because it isn't serializable
65
+ */
66
+ activeMatch?: string
88
67
  }
89
68
 
90
- export interface NavItemWithChildren extends NavItemBase {
69
+ export interface NavItemWithChildren {
70
+ text?: string
91
71
  items: NavItemWithLink[]
92
72
  }
93
73
 
94
74
  // sidebar -------------------------------------------------------------------
95
75
 
96
- export type SideBarConfig = SideBarItem[] | 'auto' | false
76
+ export type Sidebar = SidebarGroup[] | SidebarMulti
97
77
 
98
- export interface MultiSideBarConfig {
99
- [path: string]: SideBarConfig
78
+ export interface SidebarMulti {
79
+ [path: string]: SidebarGroup[]
100
80
  }
101
81
 
102
- export type SideBarItem = SideBarLink | SideBarGroup
82
+ export interface SidebarGroup {
83
+ text: string
84
+ items: SidebarItem[]
85
+ }
103
86
 
104
- export interface SideBarLink {
87
+ export interface SidebarItem {
105
88
  text: string
106
89
  link: string
107
90
  }
108
91
 
109
- export interface SideBarGroup {
110
- text: string
111
- link?: string
92
+ // edit link -----------------------------------------------------------------
93
+
94
+ export interface EditLink {
95
+ /**
96
+ * Repo of the site.
97
+ *
98
+ * @example 'vuejs/docs'
99
+ */
100
+ repo: string
101
+
102
+ /**
103
+ * Branch of the repo.
104
+ *
105
+ * @default 'main'
106
+ */
107
+ branch?: string
112
108
 
113
109
  /**
114
- * @default false
110
+ * If your docs are not at the root of the repo.
111
+ *
112
+ * @example 'docs'
115
113
  */
116
- collapsable?: boolean
114
+ dir?: string
117
115
 
118
- children: SideBarItem[]
116
+ /**
117
+ * Custom text for edit link.
118
+ *
119
+ * @default 'Edit this page'
120
+ */
121
+ text?: string
119
122
  }
120
123
 
121
- // algolia ------------------------------------------------------------------
122
- // partially copied from @docsearch/react/dist/esm/DocSearch.d.ts
124
+ // social link ---------------------------------------------------------------
125
+
126
+ export interface SocialLink {
127
+ icon: SocialLinkIcon
128
+ link: string
129
+ }
130
+
131
+ export type SocialLinkIcon =
132
+ | 'discord'
133
+ | 'facebook'
134
+ | 'github'
135
+ | 'instagram'
136
+ | 'linkedin'
137
+ | 'slack'
138
+ | 'twitter'
139
+ | 'youtube'
140
+
141
+ // footer --------------------------------------------------------------------
142
+
143
+ export interface Footer {
144
+ message?: string
145
+ copyright?: string
146
+ }
147
+
148
+ // locales -------------------------------------------------------------------
149
+
150
+ export interface LocaleLinks {
151
+ text: string
152
+ items: LocaleLink[]
153
+ }
154
+
155
+ export interface LocaleLink {
156
+ text: string
157
+ link: string
158
+ }
159
+
160
+ // algolia ------------------------------------------------------------------
161
+
162
+ /**
163
+ * The Algolia search options. Partially copied from
164
+ * `@docsearch/react/dist/esm/DocSearch.d.ts`
165
+ */
123
166
  export interface AlgoliaSearchOptions {
124
167
  appId: string
125
168
  apiKey: string
@@ -130,17 +173,11 @@ export namespace DefaultTheme {
130
173
  initialQuery?: string
131
174
  }
132
175
 
133
- // locales -------------------------------------------------------------------
176
+ // carbon ads ----------------------------------------------------------------
134
177
 
135
- export interface LocaleConfig {
136
- /**
137
- * Text for the language dropdown.
138
- */
139
- selectText?: string
140
-
141
- /**
142
- * Label for this locale in the language dropdown.
143
- */
144
- label?: string
178
+ export interface CarbonAdsOptions {
179
+ carbon: string
180
+ custom?: string
181
+ placement: string
145
182
  }
146
183
  }
package/types/shared.d.ts CHANGED
@@ -11,19 +11,30 @@ export interface PageData {
11
11
  lastUpdated?: number
12
12
  }
13
13
 
14
+ export interface Header {
15
+ level: number
16
+ title: string
17
+ slug: string
18
+ }
19
+
14
20
  export interface SiteData<ThemeConfig = any> {
15
21
  base: string
22
+
16
23
  /**
17
24
  * Language of the site as it should be set on the `html` element.
25
+ *
18
26
  * @example `en-US`, `zh-CN`
19
27
  */
20
28
  lang: string
29
+
21
30
  title: string
22
31
  description: string
23
32
  head: HeadConfig[]
33
+ appearance: boolean
24
34
  themeConfig: ThemeConfig
25
35
  scrollOffset: number | string
26
36
  locales: Record<string, LocaleConfig>
37
+
27
38
  /**
28
39
  * Available locales for the site when it has defined `locales` in its
29
40
  * `themeConfig`. This object is otherwise empty. Keys are paths like `/` or
@@ -50,12 +61,6 @@ export type HeadConfig =
50
61
  | [string, Record<string, string>]
51
62
  | [string, Record<string, string>, string]
52
63
 
53
- export interface Header {
54
- level: number
55
- title: string
56
- slug: string
57
- }
58
-
59
64
  export interface LocaleConfig {
60
65
  lang: string
61
66
  title?: string
@@ -1,188 +0,0 @@
1
- <script setup lang="ts">
2
- import '@docsearch/css'
3
- import docsearch from '@docsearch/js'
4
- import { useRoute, useRouter, useData } from 'vitepress'
5
- import { getCurrentInstance, onMounted, watch } from 'vue'
6
- import type { DefaultTheme } from '../config'
7
- import type { DocSearchHit } from '@docsearch/react/dist/esm/types'
8
-
9
- const props = defineProps<{
10
- options: DefaultTheme.AlgoliaSearchOptions
11
- multilang?: boolean
12
- }>()
13
-
14
- const vm = getCurrentInstance()
15
- const route = useRoute()
16
- const router = useRouter()
17
-
18
- watch(
19
- () => props.options,
20
- (value) => {
21
- update(value)
22
- }
23
- )
24
-
25
- onMounted(() => {
26
- initialize(props.options)
27
- })
28
-
29
- function isSpecialClick(event: MouseEvent) {
30
- return (
31
- event.button === 1 ||
32
- event.altKey ||
33
- event.ctrlKey ||
34
- event.metaKey ||
35
- event.shiftKey
36
- )
37
- }
38
-
39
- function getRelativePath(absoluteUrl: string) {
40
- const { pathname, hash } = new URL(absoluteUrl)
41
-
42
- return pathname + hash
43
- }
44
-
45
- function update(options: any) {
46
- if (vm && vm.vnode.el) {
47
- vm.vnode.el.innerHTML =
48
- '<div class="algolia-search-box" id="docsearch"></div>'
49
- initialize(options)
50
- }
51
- }
52
-
53
- const { lang } = useData()
54
-
55
- // if the user has multiple locales, the search results should be filtered
56
- // based on the language
57
- const facetFilters: string[] = props.multilang ? ['lang:' + lang.value] : []
58
-
59
- if (props.options.searchParameters?.facetFilters) {
60
- facetFilters.push(...props.options.searchParameters.facetFilters)
61
- }
62
-
63
- watch(lang, (newLang, oldLang) => {
64
- const index = facetFilters.findIndex((filter) => filter === 'lang:' + oldLang)
65
- if (index > -1) {
66
- facetFilters.splice(index, 1, 'lang:' + newLang)
67
- }
68
- })
69
-
70
- function initialize(userOptions: any) {
71
- docsearch(
72
- Object.assign({}, userOptions, {
73
- container: '#docsearch',
74
-
75
- searchParameters: Object.assign({}, userOptions.searchParameters, {
76
- // pass a custom lang facetFilter to allow multiple language search
77
- // https://github.com/algolia/docsearch-configs/pull/3942
78
- facetFilters
79
- }),
80
-
81
- navigator: {
82
- navigate: ({ itemUrl }: { itemUrl: string }) => {
83
- const { pathname: hitPathname } = new URL(
84
- window.location.origin + itemUrl
85
- )
86
-
87
- // Router doesn't handle same-page navigation so we use the native
88
- // browser location API for anchor navigation
89
- if (route.path === hitPathname) {
90
- window.location.assign(window.location.origin + itemUrl)
91
- } else {
92
- router.go(itemUrl)
93
- }
94
- }
95
- },
96
-
97
- transformItems: (items: DocSearchHit[]) => {
98
- return items.map((item) => {
99
- return Object.assign({}, item, {
100
- url: getRelativePath(item.url)
101
- })
102
- })
103
- },
104
-
105
- hitComponent: ({
106
- hit,
107
- children
108
- }: {
109
- hit: DocSearchHit
110
- children: any
111
- }) => {
112
- const relativeHit = hit.url.startsWith('http')
113
- ? getRelativePath(hit.url as string)
114
- : hit.url
115
-
116
- return {
117
- type: 'a',
118
- ref: undefined,
119
- constructor: undefined,
120
- key: undefined,
121
- props: {
122
- href: hit.url,
123
- onClick: (event: MouseEvent) => {
124
- if (isSpecialClick(event)) {
125
- return
126
- }
127
-
128
- // we rely on the native link scrolling when user is already on
129
- // the right anchor because Router doesn't support duplicated
130
- // history entries
131
- if (route.path === relativeHit) {
132
- return
133
- }
134
-
135
- // if the hits goes to another page, we prevent the native link
136
- // behavior to leverage the Router loading feature
137
- if (route.path !== relativeHit) {
138
- event.preventDefault()
139
- }
140
-
141
- router.go(relativeHit)
142
- },
143
- children
144
- },
145
- __v: null
146
- }
147
- }
148
- })
149
- )
150
- }
151
- </script>
152
-
153
- <template>
154
- <div class="algolia-search-box" id="docsearch" />
155
- </template>
156
-
157
- <style>
158
- .algolia-search-box {
159
- padding-top: 1px;
160
- }
161
-
162
- @media (min-width: 720px) {
163
- .algolia-search-box {
164
- padding-left: 8px;
165
- }
166
- }
167
-
168
- @media (min-width: 751px) {
169
- .algolia-search-box {
170
- min-width: 176.3px; /* avoid layout shift */
171
- }
172
-
173
- .algolia-search-box .DocSearch-Button-Placeholder {
174
- padding-left: 8px;
175
- font-size: 0.9rem;
176
- font-weight: 500;
177
- }
178
- }
179
-
180
- .DocSearch {
181
- --docsearch-primary-color: var(--c-brand);
182
- --docsearch-highlight-color: var(--docsearch-primary-color);
183
- --docsearch-searchbox-shadow: inset 0 0 0 2px var(--docsearch-primary-color);
184
- --docsearch-text-color: var(--c-text-light);
185
- --docsearch-muted-color: var(--c-text-lighter);
186
- --docsearch-searchbox-background: #f2f2f2;
187
- }
188
- </style>