Merge remote-tracking branch 'origin/main' into meteorlxy/mdit-types-upgrade

pull/3772/head
meteorlxy 1 year ago
commit 51324e7fe0

@ -291,3 +291,47 @@ You can deploy your Vitepress website on [Kinsta](https://kinsta.com/static-site
### Stormkit ### Stormkit
You can deploy your VitePress project to [Stormkit](https://www.stormkit.io) by following these [instructions](https://stormkit.io/blog/how-to-deploy-vitepress). You can deploy your VitePress project to [Stormkit](https://www.stormkit.io) by following these [instructions](https://stormkit.io/blog/how-to-deploy-vitepress).
### Nginx
Here is a example of an Nginx server block configuration. This setup includes gzip compression for common text-based assets, rules for serving your VitePress site's static files with proper caching headers as well as handling `cleanUrls: true`.
```nginx
server {
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
listen 80;
server_name _;
index index.html;
location / {
# content location
root /app;
# exact matches -> reverse clean urls -> folders -> not found
try_files $uri $uri.html $uri/ =404;
# non existent pages
error_page 404 /404.html;
# a folder without index.html raises 403 in this setup
error_page 403 /404.html;
# adjust caching headers
# files in the assets folder have hashes filenames
location ~* ^/assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}
}
```
This configuration assumes that your built VitePress site is located in the `/app` directory on your server. Adjust the `root` directive accordingly if your site's files are located elsewhere.
::: warning Do not default to index.html
The try_files resolution must not default to index.html like in other Vue applications. This would result in an invalid page state.
:::
Further information can be found in the [official nginx documentation](https://nginx.org/en/docs/), in these issues [#2837](https://github.com/vuejs/vitepress/discussions/2837), [#3235](https://github.com/vuejs/vitepress/issues/3235) as well as in this [blog post](https://blog.mehdi.cc/articles/vitepress-cleanurls-on-nginx-environment#readings) by Mehdi Merah.

@ -3,11 +3,11 @@
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vitepress dev",
"build": "vitepress build", "build": "vitepress build",
"preview": "vitepress preview", "dev": "vitepress dev",
"lunaria:build": "lunaria build", "lunaria:build": "lunaria build",
"lunaria:open": "open-cli .vitepress/dist/_translations/index.html" "lunaria:open": "open-cli .vitepress/dist/_translations/index.html",
"preview": "vitepress preview"
}, },
"devDependencies": { "devDependencies": {
"@lunariajs/core": "^0.0.32", "@lunariajs/core": "^0.0.32",

@ -2,9 +2,9 @@
可以通过命令行输入 `vitepress build --mpa` 或在配置文件中指定 `mpa: true` 配置选项来启用 MPA (Multi-Page Application) 模式。 可以通过命令行输入 `vitepress build --mpa` 或在配置文件中指定 `mpa: true` 配置选项来启用 MPA (Multi-Page Application) 模式。
在 MPA 模式下,所有页面都会默认不包含任何 JavaScript。因此站点可能评估工具中获得更好的初始访问性能分数。 在 MPA 模式下,所有页面都默认不会包含任何 JavaScript。因此站点也许可以在评估工具中获得更好的初始访问性能分数。
但是,由于 SPA 导航的缺失跨页面链接将导致重新加载整个页面。MPA 模式下的导航不会像 SPA 模式那样立即响应。 但是,由于缺少 SPA 路由,在 MPA 模式下切换页面时会重新加载整个页面,而不会像 SPA 模式那样立即响应。
同时请注意,默认情况下不使用 JavaScript 意味着你实际上只是将 Vue 作为服务器端模板语言。浏览器不会附加任何事件处理程序,因此将不会有任何交互性。要加载客户端 JavaScript需要使用特殊的 `<script client>` 标签: 同时请注意,默认情况下不使用 JavaScript 意味着你实际上只是将 Vue 作为服务器端模板语言。浏览器不会附加任何事件处理程序,因此将不会有任何交互性。要加载客户端 JavaScript需要使用特殊的 `<script client>` 标签:
@ -20,4 +20,4 @@ document.querySelector('h1').addEventListener('click', () => {
`<script client>` 是 VitePress 独有的功能,而不是 Vue 的功能。它可以在 `.md``.vue` 文件中使用,但只能在 MPA 模式下使用。所有主题组件中的客户端脚本将被打包在一起,而特定页面的客户端脚本将会分开处理。 `<script client>` 是 VitePress 独有的功能,而不是 Vue 的功能。它可以在 `.md``.vue` 文件中使用,但只能在 MPA 模式下使用。所有主题组件中的客户端脚本将被打包在一起,而特定页面的客户端脚本将会分开处理。
请注意,`<script client>` **不会被视为 Vue 组件代码**:它将是普通的 JavaScript 模块。因此,只有在站点需要绝对最小的客户端交互性时,才应该使用 MPA 模式。 请注意,`<script client>` **不会被视为 Vue 组件代码**,它只是普通的 JavaScript 模块。因此,只有在站点需要极少的客户端交互时,才应该使用 MPA 模式。

@ -2,10 +2,22 @@
"name": "vitepress", "name": "vitepress",
"version": "1.1.0", "version": "1.1.0",
"description": "Vite & Vue powered static site generator", "description": "Vite & Vue powered static site generator",
"keywords": [
"vite",
"vue",
"vitepress"
],
"homepage": "https://github.com/vuejs/vitepress/tree/main/#readme",
"bugs": {
"url": "https://github.com/vuejs/vitepress/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vuejs/vitepress.git"
},
"license": "MIT",
"author": "Evan You",
"type": "module", "type": "module",
"packageManager": "pnpm@8.15.6",
"main": "dist/node/index.js",
"types": "types/index.d.ts",
"exports": { "exports": {
".": { ".": {
"types": "./types/index.d.ts", "types": "./types/index.d.ts",
@ -29,6 +41,8 @@
"default": "./lib/vue-demi.mjs" "default": "./lib/vue-demi.mjs"
} }
}, },
"main": "dist/node/index.js",
"types": "types/index.d.ts",
"bin": { "bin": {
"vitepress": "bin/vitepress.js" "vitepress": "bin/vitepress.js"
}, },
@ -42,21 +56,6 @@
"theme-without-fonts.d.ts", "theme-without-fonts.d.ts",
"lib" "lib"
], ],
"repository": {
"type": "git",
"url": "git+https://github.com/vuejs/vitepress.git"
},
"keywords": [
"vite",
"vue",
"vitepress"
],
"author": "Evan You",
"license": "MIT",
"homepage": "https://github.com/vuejs/vitepress/tree/main/#readme",
"bugs": {
"url": "https://github.com/vuejs/vitepress/issues"
},
"scripts": { "scripts": {
"dev": "rimraf dist && run-s dev:shared dev:start", "dev": "rimraf dist && run-s dev:shared dev:start",
"dev:start": "run-p dev:client dev:node dev:watch", "dev:start": "run-p dev:client dev:node dev:watch",
@ -95,6 +94,13 @@
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"release": "node scripts/release.js" "release": "node scripts/release.js"
}, },
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "prettier --write --ignore-unknown",
"package.json": "sort-package-json"
},
"dependencies": { "dependencies": {
"@docsearch/css": "^3.6.0", "@docsearch/css": "^3.6.0",
"@docsearch/js": "^3.6.0", "@docsearch/js": "^3.6.0",
@ -112,18 +118,6 @@
"vite": "^5.2.8", "vite": "^5.2.8",
"vue": "^3.4.21" "vue": "^3.4.21"
}, },
"peerDependencies": {
"markdown-it-mathjax3": "^4",
"postcss": "^8"
},
"peerDependenciesMeta": {
"markdown-it-mathjax3": {
"optional": true
},
"postcss": {
"optional": true
}
},
"devDependencies": { "devDependencies": {
"@clack/prompts": "^0.7.0", "@clack/prompts": "^0.7.0",
"@mdit-vue/plugin-component": "2.1.0", "@mdit-vue/plugin-component": "2.1.0",
@ -197,24 +191,27 @@
"simple-git-hooks": "^2.11.1", "simple-git-hooks": "^2.11.1",
"sirv": "^2.0.4", "sirv": "^2.0.4",
"sitemap": "^7.1.1", "sitemap": "^7.1.1",
"sort-package-json": "^2.10.0",
"supports-color": "^9.4.0", "supports-color": "^9.4.0",
"typescript": "^5.4.4", "typescript": "^5.4.4",
"vitest": "^1.4.0", "vitest": "^1.4.0",
"vue-tsc": "^2.0.11", "vue-tsc": "^2.0.11",
"wait-on": "^7.2.0" "wait-on": "^7.2.0"
}, },
"simple-git-hooks": { "peerDependencies": {
"pre-commit": "pnpm lint-staged" "markdown-it-mathjax3": "^4",
"postcss": "^8"
}, },
"lint-staged": { "peerDependenciesMeta": {
"*": [ "markdown-it-mathjax3": {
"prettier --write --ignore-unknown" "optional": true
]
}, },
"pnpm": { "postcss": {
"overrides": { "optional": true
"ora>string-width": "^5" }
}, },
"packageManager": "pnpm@8.15.6",
"pnpm": {
"peerDependencyRules": { "peerDependencyRules": {
"ignoreMissing": [ "ignoreMissing": [
"@algolia/client-search", "@algolia/client-search",
@ -222,6 +219,9 @@
"postcss" "postcss"
] ]
}, },
"overrides": {
"ora>string-width": "^5"
},
"patchedDependencies": { "patchedDependencies": {
"@types/markdown-it@14.0.0": "patches/@types__markdown-it@14.0.0.patch" "@types/markdown-it@14.0.0": "patches/@types__markdown-it@14.0.0.patch"
} }

@ -278,6 +278,9 @@ importers:
sitemap: sitemap:
specifier: ^7.1.1 specifier: ^7.1.1
version: 7.1.1 version: 7.1.1
sort-package-json:
specifier: ^2.10.0
version: 2.10.0
supports-color: supports-color:
specifier: ^9.4.0 specifier: ^9.4.0
version: 9.4.0 version: 9.4.0
@ -2221,11 +2224,28 @@ packages:
engines: {node: '>=0.4.0'} engines: {node: '>=0.4.0'}
dev: true dev: true
/detect-indent@7.0.1:
resolution: {integrity: sha512-Mc7QhQ8s+cLrnUfU/Ji94vG/r8M26m8f++vyres4ZoojaRDpZ1eSIh/EpzLNwlWuvzSZ3UbDFspjFvTDXe6e/g==}
engines: {node: '>=12.20'}
dev: true
/detect-newline@4.0.1:
resolution: {integrity: sha512-qE3Veg1YXzGHQhlA6jzebZN2qVf6NX+A7m7qlhCGG30dJixrAQhYOsJjsnBjJkCSmuOPpCk30145fr8FV0bzog==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dev: true
/diff-sequences@29.6.3: /diff-sequences@29.6.3:
resolution: {integrity: sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==} resolution: {integrity: sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dev: true dev: true
/dir-glob@3.0.1:
resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==}
engines: {node: '>=8'}
dependencies:
path-type: 4.0.0
dev: true
/dom-serializer@1.4.1: /dom-serializer@1.4.1:
resolution: {integrity: sha512-VHwB3KfrcOOkelEG2ZOfxqLZdfkil8PtJi4P8N2MMXucZq2yLp75ClViUlOVwyoHEDjYU433Aq+5zWP61+RGag==} resolution: {integrity: sha512-VHwB3KfrcOOkelEG2ZOfxqLZdfkil8PtJi4P8N2MMXucZq2yLp75ClViUlOVwyoHEDjYU433Aq+5zWP61+RGag==}
dependencies: dependencies:
@ -2655,6 +2675,10 @@ packages:
resolve-pkg-maps: 1.0.0 resolve-pkg-maps: 1.0.0
dev: true dev: true
/git-hooks-list@3.1.0:
resolution: {integrity: sha512-LF8VeHeR7v+wAbXqfgRlTSX/1BJR9Q1vEMR8JAz1cEg6GX07+zyj3sAdDvYjj/xnlIfVuGgj4qBei1K3hKH+PA==}
dev: true
/git-raw-commits@4.0.0: /git-raw-commits@4.0.0:
resolution: {integrity: sha512-ICsMM1Wk8xSGMowkOmPrzo2Fgmfo4bMHLNX6ytHjajRJUqvHOw/TFapQ+QG75c3X/tTDDhOSRPGC52dDbNM8FQ==} resolution: {integrity: sha512-ICsMM1Wk8xSGMowkOmPrzo2Fgmfo4bMHLNX6ytHjajRJUqvHOw/TFapQ+QG75c3X/tTDDhOSRPGC52dDbNM8FQ==}
engines: {node: '>=16'} engines: {node: '>=16'}
@ -2711,6 +2735,17 @@ packages:
define-properties: 1.2.1 define-properties: 1.2.1
dev: true dev: true
/globby@13.2.2:
resolution: {integrity: sha512-Y1zNGV+pzQdh7H39l9zgB4PJqjRNqydvdYCDG4HFXM4XuvSaQQlEc91IU1yALL8gUTDomgBAfz3XJdmUS+oo0w==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dependencies:
dir-glob: 3.0.1
fast-glob: 3.3.2
ignore: 5.3.1
merge2: 1.4.1
slash: 4.0.0
dev: true
/gopd@1.0.1: /gopd@1.0.1:
resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==}
dependencies: dependencies:
@ -2830,6 +2865,11 @@ packages:
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
dev: true dev: true
/ignore@5.3.1:
resolution: {integrity: sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==}
engines: {node: '>= 4'}
dev: true
/inflight@1.0.6: /inflight@1.0.6:
resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==}
dependencies: dependencies:
@ -2994,6 +3034,11 @@ packages:
engines: {node: '>=8'} engines: {node: '>=8'}
dev: true dev: true
/is-plain-obj@4.1.0:
resolution: {integrity: sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==}
engines: {node: '>=12'}
dev: true
/is-reference@1.2.1: /is-reference@1.2.1:
resolution: {integrity: sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==} resolution: {integrity: sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==}
dependencies: dependencies:
@ -3763,6 +3808,11 @@ packages:
pify: 3.0.0 pify: 3.0.0
dev: true dev: true
/path-type@4.0.0:
resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==}
engines: {node: '>=8'}
dev: true
/pathe@1.1.2: /pathe@1.1.2:
resolution: {integrity: sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==} resolution: {integrity: sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==}
dev: true dev: true
@ -4281,6 +4331,24 @@ packages:
resolution: {integrity: sha512-4qdtOGcBjral6YIBCWJ0ljFSKNLz9KkhbWtuGvUyRowl1kxfuE1x/Z/aJcaiilpb3do9bl5K7/1h9XC5wWpY/A==} resolution: {integrity: sha512-4qdtOGcBjral6YIBCWJ0ljFSKNLz9KkhbWtuGvUyRowl1kxfuE1x/Z/aJcaiilpb3do9bl5K7/1h9XC5wWpY/A==}
dev: true dev: true
/sort-object-keys@1.1.3:
resolution: {integrity: sha512-855pvK+VkU7PaKYPc+Jjnmt4EzejQHyhhF33q31qG8x7maDzkeFhAAThdCYay11CISO+qAMwjOBP+fPZe0IPyg==}
dev: true
/sort-package-json@2.10.0:
resolution: {integrity: sha512-MYecfvObMwJjjJskhxYfuOADkXp1ZMMnCFC8yhp+9HDsk7HhR336hd7eiBs96lTXfiqmUNI+WQCeCMRBhl251g==}
hasBin: true
dependencies:
detect-indent: 7.0.1
detect-newline: 4.0.1
get-stdin: 9.0.0
git-hooks-list: 3.1.0
globby: 13.2.2
is-plain-obj: 4.1.0
semver: 7.6.0
sort-object-keys: 1.1.3
dev: true
/source-map-js@1.2.0: /source-map-js@1.2.0:
resolution: {integrity: sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==} resolution: {integrity: sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}

@ -68,8 +68,8 @@ export function createRouter(
if ((await router.onBeforeRouteChange?.(href)) === false) return if ((await router.onBeforeRouteChange?.(href)) === false) return
if (inBrowser && href !== normalizeHref(location.href)) { if (inBrowser && href !== normalizeHref(location.href)) {
// save scroll position before changing url // save scroll position before changing url
history.replaceState({ scrollPosition: window.scrollY }, document.title) history.replaceState({ scrollPosition: window.scrollY }, '')
history.pushState(null, '', href) history.pushState({}, '', href)
} }
await loadPage(href) await loadPage(href)
await router.onAfterRouteChanged?.(href) await router.onAfterRouteChanged?.(href)
@ -111,7 +111,7 @@ export function createRouter(
if (actualPathname !== targetLoc.pathname) { if (actualPathname !== targetLoc.pathname) {
targetLoc.pathname = actualPathname targetLoc.pathname = actualPathname
href = actualPathname + targetLoc.search + targetLoc.hash href = actualPathname + targetLoc.search + targetLoc.hash
history.replaceState(null, '', href) history.replaceState({}, '', href)
} }
if (targetLoc.hash && !scrollPosition) { if (targetLoc.hash && !scrollPosition) {
@ -162,6 +162,9 @@ export function createRouter(
} }
if (inBrowser) { if (inBrowser) {
if (history.state === null) {
history.replaceState({}, '')
}
window.addEventListener( window.addEventListener(
'click', 'click',
(e) => { (e) => {
@ -203,7 +206,7 @@ export function createRouter(
// scroll between hash anchors in the same page // scroll between hash anchors in the same page
// avoid duplicate history entries when the hash is same // avoid duplicate history entries when the hash is same
if (hash !== currentUrl.hash) { if (hash !== currentUrl.hash) {
history.pushState(null, '', href) history.pushState({}, '', href)
// still emit the event so we can listen to it in themes // still emit the event so we can listen to it in themes
window.dispatchEvent( window.dispatchEvent(
new HashChangeEvent('hashchange', { new HashChangeEvent('hashchange', {
@ -228,6 +231,9 @@ export function createRouter(
) )
window.addEventListener('popstate', async (e) => { window.addEventListener('popstate', async (e) => {
if (e.state === null) {
return
}
await loadPage( await loadPage(
normalizeHref(location.href), normalizeHref(location.href),
(e.state && e.state.scrollPosition) || 0 (e.state && e.state.scrollPosition) || 0

Loading…
Cancel
Save