Skip to content

Commit f328b54

Browse files
authored
docs: switch to local search (#3594)
1 parent 4c50e88 commit f328b54

17 files changed

+106
-58
lines changed

Diff for: .vitepress/components.d.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
// @ts-nocheck
44
// Generated by unplugin-vue-components
55
// Read more: https://github.com/vuejs/core/pull/3399
6-
import '@vue/runtime-core'
7-
86
export {}
97

10-
declare module '@vue/runtime-core' {
8+
declare module 'vue' {
119
export interface GlobalComponents {
1210
Contributors: typeof import('./components/Contributors.vue')['default']
1311
CourseLink: typeof import('./components/CourseLink.vue')['default']

Diff for: .vitepress/config.ts

+14-17
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ export default withPwa(defineConfig({
2424
locales: {
2525
root: {
2626
label: 'English',
27-
lang: 'en',
27+
lang: 'en-US',
2828
},
29-
en: {
29+
zh: {
3030
label: '简体中文',
3131
lang: 'zh',
3232
link: 'https://cn.vitest.dev/',
3333
},
3434
},
3535
head: [
3636
['meta', { name: 'theme-color', content: '#729b1a' }],
37+
['link', { rel: 'icon', href: '/favicon.ico', sizes: 'any' }],
3738
['link', { rel: 'icon', href: '/logo.svg', type: 'image/svg+xml' }],
38-
['link', { rel: 'alternate icon', href: '/favicon.ico', type: 'image/png', sizes: '16x16' }],
3939
['meta', { name: 'author', content: `${teamMembers.map(c => c.name).join(', ')} and ${vitestName} contributors` }],
4040
['meta', { name: 'keywords', content: 'vitest, vite, test, coverage, snapshot, react, vue, preact, svelte, solid, lit, ruby, cypress, puppeteer, jsdom, happy-dom, test-runner, jest, typescript, esm, tinypool, tinyspy, c8, node' }],
4141
['meta', { property: 'og:title', content: vitestName }],
@@ -66,20 +66,17 @@ export default withPwa(defineConfig({
6666
text: 'Suggest changes to this page',
6767
},
6868

69-
algolia: {
70-
appId: 'ZTF29HGJ69',
71-
apiKey: '9c3ced6fed60d2670bb36ab7e8bed8bc',
72-
indexName: 'vitest',
73-
// searchParameters: {
74-
// facetFilters: ['tags:en'],
75-
// },
76-
},
77-
78-
localeLinks: {
79-
text: 'English',
80-
items: [
81-
{ text: '简体中文', link: 'https://cn.vitest.dev' },
82-
],
69+
search: {
70+
provider: 'local',
71+
/* provider: 'algolia',
72+
options: {
73+
appId: 'ZTF29HGJ69',
74+
apiKey: '9c3ced6fed60d2670bb36ab7e8bed8bc',
75+
indexName: 'vitest',
76+
// searchParameters: {
77+
// facetFilters: ['tags:en'],
78+
// },
79+
}, */
8380
},
8481

8582
socialLinks: [

Diff for: .vitepress/scripts/fetch-avatars.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { join, resolve } from 'pathe'
1+
import { fileURLToPath } from 'node:url'
2+
import { dirname, join, resolve } from 'pathe'
23
import fs from 'fs-extra'
34
import { $fetch } from 'ohmyfetch'
45

5-
const docsDir = resolve(__dirname, '../..')
6+
const docsDir = resolve(dirname(fileURLToPath(import.meta.url)), '../..')
67
const pathContributors = resolve(docsDir, '.vitepress/contributor-names.json')
78
const dirAvatars = resolve(docsDir, 'public/user-avatars/')
89
const dirSponsors = resolve(docsDir, 'public/sponsors/')

Diff for: .vitepress/scripts/pwa.ts

+32-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { VitePWAOptions } from 'vite-plugin-pwa'
1+
import type { PwaOptions } from '@vite-pwa/vitepress'
22
import {
33
githubusercontentRegex,
44
pwaFontStylesRegex,
@@ -8,7 +8,7 @@ import {
88
vitestShortName,
99
} from '../meta'
1010

11-
export const pwa: Partial<VitePWAOptions> = {
11+
export const pwa: PwaOptions = {
1212
outDir: '.vitepress/dist',
1313
registerType: 'autoUpdate',
1414
// include all static assets under public/
@@ -18,7 +18,19 @@ export const pwa: Partial<VitePWAOptions> = {
1818
short_name: vitestShortName,
1919
description: vitestDescription,
2020
theme_color: '#ffffff',
21+
start_url: '/',
22+
lang: 'en-US',
23+
dir: 'ltr',
24+
orientation: 'natural',
25+
display: 'standalone',
26+
display_override: ['window-controls-overlay'],
27+
categories: ['development', 'developer tools'],
2128
icons: [
29+
{
30+
src: 'pwa-64x64.png',
31+
sizes: '64x64',
32+
type: 'image/png',
33+
},
2234
{
2335
src: 'pwa-192x192.png',
2436
sizes: '192x192',
@@ -28,14 +40,28 @@ export const pwa: Partial<VitePWAOptions> = {
2840
src: 'pwa-512x512.png',
2941
sizes: '512x512',
3042
type: 'image/png',
43+
purpose: 'any',
3144
},
3245
{
33-
src: 'logo.svg',
34-
sizes: '165x165',
35-
type: 'image/svg',
36-
purpose: 'any maskable',
46+
src: 'maskable-icon.png',
47+
sizes: '512x512',
48+
type: 'image/png',
49+
purpose: 'maskable',
3750
},
3851
],
52+
screenshots: [{
53+
src: 'og.png',
54+
sizes: '2258x1185',
55+
type: 'image/png',
56+
label: `Screenshot of ${vitestName}`,
57+
}],
58+
handle_links: 'preferred',
59+
launch_handler: {
60+
client_mode: ['navigate-existing', 'auto'],
61+
},
62+
edge_side_panel: {
63+
preferred_width: 480,
64+
},
3965
},
4066
workbox: {
4167
navigateFallbackDenylist: [/^\/new$/],

Diff for: .vitepress/scripts/transformHead.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ export async function transformHead({ pageData }: TransformContext): Promise<Hea
1313
})
1414

1515
head.push(['link', { rel: 'prefetch', href: '/logo.svg' }])
16-
if (home)
16+
if (home) {
17+
head.push(['link', { rel: 'prefetch', href: '/logo-shadow.svg' }])
18+
head.push(['link', { rel: 'prefetch', href: '/sponsors/antfu.svg' }])
19+
head.push(['link', { rel: 'prefetch', href: '/sponsors/sheremet-va.svg' }])
20+
head.push(['link', { rel: 'prefetch', href: '/sponsors/patak-dev.svg' }])
1721
head.push(['link', { rel: 'prefetch', href: '/netlify.svg' }])
22+
}
1823

1924
return head
2025
}

Diff for: .vitepress/style/main.css

-2
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,3 @@ img.resizable-img {
7474
min-height: unset;
7575
}
7676
}
77-
78-

Diff for: .vitepress/style/vars.css

-11
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@
1919
--vp-c-text-light-2: rgba(56 56 56 / 70%);
2020
/* fix contrast: lang name on gray code block */
2121
--vp-c-text-dark-3: rgba(180, 180, 180, 0.7);
22-
--vp-code-tab-divider: var(--vp-c-divider);
2322
--vp-code-copy-code-bg: rgba(125,125,125,0.1);
2423
--vp-code-copy-code-hover-bg: rgba(125,125,125,0.2);
2524
--vp-c-disabled-bg: rgba(125,125,125,0.2);
26-
--vp-code-tab-text-color: var(--vp-c-text-2);
27-
--vp-code-tab-hover-text-color: var(--vp-c-text-1);
28-
--vp-code-copy-code-active-text: var(--vp-c-text-2);
2925
}
3026

3127
.dark {
@@ -39,10 +35,6 @@
3935
--vp-c-text-dark-2: rgba(235, 235, 235, 0.60);
4036
/* fix lang name: check the same above (this is the default) */
4137
--vp-c-text-dark-3: rgba(235, 235, 235, 0.38);
42-
--vp-code-tab-text-color: var(--vp-c-text-dark-2);
43-
--vp-code-tab-active-text-color: var(--vp-c-text-dark-1);
44-
--vp-code-tab-hover-text-color: var(--vp-c-text-dark-1);
45-
--vp-code-copy-code-active-text: var(--vp-c-text-dark-2);
4638
}
4739

4840
/**
@@ -59,9 +51,6 @@
5951
--vp-button-brand-active-border: var(--vp-c-brand-light);
6052
--vp-button-brand-active-text: var(--vp-c-text-dark-1);
6153
--vp-button-brand-active-bg: var(--vp-button-brand-bg);
62-
--vp-code-tab-active-text-color: var(--vp-c-brand);
63-
--vp-code-tab-active-bar-color: var(--vp-c-brand-darker);
64-
--vp-code-tab-divider: var(--vp-c-brand);
6554
}
6655

6756
/**

Diff for: guide/index.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@ You can try Vitest online on [StackBlitz](https://vitest.new). It runs Vitest di
1818

1919
<CourseLink href="https://vueschool.io/lessons/how-to-install-vitest?friend=vueuse">Learn how to install by Video</CourseLink>
2020

21-
With npm
22-
```bash
23-
npm install -D vitest
24-
```
25-
or with yarn
26-
```bash
27-
yarn add -D vitest
28-
```
29-
or with pnpm
30-
```bash
31-
pnpm add -D vitest
32-
```
21+
::: code-group
22+
```bash [npm]
23+
npm install -D vitest
24+
```
25+
```bash [yarn]
26+
yarn add -D vitest
27+
```
28+
```bash [pnpm]
29+
pnpm add -D vitest
30+
```
31+
:::
3332

3433
:::tip
3534
Vitest requires Vite >=v3.0.0 and Node >=v14.18

Diff for: package.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "docs",
3+
"type": "module",
34
"private": true,
45
"scripts": {
56
"dev": "vitepress --port 3333 --open",
@@ -8,7 +9,8 @@
89
"serve": "vitepress serve",
910
"preview-https": "pnpm run build && serve .vitepress/dist",
1011
"preview-https-no-prefetch": "pnpm run build-no-prefetch && serve .vitepress/dist",
11-
"prefetch": "esno .vitepress/scripts/fetch-avatars.ts"
12+
"prefetch": "esno .vitepress/scripts/fetch-avatars.ts",
13+
"generate-pwa-icons": "pwa-assets-generator"
1214
},
1315
"dependencies": {
1416
"@vueuse/core": "^10.2.0",
@@ -18,6 +20,7 @@
1820
"devDependencies": {
1921
"@iconify-json/carbon": "^1.1.18",
2022
"@unocss/reset": "^0.53.1",
23+
"@vite-pwa/assets-generator": "^0.0.3",
2124
"@vite-pwa/vitepress": "^0.2.0",
2225
"@vitejs/plugin-vue": "latest",
2326
"esno": "^0.16.3",
@@ -30,5 +33,12 @@
3033
"vite-plugin-pwa": "^0.16.4",
3134
"vitepress": "1.0.0-beta.3",
3235
"workbox-window": "^7.0.0"
36+
},
37+
"pnpm": {
38+
"peerDependencyRules": {
39+
"ignoreMissing": [
40+
"@algolia/client-search"
41+
]
42+
}
3343
}
3444
}

Diff for: public/apple-touch-icon.png

-1.45 KB
Loading

Diff for: public/favicon.ico

-13.9 KB
Binary file not shown.

Diff for: public/maskable-icon.png

2 KB
Loading

Diff for: public/pwa-192x192.png

-1.3 KB
Loading

Diff for: public/pwa-512x512.png

-2.26 KB
Loading

Diff for: public/pwa-64x64.png

493 Bytes
Loading

Diff for: pwa-assets.config.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {
2+
defineConfig,
3+
minimalPreset as preset,
4+
} from '@vite-pwa/assets-generator/config'
5+
6+
export default defineConfig({
7+
preset: {
8+
...preset,
9+
assetName(type, size) {
10+
switch (type) {
11+
case 'transparent':
12+
return `pwa-${size.width}x${size.height}.png`
13+
case 'maskable':
14+
return 'maskable-icon.png'
15+
case 'apple':
16+
return 'apple-touch-icon.png'
17+
}
18+
},
19+
},
20+
images: ['public/logo.svg'],
21+
})

Diff for: vite.config.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ export default defineConfig({
1010
optimizeDeps: {
1111
// vitepress is aliased with replacement `join(DIST_CLIENT_PATH, '/index')`
1212
// This needs to be excluded from optimization
13-
exclude: ['vitepress'],
13+
exclude: ['@vueuse/core', 'vitepress'],
14+
},
15+
server: {
16+
hmr: {
17+
overlay: false,
18+
},
1419
},
1520
plugins: [
16-
// TODO remove cast when moved to Vite 3
1721
Components({
1822
include: [/\.vue/, /\.md/],
1923
dirs: '.vitepress/components',
@@ -32,7 +36,7 @@ export default defineConfig({
3236
scale: 1.2,
3337
}),
3438
],
35-
}) as unknown as Plugin,
39+
}),
3640
IncludesPlugin(),
3741
],
3842
})

0 commit comments

Comments
 (0)