From dbb077b69649e43bcfb1cf1c101431e82d62050d Mon Sep 17 00:00:00 2001 From: chufan Date: Mon, 21 Sep 2026 14:36:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(vuepress):=20=E7=B2=BE=E7=AE=80=E7=AB=99?= =?UTF-8?q?=E7=82=B9=E9=85=8D=E7=BD=AE=E5=B9=B6=E4=BF=AE=E5=A4=8D=E5=A4=9A?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=20head=20=E8=84=9A=E6=9C=AC=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 提取 siteHead,Vercel 统计仅在 VERCEL=1 时注入,避免自定义域名与 Docker 部署 404 - 启用 appBuildLog 输出构建版本与时间 - 移除与 @142vip/vuepress 默认重复的主题项,补充 NEED_PROXY 说明 --- vuepress.config.ts | 59 ++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/vuepress.config.ts b/vuepress.config.ts index 8039f75..691813a 100644 --- a/vuepress.config.ts +++ b/vuepress.config.ts @@ -1,15 +1,40 @@ +import type { UserConfig } from '@vuepress/cli' import { OPEN_SOURCE_ADDRESS, OPEN_SOURCE_AUTHOR } from '@142vip/open-source' -import { GitGeneralBranch, vipDocSite, VipPackageJSON } from '@142vip/utils' +import { vipDocSite, VipNodeJS, VipPackageJSON } from '@142vip/utils' import { defineVipVuepressConfig, getVipHopeTheme, handleImportCodePath, - VUEPRESS_DEFAULT_DOCS_DIR, } from '@142vip/vuepress' import { navbarConfig, sidebarConfig } from './docs/theme.config' const pkg = VipPackageJSON.getPackageJSON<{ description: string }>() +/** + * 站点 head 配置 + * - Vercel 统计:仅 Vercel 构建注入(`/_vercel/insights/script.js` 仅该平台托管时存在) + * - 百度统计 + */ +const siteHead: NonNullable = [ + ['link', { rel: 'icon', href: 'favicon.ico' }], + [ + 'script', + {}, + `var _hmt = _hmt || []; + (function() { + var hm = document.createElement("script"); + hm.src = "https://hm.baidu.com/hm.js?3515cc46ae60747b778140f0e5e22dfe"; + var s = document.getElementsByTagName("script")[0]; + s.parentNode.insertBefore(hm, s); + })();`, + ], +] + +// vercel 统计 +if (VipNodeJS.getProcessEnv('VERCEL') === '1') { + siteHead.push(['script', { type: 'text/javascript', src: '/_vercel/insights/script.js' }]) +} + /** * 页脚 */ @@ -71,7 +96,8 @@ const copyrightHtmlStr = ` /** * 用户自定义配置 * 注意: - * - 环境变量中的PROXY_DOMAIN字段,用于区分是否nginx代理 + * - 环境变量 NEED_PROXY=true 时,base 为 /{pkg.name}/,否则为 / + * - locales / lang / bundler / favicon 等由 defineVipVuepressConfig 默认注入 */ export default defineVipVuepressConfig({ base: vipDocSite.getBase(pkg.name), @@ -79,23 +105,7 @@ export default defineVipVuepressConfig({ description: '磨刀不误砍柴工,读完硕士再打工', port: 4200, source: '', - head: [ - ['link', { rel: 'icon', href: 'favicon.ico' }], - // vercel统计 相关配置 - ['script', { type: 'text/javascript', src: '/_vercel/insights/script.js' }], - // 百度统计 - [ - 'script', - {}, - `var _hmt = _hmt || []; - (function() { - var hm = document.createElement("script"); - hm.src = "https://hm.baidu.com/hm.js?3515cc46ae60747b778140f0e5e22dfe"; - var s = document.getElementsByTagName("script")[0]; - s.parentNode.insertBefore(hm, s); - })();`, - ], - ], + head: siteHead, markdown: { importCode: { handleImportPath: handleImportCodePath([ @@ -128,16 +138,10 @@ export default defineVipVuepressConfig({ copyright: copyrightHtmlStr, // 仓库 142vip/408CSFamily repo: `${OPEN_SOURCE_ADDRESS.GITHUB_ORGANIZATION_NAME}/${pkg.name}`, - // 作者信息 author: OPEN_SOURCE_AUTHOR, - - // 文档路径,开启编辑功能 - docsDir: VUEPRESS_DEFAULT_DOCS_DIR, - docsBranch: GitGeneralBranch.NEXT, // 主题布局选项 docsRepo: OPEN_SOURCE_ADDRESS.GITHUB_REPO_408, - contributors: true, // 插件 plugins: { @@ -150,4 +154,7 @@ export default defineVipVuepressConfig({ }, }, }), +}, { + // 浏览器控制台打印版本与构建时间 + appBuildLog: { version: pkg.version }, })