-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme): introduce independent search page
- Loading branch information
Showing
7 changed files
with
123 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<script setup lang="ts"> | ||
import { | ||
defineAsyncComponent, | ||
onMounted, | ||
onUnmounted, | ||
ref | ||
} from 'vue' | ||
import { useData } from './composables/data' | ||
const { theme, site } = useData() | ||
const VPLocalSearchBox = __VP_LOCAL_SEARCH__ | ||
? defineAsyncComponent(() => import('./components/VPLocalSearchBox.vue')) | ||
: () => null | ||
const VPAlgoliaSearchBox = __ALGOLIA__ | ||
? defineAsyncComponent(() => import('./components/VPAlgoliaSearchBox.vue')) | ||
: () => null | ||
const provider = __ALGOLIA__ ? 'algolia' : __VP_LOCAL_SEARCH__ ? 'local' : '' | ||
const filterText = ref(''); | ||
const handleFilterTextChange = (text: string) => { | ||
filterText.value = text; | ||
const newUrl = (new URL(window.location.href)); | ||
newUrl.searchParams.set('q', filterText.value) | ||
history.replaceState({}, '', newUrl.href) | ||
} | ||
const title = site.value.title; | ||
</script> | ||
|
||
<template> | ||
<div class="Search"> | ||
|
||
<div class="search-wrapper"> | ||
<h1 class="title">{{ filterText ? `Search Results For "${filterText}"` : `Search ${title}` }}</h1> | ||
|
||
<template v-if="provider === 'local'"> | ||
<VPLocalSearchBox @filter-change="handleFilterTextChange"/> | ||
</template> | ||
|
||
<template v-else-if="provider === 'algolia'"> | ||
<VPAlgoliaSearchBox | ||
:algolia="theme.search?.options ?? theme.algolia" | ||
/> | ||
</template> | ||
</div> | ||
</div> | ||
</template> | ||
<style scoped> | ||
.search-wrapper { | ||
position: relative; | ||
padding: 12px; | ||
margin: 64px auto 0; | ||
width: min(100vw - 60px, 900px); | ||
} | ||
.title { | ||
margin-bottom: 12px; | ||
letter-spacing: -0.02em; | ||
line-height: 40px; | ||
font-size: 32px; | ||
font-weight: 600; | ||
outline: none; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters