fix(portal): 官方文档导航直接跳文档站,不再停在本站锚点
mirror-to-gitee / mirror (push) Successful in 3s

原先导航「官方文档」指向 /#docs(首页内的文档区块),
用户期望点它直接进 http://open.5iot.com:5051/docs/。

改动
- 导航项改为外链 http://open.5iot.com:5051/docs/,
  带 target=_blank 与 rel=noopener,新开标签页不打断阅读
- 首页 hero 的「官方文档」按钮同样改为外链直跳
- 文档站地址收敛为单一来源:data/content.ts 导出 DOCS_BASE / DOCS_HOME,
  可用环境变量 DOCS_BASE 覆盖;config.mts 与 HomePage.vue 都引用它,
  消除原先三处硬编码
- 首页的「官方文档」区块(#docs)保留,仍是各手册入口的聚合卡片

验证
- 导航渲染实测:href=http://open.5iot.com:5051/docs/, target=_blank
- 点击实测:新开标签页到目标地址,原页面 URL 不变
- 锚点项高亮不受影响(点「产品功能」仍正常变蓝)
- 构建 13 页 262 引用 0 失效
This commit is contained in:
Dai0814
2026-11-04 15:36:04 +08:00
parent 39209ef591
commit 6944652966
9 changed files with 195 additions and 21 deletions
+62 -5
View File
@@ -1,5 +1,6 @@
import { defineConfig } from 'vitepress'
import { projects } from '../data/projects'
import { docs, DOCS_HOME } from '../data/content'
/**
* 门户站构建配置
@@ -19,11 +20,42 @@ const DOCS_URL: Record<string, string> = {
iotlcm: 'http://open.5iot.com:5051/docs/',
}
function tokenizeSearchText(text: string): string[] {
const terms = text.match(/[A-Za-z0-9]+|[\u3400-\u9fff]+/g) ?? []
return terms.flatMap((term) => {
if (!/^[\u3400-\u9fff]+$/.test(term)) return [term.toLowerCase()]
if (term.length === 1) return [term]
return Array.from({ length: term.length - 1 }, (_, index) => term.slice(index, index + 2))
})
}
const searchTranslations = {
button: {
buttonText: '搜索',
buttonAriaLabel: '搜索文档',
},
modal: {
displayDetails: '显示详细结果',
resetButtonTitle: '清除搜索',
backButtonTitle: '关闭搜索',
noResultsText: '没有找到相关结果',
footer: {
selectText: '选择',
selectKeyAriaLabel: '回车',
navigateText: '切换结果',
navigateUpKeyAriaLabel: '上箭头',
navigateDownKeyAriaLabel: '下箭头',
closeText: '关闭',
closeKeyAriaLabel: '退出',
},
},
}
export default defineConfig({
srcDir: './pages',
base: SITE_BASE,
title: '雪羊科技开源',
description: '雪羊科技开源项目门户:物联网卡管理、DTU 设备管理、中后台开发框架',
title: '雪羊科技物联网卡与设备管理平台',
description: '雪羊科技开源的物联网卡与设备管理平台:物联网卡管理、DTU 设备管理、中后台开发框架,Apache-2.0 许可',
lang: 'zh-CN',
cleanUrls: true,
lastUpdated: false,
@@ -31,7 +63,7 @@ export default defineConfig({
['link', { rel: 'icon', type: 'image/svg+xml', href: `${SITE_BASE}favicon.svg` }],
],
themeConfig: {
siteTitle: '雪羊科技',
siteTitle: '雪羊科技<span class="site-subtitle">物联网卡与设备管理平台</span>',
logo: { src: '/snowgoat-logo.png', alt: '雪羊科技' },
nav: [
{ text: '首页', link: '/' },
@@ -40,7 +72,13 @@ export default defineConfig({
{ text: '界面预览', link: '/#preview' },
// activeMatch:进入任一项目详情页时「项目」保持高亮
{ text: '项目', link: '/projects/', activeMatch: '^/projects/' },
{ text: '官方文档', link: '/#docs' },
// 官方文档直接跳文档站(外站),不在本站内做锚点停留
{
text: '官方文档',
link: DOCS_HOME,
target: '_blank',
rel: 'noopener',
},
{ text: '关于', link: '/about' },
],
sidebar: {
@@ -63,11 +101,30 @@ export default defineConfig({
{ icon: 'github', link: ORG_URL },
],
footer: {
message: '雪羊科技开源 · Apache-2.0',
message: '雪羊科技物联网卡与设备管理平台 · Apache-2.0',
copyright: 'Copyright © 雪羊科技',
},
search: {
provider: 'local',
options: {
translations: searchTranslations,
miniSearch: {
options: { tokenize: tokenizeSearchText },
searchOptions: { combineWith: 'AND' },
},
_render(src, env, md) {
const html = md.render(src, env)
if (env.relativePath !== 'index.md') return html
const homeSearchText = [
'雪羊科技开源 首页 项目 产品功能 核心能力 界面预览 官方文档',
...projects.map((project) => `${project.name} ${project.tagline} ${project.summary}`),
...docs.map((doc) => `${doc.name} ${doc.desc} ${doc.project}`),
].join('\n\n')
return `${html}\n${md.render(homeSearchText, env)}`
},
},
},
outline: {
level: [2, 3],