Skip to content

Commit 9379bdc

Browse files
Add opensearch XML for automatic search engine
Also fixup some TS lint errors in the new component, language server wasn't working before.
1 parent e6802e5 commit 9379bdc

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

.vuepress/components/URLDocSearch.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
</template>
44

55
<script setup lang="ts">
6-
import { DocSearch } from '@vuepress/plugin-docsearch/client';
6+
import { DocSearch, DocSearchOptions } from '@vuepress/plugin-docsearch/client';
77
import { useDebounceFn, useEventListener } from '@vueuse/core';
8-
import { onMounted, onUnmounted, ref } from 'vue';
8+
import { onMounted, Ref, ref } from 'vue';
99
import { useRouter, useRoute } from 'vue-router';
1010
1111
const SEARCH_KEY = 'search';
12-
const docsearchOptions = ref({});
12+
const docsearchOptions: Ref<DocSearchOptions> = ref({});
1313
const router = useRouter();
1414
const route = useRoute();
1515
@@ -18,20 +18,20 @@ onMounted(() => {
1818
const query = new URL(window.location.href).searchParams.get(SEARCH_KEY);
1919
if (query) {
2020
docsearchOptions.value.initialQuery = query;
21-
document.querySelector('.DocSearch-Button').click();
21+
(document.querySelector('.DocSearch-Button') as HTMLButtonElement).click();
2222
}
2323
});
2424
2525
// There's some debounce builtin to docsearch, this mimics that and should
2626
// help prevent browser history from getting filled with partial queries.
2727
const inputHandler = useDebounceFn(handleSearchInput, 500);
28-
useEventListener('input', inputHandler);
28+
useEventListener('input', (event) => inputHandler(event as InputEvent));
2929
3030
// Update the URL bar when the search input changes.
31-
function handleSearchInput(event) {
32-
const searchQuery = event.target.value;
33-
34-
if (event.target.id !== 'docsearch-input' || !searchQuery) {
31+
function handleSearchInput(event: InputEvent) {
32+
const target = event.target as HTMLInputElement | undefined;
33+
const searchQuery = target?.value;
34+
if (target?.id !== 'docsearch-input' || !searchQuery) {
3535
return;
3636
}
3737

.vuepress/config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ export default defineUserConfig({
110110
{ name: 'apple-mobile-web-app-status-bar-style', content: 'black' },
111111
],
112112
['link', { rel: 'icon', href: '/icon.png' }],
113+
[
114+
'link',
115+
{
116+
rel: 'search',
117+
type: 'application/opensearchdescription+xml',
118+
title: 'Nushell Docs', // NOTE: must match ShortName
119+
href: '/opensearch.xml',
120+
},
121+
],
113122
],
114123
markdown: {
115124
importCode: {

.vuepress/public/opensearch.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<OpenSearchDescription
2+
xmlns="http://a9.com/-/spec/opensearch/1.1/"
3+
xmlns:moz="http://www.mozilla.org/2006/browser/search/"
4+
>
5+
<ShortName>Nushell Docs</ShortName>
6+
<Description>Search Nushell documentation</Description>
7+
<InputEncoding>UTF-8</InputEncoding>
8+
<Image width="16" height="16" type="image/png">https://www.nushell.sh/icon.png</Image>
9+
<Url type="text/html" template="https://www.nushell.sh/?search={searchTerms}" />
10+
<Url type="application/opensearchdescription+xml" rel="self" template="https://www.nushell.sh/opensearch.xml" />
11+
<!-- TODO: it might be possible to provide suggestions via some Algolia API? -->
12+
</OpenSearchDescription>

0 commit comments

Comments
 (0)