Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add opensearch support #980

Merged
merged 4 commits into from Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion app.config.ts
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
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
@@ -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
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
@@ -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>'
})