diff --git a/docs/en/guide/markdown.md b/docs/en/guide/markdown.md index 9eb4c0e7..dd577fe1 100644 --- a/docs/en/guide/markdown.md +++ b/docs/en/guide/markdown.md @@ -187,7 +187,7 @@ You may set custom title by appending the text right after the "type" of the con Danger zone, do not proceed ::: -::: details Click me to view the code +::: details Click me to toggle the code ```js console.log('Hello, VitePress!') ``` @@ -200,7 +200,7 @@ console.log('Hello, VitePress!') Danger zone, do not proceed ::: -::: details Click me to view the code +::: details Click me to toggle the code ```js console.log('Hello, VitePress!') ``` @@ -225,6 +225,28 @@ export default defineConfig({ }) ``` +### Additional Attributes + +You can add additional attributes to the custom containers. We use [markdown-it-attrs](https://github.com/arve0/markdown-it-attrs) for this feature, and it is supported on almost all markdown elements. For example, you can set the `open` attribute to make the details block open by default: + +**Input** + +````md +::: details Click me to toggle the code {open} +```js +console.log('Hello, VitePress!') +``` +::: +```` + +**Output** + +::: details Click me to toggle the code {open} +```js +console.log('Hello, VitePress!') +``` +::: + ### `raw` This is a special container that can be used to prevent style and router conflicts with VitePress. This is especially useful when you're documenting component libraries. You might also wanna check out [whyframe](https://whyframe.dev/docs/integrations/vitepress) for better isolation. diff --git a/docs/en/guide/routing.md b/docs/en/guide/routing.md index 945e63c0..55b3cd4c 100644 --- a/docs/en/guide/routing.md +++ b/docs/en/guide/routing.md @@ -156,22 +156,24 @@ You can customize the mapping between the source directory structure and the gen ``` . -├─ packages -│ ├─ pkg-a -│ │ └─ src -│ │ ├─ pkg-a-code.ts -│ │ └─ pkg-a-docs.md -│ └─ pkg-b -│ └─ src -│ ├─ pkg-b-code.ts -│ └─ pkg-b-docs.md +└─ packages + ├─ pkg-a + │ └─ src + │ ├─ foo.md + │ └─ index.md + └─ pkg-b + └─ src + ├─ bar.md + └─ index.md ``` And you want the VitePress pages to be generated like this: ``` -packages/pkg-a/src/pkg-a-docs.md --> /pkg-a/index.html -packages/pkg-b/src/pkg-b-docs.md --> /pkg-b/index.html +packages/pkg-a/src/index.md --> /pkg-a/index.html +packages/pkg-a/src/foo.md --> /pkg-a/foo.html +packages/pkg-b/src/index.md --> /pkg-b/index.html +packages/pkg-b/src/bar.md --> /pkg-b/bar.html ``` You can achieve this by configuring the [`rewrites`](../reference/site-config#rewrites) option like this: @@ -180,8 +182,10 @@ You can achieve this by configuring the [`rewrites`](../reference/site-config#re // .vitepress/config.js export default { rewrites: { - 'packages/pkg-a/src/pkg-a-docs.md': 'pkg-a/index.md', - 'packages/pkg-b/src/pkg-b-docs.md': 'pkg-b/index.md' + 'packages/pkg-a/src/index.md': 'pkg-a/index.md', + 'packages/pkg-a/src/foo.md': 'pkg-a/foo.md', + 'packages/pkg-b/src/index.md': 'pkg-b/index.md', + 'packages/pkg-b/src/bar.md': 'pkg-b/bar.md' } } ``` @@ -191,12 +195,22 @@ The `rewrites` option also supports dynamic route parameters. In the above examp ```ts export default { rewrites: { - 'packages/:pkg/src/(.*)': ':pkg/index.md' + 'packages/:pkg/src/:slug*': ':pkg/:slug*' } } ``` -The rewrite paths are compiled using the `path-to-regexp` package - consult [its documentation](https://github.com/pillarjs/path-to-regexp#parameters) for more advanced syntax. +The rewrite paths are compiled using the `path-to-regexp` package - consult [its documentation](https://github.com/pillarjs/path-to-regexp/tree/6.x#parameters) for more advanced syntax. + +`rewrites` can also be a function that receives the original path and returns the new path: + +```ts +export default { + rewrites(id) { + return id.replace(/^packages\/([^/]+)\/src\//, '$1/') + } +} +``` ::: warning Relative Links with Rewrites diff --git a/docs/public/_headers b/docs/public/_headers deleted file mode 100644 index 5d2850dd..00000000 --- a/docs/public/_headers +++ /dev/null @@ -1,6 +0,0 @@ -/assets/* - cache-control: max-age=31536000 - cache-control: immutable - -/_translations/* - x-robots-tag: noindex diff --git a/docs/public/_redirects b/docs/public/_redirects deleted file mode 100644 index 45c59465..00000000 --- a/docs/public/_redirects +++ /dev/null @@ -1 +0,0 @@ -https://vitepress.vuejs.org/* https://vitepress.dev/:splat 301! diff --git a/netlify.toml b/netlify.toml index 801b84fc..c90c283b 100644 --- a/netlify.toml +++ b/netlify.toml @@ -4,3 +4,24 @@ [build] publish = "docs/.vitepress/dist" command = "pnpm docs:build && pnpm docs:lunaria:build" + +[[headers]] + for = "/assets/*" + [headers.values] + cache-control = ''' + max-age=31536000, + immutable''' + +[[headers]] + for = "/_translations/*" + [headers.values] + x-robots-tag = "noindex" + +[[redirects]] + from = "https://vitepress.vuejs.org/*" + to = "https://vitepress.dev/:splat" + force = true + +[[redirects]] + from = "/guide/" + to = "/guide/getting-started" diff --git a/src/client/app/composables/head.ts b/src/client/app/composables/head.ts index 708c16eb..f0296b18 100644 --- a/src/client/app/composables/head.ts +++ b/src/client/app/composables/head.ts @@ -87,7 +87,7 @@ function createHeadElement([tag, attrs, innerHTML]: HeadConfig) { if (innerHTML) { el.innerHTML = innerHTML } - if (tag === 'script' && !attrs.async) { + if (tag === 'script' && attrs.async == null) { // async is true by default for dynamically created scripts ;(el as HTMLScriptElement).async = false } diff --git a/src/client/app/data.ts b/src/client/app/data.ts index 67fc0942..c99de52f 100644 --- a/src/client/app/data.ts +++ b/src/client/app/data.ts @@ -1,5 +1,5 @@ import siteData from '@siteData' -import { useDark } from '@vueuse/core' +import { useDark, usePreferredDark } from '@vueuse/core' import { computed, inject, @@ -79,13 +79,15 @@ export function initData(route: Route): VitePressData { const isDark = appearance === 'force-dark' ? ref(true) - : appearance - ? useDark({ - storageKey: APPEARANCE_KEY, - initialValue: () => (appearance === 'dark' ? 'dark' : 'auto'), - ...(typeof appearance === 'object' ? appearance : {}) - }) - : ref(false) + : appearance === 'force-auto' + ? usePreferredDark() + : appearance + ? useDark({ + storageKey: APPEARANCE_KEY, + initialValue: () => (appearance === 'dark' ? 'dark' : 'auto'), + ...(typeof appearance === 'object' ? appearance : {}) + }) + : ref(false) const hashRef = ref(inBrowser ? location.hash : '') diff --git a/src/client/theme-default/components/VPLocalSearchBox.vue b/src/client/theme-default/components/VPLocalSearchBox.vue index c8aded40..70624e42 100644 --- a/src/client/theme-default/components/VPLocalSearchBox.vue +++ b/src/client/theme-default/components/VPLocalSearchBox.vue @@ -440,10 +440,20 @@ function formMarkRegex(terms: Set) {