From be260fda6efc1d6c4b56219d7a17a19ab7a4ba76 Mon Sep 17 00:00:00 2001 From: Dmitrii Savelev Date: Sat, 25 Oct 2025 19:54:41 +0300 Subject: [PATCH 1/4] fix(theme): use nav height css var for curtain top in sidebar (#4993) --- src/client/theme-default/components/VPSidebar.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/theme-default/components/VPSidebar.vue b/src/client/theme-default/components/VPSidebar.vue index b27d8028..e20a5a0a 100644 --- a/src/client/theme-default/components/VPSidebar.vue +++ b/src/client/theme-default/components/VPSidebar.vue @@ -119,7 +119,7 @@ watch( @media (min-width: 960px) { .curtain { position: sticky; - top: -64px; + top: calc(var(--vp-nav-height) * -1); left: 0; z-index: 1; margin-top: calc(var(--vp-nav-height) * -1); From 8da5e74948e22aff26f844e9fe797c3d1dcc87e9 Mon Sep 17 00:00:00 2001 From: WuMingDao <146366930+WuMingDao@users.noreply.github.com> Date: Wed, 12 Nov 2025 04:14:43 +0800 Subject: [PATCH 2/4] docs(zh): add comment translations in deploy.md (#5024) --- docs/zh/guide/deploy.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/zh/guide/deploy.md b/docs/zh/guide/deploy.md index 54ed13d4..dbd1b411 100644 --- a/docs/zh/guide/deploy.md +++ b/docs/zh/guide/deploy.md @@ -308,20 +308,20 @@ server { index index.html; location / { - # content location + # 内容位置 root /app; - # exact matches -> reverse clean urls -> folders -> not found + # 完全匹配 -> 反向清理 url -> 文件夹 -> 没有发现 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 + # 在此设置中,如果文件夹没有 index.html,就会引发 403 错误 error_page 403 /404.html; - # adjust caching headers - # files in the assets folder have hashes filenames + # 调整缓存标头 + # assets 文件夹中的文件都有哈希文件名 location ~* ^/assets/ { expires 1y; add_header Cache-Control "public, immutable"; From bf2715ed67f290726fc6d4c85c203ca8f74cc907 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 12 Nov 2025 12:49:44 +0800 Subject: [PATCH 3/4] feat: prevent `$` symbol selection in shell code (#5025) --- src/client/app/composables/copyCode.ts | 9 ++++--- src/node/markdown/plugins/highlight.ts | 36 ++++++++++++++++++++++++++ src/shared/shared.ts | 5 ++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/client/app/composables/copyCode.ts b/src/client/app/composables/copyCode.ts index 4d35e012..3d920a85 100644 --- a/src/client/app/composables/copyCode.ts +++ b/src/client/app/composables/copyCode.ts @@ -1,6 +1,6 @@ import { inBrowser } from 'vitepress' +import { isShell } from '../../shared' -const shellRE = /language-(shellscript|shell|bash|sh|zsh)/ const ignoredNodes = ['.vp-copy-ignore', '.diff.remove'].join(', ') export function useCopyCode() { @@ -15,8 +15,6 @@ export function useCopyCode() { return } - const isShell = shellRE.test(parent.className) - // Clone the node and remove the ignored nodes const clone = sibling.cloneNode(true) as HTMLElement clone.querySelectorAll(ignoredNodes).forEach((node) => node.remove()) @@ -26,7 +24,10 @@ export function useCopyCode() { let text = clone.textContent || '' - if (isShell) { + // NOTE: Any changes to this the code here may also need to update + // `transformerDisableShellSymbolSelect` in `src/node/markdown/plugins/highlight.ts` + const lang = /language-(\w+)/.exec(parent.className)?.[1] || '' + if (isShell(lang)) { text = text.replace(/^ *(\$|>) /gm, '').trim() } diff --git a/src/node/markdown/plugins/highlight.ts b/src/node/markdown/plugins/highlight.ts index 8f427823..5862aff1 100644 --- a/src/node/markdown/plugins/highlight.ts +++ b/src/node/markdown/plugins/highlight.ts @@ -11,6 +11,7 @@ import c from 'picocolors' import type { BundledLanguage, ShikiTransformer } from 'shiki' import { createHighlighter, guessEmbeddedLanguages, isSpecialLang } from 'shiki' import type { Logger } from 'vite' +import { isShell } from '../../shared' import type { MarkdownOptions, ThemeOptions } from '../markdown' const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10) @@ -47,6 +48,40 @@ function attrsToLines(attrs: string): TransformerCompactLineOption[] { })) } +/** + * Prevents the leading '$' symbol etc from being selectable/copyable. Also + * normalizes its syntax so there's no leading spaces, and only a single + * trailing space. + * + * NOTE: Any changes to this function may also need to update + * `src/client/app/composables/copyCode.ts` + */ +function transformerDisableShellSymbolSelect(): ShikiTransformer { + return { + name: 'vitepress:disable-shell-symbol-select', + tokens(tokensByLine) { + if (!isShell(this.options.lang)) return + + for (const tokens of tokensByLine) { + if (tokens.length < 2) continue + + // The first token should only be a symbol token + const firstTokenText = tokens[0].content.trim() + if (firstTokenText !== '$' && firstTokenText !== '>') continue + + // The second token must have a leading space (separates the symbol) + if (tokens[1].content[0] !== ' ') continue + + tokens[0].content = firstTokenText + ' ' + tokens[0].htmlStyle ??= {} + tokens[0].htmlStyle['user-select'] = 'none' + tokens[0].htmlStyle['-webkit-user-select'] = 'none' + tokens[1].content = tokens[1].content.slice(1) + } + } + } +} + export async function highlight( theme: ThemeOptions, options: MarkdownOptions, @@ -83,6 +118,7 @@ export async function highlight( }), transformerNotationHighlight(), transformerNotationErrorLevel(), + transformerDisableShellSymbolSelect(), { name: 'vitepress:add-dir', pre(node) { diff --git a/src/shared/shared.ts b/src/shared/shared.ts index c556e723..f16a25ba 100644 --- a/src/shared/shared.ts +++ b/src/shared/shared.ts @@ -353,3 +353,8 @@ type ObjectType = Record export function isObject(value: unknown): value is ObjectType { return Object.prototype.toString.call(value) === '[object Object]' } + +const shellLangs = ['shellscript', 'shell', 'bash', 'sh', 'zsh'] +export function isShell(lang: string): boolean { + return shellLangs.includes(lang) +} From eddf0ca257167c5e06603e55702783fe1b25108d Mon Sep 17 00:00:00 2001 From: WuMingDao <146366930+WuMingDao@users.noreply.github.com> Date: Wed, 12 Nov 2025 17:59:08 +0800 Subject: [PATCH 4/4] docs(zh): add comment translations in extending-default-theme.md (#5026) --- docs/zh/guide/extending-default-theme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/zh/guide/extending-default-theme.md b/docs/zh/guide/extending-default-theme.md index a23cebd1..6218247d 100644 --- a/docs/zh/guide/extending-default-theme.md +++ b/docs/zh/guide/extending-default-theme.md @@ -55,8 +55,8 @@ export default DefaultTheme ```css /* .vitepress/theme/my-fonts.css */ :root { - --vp-font-family-base: /* normal text font */ - --vp-font-family-mono: /* code font */ + --vp-font-family-base: /* 普通文本字体 */ + --vp-font-family-mono: /* 代码字体 */ } ```