Skip to content

Commit

Permalink
feat: add opensearch support (#980)
Browse files Browse the repository at this point in the history
Co-authored-by: Sébastien Chopin <seb@nuxtlabs.com>
  • Loading branch information
qwerzl and atinux authored Oct 5, 2023
1 parent 5260272 commit 1dfc769
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export default defineAppConfig({

description: 'The best place to start your documentation.',

url: 'https://docus.dev',

image: 'https://user-images.githubusercontent.com/904724/185365452-87b7ca7b-6030-4813-a2db-5e65c785bf88.png',

socials: {},
Expand Down Expand Up @@ -41,6 +43,6 @@ export default defineAppConfig({
repo: undefined,
owner: undefined,
edit: false
}
},
}
})
8 changes: 8 additions & 0 deletions components/app/AppSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ function closeButtonHandler() {
}
}
onMounted (() => {
const route = useRoute()
if (route.query.q) {
show.value = true
q.value = route.query.q
}
})
// Scroll to selected item on change
watch(selected, value => {
const nextId = results?.value?.[value]?.item?.id
Expand Down
17 changes: 12 additions & 5 deletions layouts/page.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<script setup lang="ts">
const { config } = useDocus()
useHead({
link: {
rel: 'search',
type: 'application/opensearchdescription+xml',
href: 'opensearch.xml'
}
})
</script>

<template>
Expand All @@ -17,10 +24,10 @@ const { config } = useDocus()
<style lang="ts" scoped>
css({
'.page-layout': {
display: 'flex',
flexDirection: 'column',
position: 'relative'
}
'.page-layout': {
display: 'flex',
flexDirection: 'column',
position: 'relative'
}
})
</style>
3 changes: 2 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export default defineNuxtConfig({
},
nitro: {
prerender: {
ignore: ['/__pinceau_tokens_config.json', '/__pinceau_tokens_schema.json']
ignore: ['/__pinceau_tokens_config.json', '/__pinceau_tokens_schema.json'],
routes: ['/opensearch.xml']
}
},
})
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions server/routes/opensearch.xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default defineEventHandler(async () => {
const config = useAppConfig()
return '<?xml version="1.0"?>\n' +
'<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">\n' +
' <ShortName>' + config?.docus?.title + '</ShortName>\n' +
' <Description>' + config?.docus?.description + '</Description>\n' +
' <Image width="16" height="16" type="image/x-icon">' + config?.docus?.url + '/favicon.ico</Image>\n' +
' <Url type="text/html" template="' + config?.docus?.url + '">\n' +
' <Param name="q" value="{searchTerms}"/>\n' +
' </Url>\n' +
'</OpenSearchDescription>'
})

0 comments on commit 1dfc769

Please sign in to comment.