@@ -6,25 +6,38 @@ const query = ref('')
6
6
7
7
const filtered = computed (() => {
8
8
const q = query .value .toLowerCase ()
9
+ const matches = (text : string ) =>
10
+ text .toLowerCase ().replace (/ -/ g , ' ' ).includes (q )
11
+
9
12
return apiIndex
10
13
.map ((section ) => {
11
- if (section .text .toLowerCase ().includes (q )) {
14
+ // section title match
15
+ if (matches (section .text )) {
12
16
return section
13
17
}
14
- const items = section .items
18
+
19
+ // filter groups
20
+ const matchedGroups = section .items
15
21
.map ((item ) => {
16
- if (item .text .toLowerCase ().includes (q )) {
22
+ // group title match
23
+ if (matches (item .text )) {
17
24
return item
18
25
}
19
- const headers = item .headers .filter ((h ) => {
20
- return h .toLowerCase ().includes (q )
21
- })
22
- return headers .length
23
- ? { text: item .text , link: item .link , headers }
26
+ // ssr special case
27
+ if (q .includes (' ssr' ) && item .text .startsWith (' Server' )) {
28
+ return item
29
+ }
30
+ // filter headers
31
+ const matchedHeaders = item .headers .filter (matches )
32
+ return matchedHeaders .length
33
+ ? { text: item .text , link: item .link , headers: matchedHeaders }
24
34
: null
25
35
})
26
36
.filter ((i ) => i )
27
- return items .length ? { text: section .text , items } : null
37
+
38
+ return matchedGroups .length
39
+ ? { text: section .text , items: matchedGroups }
40
+ : null
28
41
})
29
42
.filter ((i ) => i )
30
43
})
@@ -54,13 +67,13 @@ function slugify(text) {
54
67
<input class =" api-filter" placeholder =" Filter" v-model =" query" />
55
68
</div >
56
69
57
- <div v-for =" section of filtered" class =" api-section" >
70
+ <div v-for =" section of filtered" :key = " section.text " class =" api-section" >
58
71
<h2 >{{ section.text }}</h2 >
59
72
<div class =" api-groups" >
60
- <div v-for =" item of section.items" class =" api-group" >
73
+ <div v-for =" item of section.items" :key = " item.text " class =" api-group" >
61
74
<h3 >{{ item.text }}</h3 >
62
75
<ul >
63
- <li v-for =" h of item.headers" >
76
+ <li v-for =" h of item.headers" :key = " h " >
64
77
<a :href =" item.link + '.html#' + slugify(h)" >{{ h }}</a >
65
78
</li >
66
79
</ul >
0 commit comments