Skip to content

Commit 398344f

Browse files
authored
搜索支持API参考 (#1347)
* add api reference doc search * update api reference category name * update search content * update API reference search * docs: update API reference link url * update home page link style * fix: the url 404 when switch platform
1 parent 94cc86d commit 398344f

File tree

7 files changed

+137
-27
lines changed

7 files changed

+137
-27
lines changed

docs/.vuepress/components/CardMenu.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
width="24px"
2020
:alt="sdk.text"
2121
/>
22-
<el-link :href="sdk.link" class="link-label">{{ sdk.text }}</el-link>
22+
<a :href="sdk.link" class="link-label">{{ sdk.text }}</a>
2323
</div>
2424
</section>
2525
</div>
@@ -110,6 +110,7 @@ defineProps<{
110110
.link-label {
111111
font-family: 'SF Pro', sans-serif;
112112
margin: auto 0;
113+
text-decoration: underline;
113114
}
114115
@media (max-width: 991px) {
115116
.links-section {

docs/.vuepress/components/HomePage.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,15 @@
104104
v-if="context.link"
105105
class="feature-link"
106106
type="primary"
107+
target="_blank"
107108
:href="context.link"
108109
>
109110
{{ context.text }}
110111
</a>
111112
<ClientOnly v-else>
112113
<el-popover placement="bottom-start" :width="436">
113114
<template #reference>
114-
<a class="feature-link" type="primary">
115+
<a class="feature-link" type="primary" :href="context.sdks[0].link" target="_blank">
115116
{{ context.text }}
116117
</a>
117118
</template>

docs/.vuepress/components/Navbar.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const extraNavList = themeData.value.extra_nav || [];
2929
></path>
3030
</svg>
3131
</div>
32-
<div class="search-input">搜索关键字</div>
32+
<div class="search-input">Search</div>
3333
</div>
3434
</div>
3535

@@ -91,7 +91,7 @@ export default {
9191
font-weight: 500;
9292
color: #999; /* 字体颜色 */
9393
font-size: 14px; /* 缩小字体大小 */
94-
width: 100px; /* 缩小输入框宽度 */
94+
width: 50px; /* 缩小输入框宽度 */
9595
margin-left: 0.4em; /* 缩小间距 */
9696
cursor: pointer;
9797
}

docs/.vuepress/components/PlatformSwitch.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,16 @@ const onChange = (platform) => {
7272
let newPath = route.path.split('/')
7373
newPath[2] = platform
7474
const nextPathPath = newPath.join('/')
75-
75+
const quickstartPath = `/document/${platform}/quickstart.html`;
76+
const overviewPath = `/document/${platform}/overview.html`;
7677
if (nextPlatformDocRouters.indexOf(nextPathPath) > -1) {
77-
router.push(nextPathPath)
78+
router.push(nextPathPath);
79+
} else if (nextPlatformDocRouters.indexOf(quickstartPath) > -1) {
80+
router.push(quickstartPath);
81+
} else if (nextPlatformDocRouters.indexOf(overviewPath) > -1) {
82+
router.push(overviewPath);
7883
} else {
79-
router.push('/document/'+platform+'/overview.html')
84+
router.push(`/document/${platform}`);
8085
}
8186
}
8287

docs/.vuepress/layouts/InstanceSearchLayout.vue

Lines changed: 110 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<div class="search-container">
2323
<div class="search-box">
2424
<ais-search-box
25+
autofocus
2526
placeholder="热门搜索: 登录、消息扩展"
2627
show-loading-indicator
2728
/>
@@ -278,12 +279,95 @@
278279
</template>
279280
</ais-hits>
280281
</el-tab-pane>
282+
<el-tab-pane name="api-reference">
283+
<template #label>
284+
<ais-clear-refinements
285+
:included-attributes="includeAttributes"
286+
>
287+
<template v-slot="{ canRefine, refine, createURL }">
288+
<div
289+
:class="{
290+
'ais-tab-item': true,
291+
'ais-tab-item--active':
292+
activeCategoryType === 'api-reference'
293+
}"
294+
@click="
295+
handleClick({ name: 'api-reference', refine })
296+
"
297+
>
298+
API参考
299+
</div>
300+
</template>
301+
</ais-clear-refinements>
302+
</template>
303+
<ais-refinement-list
304+
attribute="category"
305+
:limit="100"
306+
:transform-items="filterCategories"
307+
>
308+
<template v-slot:item="{ item, refine }">
309+
<div
310+
:class="{
311+
'refinement-list-item': true,
312+
'refinement-list-item--selected': item.isRefined
313+
}"
314+
@click="refine(item.value)"
315+
>
316+
{{ categoryMap[item.label] }}
317+
</div>
318+
</template>
319+
</ais-refinement-list>
320+
<ais-hits v-loading="status === 'stalled'">
321+
<template v-slot:item="{ item }">
322+
<p>
323+
<a :href="item.url" target="_blank">
324+
<ais-highlight
325+
attribute="hierarchy.lvl0"
326+
:hit="item"
327+
/>
328+
<span v-if="item.hierarchy.lvl1"> > </span>
329+
<ais-highlight
330+
attribute="hierarchy.lvl1"
331+
:hit="item"
332+
/>
333+
<span v-if="item.hierarchy.lvl2"> > </span>
334+
<ais-highlight
335+
attribute="hierarchy.lvl2"
336+
:hit="item"
337+
/>
338+
<span v-if="item.hierarchy.lvl3"> > </span>
339+
<ais-highlight
340+
attribute="hierarchy.lvl3"
341+
:hit="item"
342+
/>
343+
<span v-if="item.hierarchy.lvl4"> > </span>
344+
<ais-highlight
345+
attribute="hierarchy.lvl4"
346+
:hit="item"
347+
/>
348+
<span v-if="item.hierarchy.lvl5"> > </span>
349+
<ais-highlight
350+
attribute="hierarchy.lvl5"
351+
:hit="item"
352+
/>
353+
</a>
354+
</p>
355+
<div class="content-snippet">
356+
<ais-snippet
357+
style="font-size: 14px"
358+
attribute="content"
359+
:hit="item"
360+
/>
361+
</div>
362+
</template>
363+
</ais-hits>
364+
</el-tab-pane>
281365
</el-tabs>
282366

283367
<div v-if="nbHits === 0">
284368
<div class="no-results">
285369
<p>
286-
抱歉,对于搜索词“**{{ query }}**”,我们没有找到任何结果。
370+
抱歉,对于搜索词“{{ query }}”,我们没有找到任何结果。
287371
</p>
288372
</div>
289373
</div>
@@ -329,26 +413,40 @@ const uikitCategoryMap = {
329413
const productCategoryMap = {
330414
产品介绍: "产品功能",
331415
内容审核: "内容审核",
332-
solution_common: "常见方案",
416+
常见方案: "常见方案",
333417
即时推送: "即时推送",
334418
"AI 集成": "AI 集成"
335419
};
336420
421+
const apiReferenceCategoryMap = {
422+
"Android API参考": "Android",
423+
"IOS API参考": "IOS",
424+
"Web API参考": "Web",
425+
"Harmony API参考": "Harmony",
426+
"Flutter API参考": "Flutter",
427+
"React Native API参考": "React Native",
428+
"Unity and Windows API参考": "Unity and Windows"
429+
};
430+
337431
const categoryMap = {
338432
...sdkCategoryMap,
339433
...uikitCategoryMap,
340-
...productCategoryMap
434+
...productCategoryMap,
435+
...apiReferenceCategoryMap
341436
};
342437
343438
const productFilters =
344-
"category:'产品介绍' OR category:'即时推送' OR category:'内容审核' OR category:'AI 集成' OR category:'solution_common1'";
439+
"category:'产品介绍' OR category:'即时推送' OR category:'内容审核' OR category:'常见方案' OR category:'AI 集成'";
345440
346441
const sdkFilters =
347442
"category:'Andorid 集成文档' OR category:'iOS 集成文档' OR category:'Web 集成文档' OR category:'HarmonyOS 集成文档' OR category:'小程序集成文档' OR category:'Flutter 集成文档' OR category:'React Native 集成文档' OR category:'Windows 集成文档' OR category:'Unity 集成文档' OR category:'REST API'";
348443
349444
const uikitFilters =
350445
"category:'UIKit-Andorid 集成文档' OR category:'UIKit-iOS 集成文档' OR category:'UIKit-Web 集成文档' OR category:'UIKit-HarmonyOS 集成文档' OR category:'UIKit-Flutter 集成文档' OR category:'UIKit-React Native 集成文档' OR category:'UIKit-uniapp'";
351446
447+
const apiReferenceFilters =
448+
"category:'Android API参考' OR category:'IOS API参考' OR category:'Web API参考' OR category:'Harmony API参考' OR category:'Flutter API参考' OR category:'React Native API参考' OR category:'Unity and Windows API参考'";
449+
352450
export default {
353451
name: "InstanceSearchLayout",
354452
components: {
@@ -360,6 +458,8 @@ export default {
360458
return productFilters;
361459
} else if (this.activeCategoryType === "uikit") {
362460
return uikitFilters;
461+
} else if (this.activeCategoryType === "api-reference") {
462+
return apiReferenceFilters;
363463
} else {
364464
return sdkFilters;
365465
}
@@ -369,6 +469,8 @@ export default {
369469
return this.productCategories;
370470
} else if (this.activeCategoryType === "uikit") {
371471
return this.uikitCategories;
472+
} else if (this.activeCategoryType === "api-reference") {
473+
return this.apiReferenceCategories;
372474
} else {
373475
return this.sdkCategories;
374476
}
@@ -397,6 +499,7 @@ export default {
397499
sdkCategories: Object.keys(sdkCategoryMap),
398500
uikitCategories: Object.keys(uikitCategoryMap),
399501
productCategories: Object.keys(productCategoryMap),
502+
apiReferenceCategories: Object.keys(apiReferenceCategoryMap),
400503
snippet: [
401504
"hierarchy.lvl1:20",
402505
"hierarchy.lvl2:20",
@@ -438,6 +541,8 @@ export default {
438541
return "sdk";
439542
} else if (this.uikitCategories.includes(categoryItem)) {
440543
return "uikit";
544+
} else if (this.apiReferenceCategories.includes(categoryItem)) {
545+
return "api-reference";
441546
} else {
442547
return "product";
443548
}
@@ -501,16 +606,14 @@ body {
501606
}
502607
503608
.search-box-container {
504-
display: flex;
505609
font-family: sans-serif;
506610
padding: 1em;
507611
max-width: 1080px;
508612
margin: 75px auto 20px;
509-
padding: 2em;
613+
padding: 1em;
510614
background: #ffffff;
511615
border-radius: 12px;
512616
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
513-
justify-content: center;
514617
}
515618
516619
.search-category {

docs/.vuepress/navbar/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ export const zhNavbar = navbar([
176176
{
177177
text: 'Android',
178178
icon: '/icon-Android.svg',
179-
link: 'https://sdkdocs.easemob.com/apidoc/android/chat3.0/annotated.html'
179+
link: 'https://doc.easemob.com/apidoc/android/chat3.0/annotated.html'
180180
},
181181
{
182182
text: 'iOS',
183183
icon: '/icon-iOS.svg',
184-
link: 'https://sdkdocs.easemob.com/apidoc/ios/chat3.0/annotated.html'
184+
link: 'https://doc.easemob.com/apidoc/ios/chat3.0/annotated.html'
185185
},
186186
{
187187
text: 'Web/小程序',
@@ -191,12 +191,12 @@ export const zhNavbar = navbar([
191191
{
192192
text: 'HarmonyOS',
193193
icon: '/icon-harmonyos.svg',
194-
link: 'https://sdkdocs.easemob.com/apidoc/harmony/chat3.0/classes/ChatClient.ChatClient.html'
194+
link: 'https://doc.easemob.com/apidoc/harmony/chat3.0/classes/ChatClient.ChatClient.html'
195195
},
196196
{
197197
text: 'Windows',
198198
icon: '/icon-windows.svg',
199-
link: 'https://sdkdocs.easemob.com/apidoc/unity/annotated.html'
199+
link: 'https://doc.easemob.com/apidoc/unity/annotated.html'
200200
}
201201
]
202202
},
@@ -206,17 +206,17 @@ export const zhNavbar = navbar([
206206
{
207207
text: 'React Native',
208208
icon: '/icon-ReactNative.svg',
209-
link: 'https://sdkdocs.easemob.com/apidoc/rn/modules.html'
209+
link: 'https://doc.easemob.com/apidoc/rn/modules.html'
210210
},
211211
{
212212
text: 'Flutter',
213213
icon: '/icon-flutter.svg',
214-
link: 'https://sdkdocs.easemob.com/apidoc/flutter/index.html'
214+
link: 'https://doc.easemob.com/apidoc/flutter/index.html'
215215
},
216216
{
217217
text: 'Unity',
218218
icon: '/icon-unity.svg',
219-
link: 'https://sdkdocs.easemob.com/apidoc/unity/annotated.html'
219+
link: 'https://doc.easemob.com/apidoc/unity/annotated.html'
220220
},
221221
{
222222
text: 'Electron',

docs/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,19 +2071,19 @@ projects:
20712071
icon: /feature/api-client.svg
20722072
contexts:
20732073
- text: Android
2074-
link: https://sdkdocs.easemob.com/apidoc/android/chat3.0/annotated.html
2074+
link: https://doc.easemob.com/apidoc/android/chat3.0/annotated.html
20752075
- text: iOS
2076-
link: https://sdkdocs.easemob.com/apidoc/ios/chat3.0/annotated.html
2076+
link: https://doc.easemob.com/apidoc/ios/chat3.0/annotated.html
20772077
- text: Web/小程序
20782078
link: https://doc.easemob.com/jsdoc/index.html
20792079
- text: HarmonyOS
2080-
link: https://sdkdocs.easemob.com/apidoc/harmony/chat3.0/classes/ChatClient.ChatClient.html
2080+
link: https://doc.easemob.com/apidoc/harmony/chat3.0/classes/ChatClient.ChatClient.html
20812081
- text: Flutter
2082-
link: https://sdkdocs.easemob.com/apidoc/flutter/index.html
2082+
link: https://doc.easemob.com/apidoc/flutter/index.html
20832083
- text: React Native
2084-
link: https://sdkdocs.easemob.com/apidoc/rn/modules.html
2084+
link: https://doc.easemob.com/apidoc/rn/modules.html
20852085
- text: Unity/Windows
2086-
link: https://sdkdocs.easemob.com/apidoc/unity/annotated.html
2086+
link: https://doc.easemob.com/apidoc/unity/annotated.html
20872087
- title: IM 服务端
20882088
icon: /feature/api-server.svg
20892089
contexts:

0 commit comments

Comments
 (0)