-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsearch.vue
63 lines (56 loc) · 1.35 KB
/
search.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
<script setup lang="ts">
import { useDebounceFn } from '@vueuse/core'
const searchValue = ref('')
const queryResult = ref()
const getQueryResult = useDebounceFn(async () => {
if (!searchValue.value) {
queryResult.value = []
return
}
queryResult.value = await queryContent()
.where({
$or: [
{ title: { $regex: new RegExp(`.*${searchValue.value}.*`, 'i') } },
{
description: {
$regex: new RegExp(`.*${searchValue.value}.*`, 'i'),
},
},
{
tags: {
$contains: searchValue.value,
},
},
],
})
.find()
}, 600)
watch(searchValue, getQueryResult)
</script>
<template>
<h1 class="text-title mb-2em font-bold">
Search
</h1>
<div class="slide-enter-content">
<input v-model="searchValue" placeholder="Search post title / description / tag" class="search-input mb-2em">
<ul>
<cell
v-for="(article, index) in queryResult" :key="article._path" :article="article"
slide-enter :style="{ '--stagger': index + 1 }"
/>
</ul>
</div>
</template>
<style>
.search-input {
width: 100%;
padding: 1em;
background-color: var(--input-bg);
border-bottom: 2px solid var(--common-bd);
outline: none;
transition: var(--common-transition);
}
.search-input:focus {
border-color: currentcolor;
}
</style>