Skip to content

Commit 5000410

Browse files
committed
further tweak api filtering
1 parent b463848 commit 5000410

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

src/.vitepress/config.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -277,26 +277,6 @@ const sidebar = {
277277
}
278278
]
279279
},
280-
{
281-
text: 'Options API',
282-
items: [
283-
{ text: 'Options: State', link: '/api/options-state' },
284-
{ text: 'Options: Rendering', link: '/api/options-rendering' },
285-
{
286-
text: 'Options: Lifecycle',
287-
link: '/api/options-lifecycle'
288-
},
289-
{
290-
text: 'Options: Composition',
291-
link: '/api/options-composition'
292-
},
293-
{ text: 'Options: Misc', link: '/api/options-misc' },
294-
{
295-
text: 'Component Instance',
296-
link: '/api/component-instance'
297-
}
298-
]
299-
},
300280
{
301281
text: 'Composition API',
302282
items: [
@@ -323,6 +303,26 @@ const sidebar = {
323303
}
324304
]
325305
},
306+
{
307+
text: 'Options API',
308+
items: [
309+
{ text: 'Options: State', link: '/api/options-state' },
310+
{ text: 'Options: Rendering', link: '/api/options-rendering' },
311+
{
312+
text: 'Options: Lifecycle',
313+
link: '/api/options-lifecycle'
314+
},
315+
{
316+
text: 'Options: Composition',
317+
link: '/api/options-composition'
318+
},
319+
{ text: 'Options: Misc', link: '/api/options-misc' },
320+
{
321+
text: 'Component Instance',
322+
link: '/api/component-instance'
323+
}
324+
]
325+
},
326326
{
327327
text: 'Built-ins',
328328
items: [

src/api/ApiIndex.vue

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,38 @@ const query = ref('')
66
77
const filtered = computed(() => {
88
const q = query.value.toLowerCase()
9+
const matches = (text: string) =>
10+
text.toLowerCase().replace(/-/g, ' ').includes(q)
11+
912
return apiIndex
1013
.map((section) => {
11-
if (section.text.toLowerCase().includes(q)) {
14+
// section title match
15+
if (matches(section.text)) {
1216
return section
1317
}
14-
const items = section.items
18+
19+
// filter groups
20+
const matchedGroups = section.items
1521
.map((item) => {
16-
if (item.text.toLowerCase().includes(q)) {
22+
// group title match
23+
if (matches(item.text)) {
1724
return item
1825
}
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 }
2434
: null
2535
})
2636
.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
2841
})
2942
.filter((i) => i)
3043
})
@@ -54,13 +67,13 @@ function slugify(text) {
5467
<input class="api-filter" placeholder="Filter" v-model="query" />
5568
</div>
5669

57-
<div v-for="section of filtered" class="api-section">
70+
<div v-for="section of filtered" :key="section.text" class="api-section">
5871
<h2>{{ section.text }}</h2>
5972
<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">
6174
<h3>{{ item.text }}</h3>
6275
<ul>
63-
<li v-for="h of item.headers">
76+
<li v-for="h of item.headers" :key="h">
6477
<a :href="item.link + '.html#' + slugify(h)">{{ h }}</a>
6578
</li>
6679
</ul>

0 commit comments

Comments
 (0)