Skip to content

Commit 4e9cc64

Browse files
authored
Merge pull request #9 from hyt1004/main
文档搜索优化、页面优化
2 parents ddd2e91 + 0f61539 commit 4e9cc64

26 files changed

+209
-141
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 安装
44

5-
``` shell
5+
```shell
66
npm install
77
```
88

@@ -11,16 +11,17 @@ npm install
1111
```shell
1212
npm run docs:dev
1313
```
14-
浏览器打开 http://localhost:5173
14+
15+
浏览器打开 <http://localhost:5173>
1516

1617
## 部署
1718

1819
```shell
1920
npm run docs:build
2021
```
2122

22-
本地预览,执行下列命令后,生成一个本地静态 Web 服务 http://localhost:4173,该服务以 .vitepress/dist 作为源文件
23+
本地预览,执行下列命令后,生成一个本地静态 Web 服务 <http://localhost:4173>,该服务以 .vitepress/dist 作为源文件
24+
2325
```shell
2426
npm run docs:preview
2527
```
26-

docs/.vitepress/config.mts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,12 @@ const sidebarItems = getChapterItems(1, 2);
77

88
// https://vitepress.dev/reference/site-config
99
export default defineConfig({
10+
lang: "zh",
1011
title: "灵矽文档中心",
1112
description: "A 灵矽 Documentation Project",
1213
lastUpdated: true,
1314
cleanUrls: true,
1415
base: "/Xrobot-docs/",
15-
locales: {
16-
root: {
17-
label: "简体中文",
18-
lang: "cn",
19-
},
20-
// en: {
21-
// label: "English",
22-
// lang: "en",
23-
// },
24-
},
2516
themeConfig: {
2617
// https://vitepress.dev/reference/default-theme-config
2718
outline: [2, 4],
@@ -41,8 +32,8 @@ export default defineConfig({
4132
},
4233
],
4334
search: {
44-
provider: "local",
45-
},
35+
provider: 'local',
36+
}
4637
},
4738
markdown: {
4839
toc: {

docs/.vitepress/theme/components/ChapterContents.vue

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
<script setup lang="ts">
22
import { useData } from "vitepress";
33
import {
4+
ChapterItem,
45
ChapterItems,
56
Chapters,
67
isChapter,
78
} from "../../../.vitepress/theme/constrants/route";
8-
9-
function apply_prefix(link: string, prefix: string) {
10-
if (!prefix) return link;
11-
if (link.startsWith("/") && prefix.endsWith("/")) {
12-
return prefix.slice(0, -1) + link;
13-
} else if (!link.startsWith("/") && !prefix.endsWith("/")) {
14-
return prefix + "/" + link;
15-
}
16-
return prefix + link;
17-
}
9+
import { apply_prefix } from "../utils";
1810
1911
const { chapter: chapter_root, root = true } = defineProps<{
2012
// 参数chapter应该是如 Chapter.xrobot_device这样的
@@ -28,12 +20,13 @@ const base = site.value.base;
2820
2921
// console.log("contents");
3022
let chapter_name: string[] = [];
31-
let tocs: { link: string; text: string }[][] = [];
23+
let tocs: ChapterItem[][] = [];
3224
3325
// console.log("chapter_root", chapter_root);
3426
// console.log("ChapterItems[chapter_root]", ChapterItems[chapter_root]);
3527
36-
const items = ChapterItems[chapter_root];
28+
const items: ChapterItem[] = ChapterItems[chapter_root];
29+
3730
if (!items) {
3831
const { page } = useData();
3932
console.warn(
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!-- .vitepress/theme/components/SearchBox.vue -->
2+
<template>
3+
<div class="custom-search">
4+
<button
5+
ref="searchButton"
6+
class="search-button"
7+
@click="openSearch"
8+
aria-label="搜索文档"
9+
>
10+
<svg
11+
xmlns="http://www.w3.org/2000/svg"
12+
viewBox="0 0 24 24"
13+
fill="none"
14+
stroke="currentColor"
15+
stroke-width="2"
16+
>
17+
<circle cx="11" cy="11" r="8"></circle>
18+
<path d="M21 21l-4.35-4.35"></path>
19+
</svg>
20+
<span class="DocSearch-Button-Placeholder">搜索文档...</span>
21+
</button>
22+
</div>
23+
</template>
24+
25+
<script setup>
26+
const openSearch = async () => {
27+
const ele = document.getElementById("local-search").querySelector("button");
28+
console.log("search", ele);
29+
ele.click();
30+
};
31+
</script>
32+
33+
<style scoped>
34+
.custom-search {
35+
max-width: 580px;
36+
width: 100%;
37+
margin: 0 auto 32px;
38+
padding: 0 24px;
39+
}
40+
41+
.search-button {
42+
display: flex;
43+
align-items: center;
44+
width: 100%;
45+
padding: 10px 16px;
46+
background: var(--vp-c-bg-alt);
47+
border: 1px solid var(--vp-c-divider);
48+
border-radius: 8px;
49+
cursor: pointer;
50+
transition: all 0.25s ease;
51+
box-shadow: var(--vp-shadow-1);
52+
text-align: left;
53+
}
54+
55+
.search-button:hover {
56+
background: var(--vp-c-bg-soft);
57+
border-color: var(--vp-c-brand);
58+
box-shadow: var(--vp-shadow-2);
59+
}
60+
61+
.search-button:active {
62+
transform: translateY(1px);
63+
}
64+
65+
.search-button svg {
66+
width: 18px;
67+
height: 18px;
68+
margin-right: 12px;
69+
color: var(--vp-c-text-2);
70+
transition: color 0.25s ease;
71+
}
72+
73+
.search-button:hover svg {
74+
color: var(--vp-c-brand);
75+
}
76+
77+
.search-button span {
78+
font-size: 15px;
79+
color: var(--vp-c-text-2);
80+
transition: color 0.25s ease;
81+
}
82+
83+
.search-button:hover span {
84+
color: var(--vp-c-text-1);
85+
}
86+
87+
/* 在首页的特殊样式 */
88+
.VPHero.has-image .custom-search {
89+
margin-top: 24px;
90+
margin-bottom: 48px;
91+
}
92+
93+
/* 响应式调整 */
94+
@media (max-width: 768px) {
95+
.custom-search {
96+
padding: 0 16px;
97+
margin-bottom: 24px;
98+
}
99+
100+
.search-button {
101+
padding: 8px 14px;
102+
}
103+
104+
.search-button span {
105+
font-size: 14px;
106+
}
107+
}
108+
</style>

docs/.vitepress/theme/index.css

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@
1818
/* border: 1px solid #e5e7eb; */
1919
}
2020

21-
div[class="VPContent is-home"] {
22-
/* todo 移除测试背景-该背景被应用到整个页面 */
21+
/* 居中 */
22+
.name.clip,
23+
.VPHomeFeatures .VPImage,
24+
.VPHomeFeatures .link-text {
25+
margin: auto;
26+
}
27+
28+
/* todo 移除测试背景-该背景被应用到整个页面 */
29+
/* div[class="VPContent is-home"] {
2330
background: linear-gradient(to bottom right, #dce8ff, #e4eeff, #e6cbfd);
2431
}
2532
2633
html.dark div[class="VPContent is-home"] {
2734
background: none;
28-
}
35+
} */

docs/.vitepress/theme/layout.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup>
22
import DefaultTheme from "vitepress/theme";
3+
import SearchBox from "./components/SearchBox.vue";
34
45
const { Layout } = DefaultTheme;
56
</script>
@@ -8,5 +9,8 @@ const { Layout } = DefaultTheme;
89
<Layout>
910
<!-- <template #not-found> 404 not-found </template> -->
1011
<!-- <template #home-hero-image> </template> -->
12+
<template #home-hero-after>
13+
<SearchBox></SearchBox>
14+
</template>
1115
</Layout>
1216
</template>

docs/index.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,47 @@ hero:
66
name: "灵矽文档中心"
77
# text: "Xrobot Docs"
88
# tagline: ddddddddddddddddddddddddd
9-
actions:
10-
- theme: brand
11-
text: 开发文档
12-
link: /xrobot/
13-
- theme: brand
14-
text: 常见问题
15-
link: /xrobot/faq/
16-
- theme: alt
17-
text: 去体验-灵矽
18-
link: https://xrobo.qiniu.com/#/home
199
features:
2010
- linkText: 设备接入协议
2111
icon:
22-
src: /icons/protocol.png
12+
light: /icons/light/protocol.svg
13+
dark: /icons/dark/protocol.svg
2314
width: 100
2415
height: 100
2516
link: ./xrobot/platform
2617
- linkText: 平台API
2718
icon:
28-
src: /icons/API.png
19+
light: /icons/light/API.svg
20+
dark: /icons/dark/API.svg
2921
width: 100
3022
height: 100
3123
link: ./xrobot/api
3224
- linkText: MCP接入
3325
icon:
34-
src: /icons/mcp.png
26+
light: /icons/light/mcp.svg
27+
dark: /icons/dark/mcp.svg
3528
width: 100
3629
height: 100
3730
link: ./xrobot/mcp
3831
- linkText: 最佳实践
3932
icon:
40-
src: /icons/best-practice.png
33+
light: /icons/light/best-practice.svg
34+
dark: /icons/dark/best-practice.svg
4135
width: 100
4236
height: 100
4337
link: ./xrobot/guide
4438
- linkText: FAQ
4539
icon:
46-
src: /icons/faq.png
40+
light: /icons/light/faq.svg
41+
dark: /icons/dark/faq.svg
4742
width: 100
4843
height: 100
4944
link: ./xrobot/faq
45+
- linkText: 去体验
46+
icon:
47+
light: /icons/light/experience.svg
48+
dark: /icons/dark/experience.svg
49+
width: 100
50+
height: 100
51+
link: https://xrobo.qiniu.com/#/home
5052
---

docs/public/icons/API.png

-3.75 KB
Binary file not shown.

docs/public/icons/best-practice.png

-3.49 KB
Binary file not shown.

docs/public/icons/dark/API.svg

Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)