forked from vuejs/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiIndex.vue
244 lines (216 loc) Β· 4.73 KB
/
ApiIndex.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<script setup lang="ts">
// in .vue components or .md pages:
// named import "data" is the resolved static data
// can also import types for type consistency
import { data as apiIndex, APIGroup } from './api.data'
import { ref, computed } from 'vue'
const query = ref('')
const normalize = (s: string) => s.toLowerCase().replace(/-/g, ' ')
const filtered = computed(() => {
const q = normalize(query.value)
const matches = (text: string) => normalize(text).includes(q)
return apiIndex
.map((section) => {
// section title match
if (matches(section.text)) {
return section
}
// filter groups
const matchedGroups = section.items
.map((item) => {
// group title match
if (matches(item.text)) {
return item
}
// ssr special case
if (q.includes('ssr') && item.text.startsWith('Server')) {
return item
}
// filter headers
const matchedHeaders = item.headers.filter(matches)
return matchedHeaders.length
? { text: item.text, link: item.link, headers: matchedHeaders }
: null
})
.filter((i) => i)
return matchedGroups.length
? { text: section.text, items: matchedGroups }
: null
})
.filter((i) => i) as APIGroup[]
})
// same as vitepress' slugify logic
function slugify(text: string): string {
return (
text
// Replace special characters
.replace(/[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g, '-')
// Remove continuous separators
.replace(/\-{2,}/g, '-')
// Remove prefixing and trailing separators
.replace(/^\-+|\-+$/g, '')
// ensure it doesn't start with a number (#121)
.replace(/^(\d)/, '_$1')
// lowercase
.toLowerCase()
)
}
</script>
<template>
<div id="api-index">
<div class="header">
<h1>API Reference</h1>
<div class="api-filter">
<label for="api-filter">Filter</label>
<input
type="search"
placeholder="Enter keyword"
id="api-filter"
v-model="query"
/>
</div>
</div>
<div
v-for="section of filtered"
:key="section.text"
class="api-section"
>
<h2 :id="slugify(section.text)">{{ section.text }}</h2>
<div class="api-groups">
<div
v-for="item of section.items"
:key="item.text"
class="api-group"
>
<h3>{{ item.text }}</h3>
<ul>
<li v-for="h of item.headers" :key="h">
<a :href="item.link + '.html#' + slugify(h)">{{ h }}</a>
</li>
</ul>
</div>
</div>
</div>
<div v-if="!filtered.length" class="no-match">
No API matching "{{ query }}" found.
</div>
</div>
</template>
<style scoped>
#api-index {
max-width: 1024px;
margin: 0px auto;
padding: 64px 32px;
}
h1,
h2,
h3 {
font-weight: 600;
line-height: 1;
}
h1,
h2 {
letter-spacing: -0.02em;
}
h1 {
font-size: 38px;
}
h2 {
font-size: 24px;
color: var(--vt-c-text-1);
margin: 36px 0;
transition: color 0.5s;
padding-top: 36px;
border-top: 1px solid var(--vt-c-divider-light);
}
h3 {
letter-spacing: -0.01em;
color: var(--vt-c-green);
font-size: 18px;
margin-bottom: 1em;
transition: color 0.5s;
}
.api-section {
margin-bottom: 64px;
}
.api-groups a {
font-size: 15px;
font-weight: 500;
line-height: 2;
color: var(--vt-c-text-code);
transition: color 0.5s;
}
.dark api-groups a {
font-weight: 400;
}
.api-groups a:hover {
color: var(--vt-c-green);
transition: none;
}
.api-group {
break-inside: avoid;
overflow: auto;
margin-bottom: 20px;
background-color: var(--vt-c-bg-soft);
border-radius: 8px;
padding: 28px 32px;
transition: background-color 0.5s;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
}
.api-filter {
display: flex;
align-items: center;
justify-content: flex-start;
gap: 1rem;
}
.api-filter input {
border: 1px solid var(--vt-c-divider);
border-radius: 8px;
padding: 6px 12px;
}
.api-filter:focus {
border-color: var(--vt-c-green-light);
}
.no-match {
font-size: 1.2em;
color: var(--vt-c-text-3);
text-align: center;
margin-top: 36px;
padding-top: 36px;
border-top: 1px solid var(--vt-c-divider-light);
}
@media (max-width: 768px) {
#api-index {
padding: 42px 24px;
}
h1 {
font-size: 32px;
margin-bottom: 24px;
}
h2 {
font-size: 22px;
margin: 42px 0 32px;
padding-top: 32px;
}
.api-groups a {
font-size: 14px;
}
.header {
display: block;
}
}
@media (min-width: 768px) {
.api-groups {
columns: 2;
}
}
@media (min-width: 1024px) {
.api-groups {
columns: 3;
}
}
</style>