-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
连远生
committed
Sep 3, 2024
1 parent
ab31cd4
commit 0527659
Showing
4 changed files
with
278 additions
and
178 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 @@ | ||
<template> | ||
<div class="place-content-center" @click="showSearchDialog"> | ||
<Icon name="uil:search" /> | ||
<div ref="docsearchRef" v-show="false"></div> | ||
</div> | ||
</template> | ||
|
||
<script lang="tsx"> | ||
import { defineComponent } from "vue"; | ||
import docsearch from "@docsearch/js"; | ||
import "@docsearch/css"; | ||
export default defineComponent({ | ||
setup() { | ||
useHead({ | ||
link: [ | ||
{ | ||
rel: "preconnect", | ||
href: "https://F9HLDQ3K76-dsn.algolia.net", | ||
crossorigin: "anonymous", | ||
}, | ||
], | ||
}); | ||
const docsearchRef = ref<HTMLElement>(); | ||
const showSearchDialog = () => { | ||
docsearchRef.value?.firstElementChild?.dispatchEvent(new Event("click")); | ||
}; | ||
const router = useRouter(); | ||
onMounted(() => { | ||
if (import.meta.browser) { | ||
docsearch({ | ||
container: docsearchRef.value!, | ||
appId: "F9HLDQ3K76", | ||
indexName: "laoergege-pages", | ||
apiKey: "0a2dda2da8594d4d2e2ab6e7fff6dcff", | ||
hitComponent: ({ hit, children }) => { | ||
return { | ||
...children, | ||
type: "a", | ||
props: { | ||
href: hit.url, | ||
onClick: (e: Event) => { | ||
e.preventDefault(); | ||
router.push(new URL(hit.url).pathname); | ||
}, | ||
children, | ||
}, | ||
}; | ||
}, | ||
}); | ||
} | ||
}); | ||
return { docsearchRef, showSearchDialog }; | ||
}, | ||
}); | ||
</script> | ||
|
||
<style lang="css"> | ||
:root { | ||
--docsearch-primary-color: oklch(var(--p)); | ||
--docsearch-text-color: oklch(var(--pc)); | ||
} | ||
</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
Oops, something went wrong.