Skip to content

Commit

Permalink
Internal search (#29)
Browse files Browse the repository at this point in the history
* update to vitepress@1.0.0-rc.44

* patch algolia search to handle internalDomain stuff part 1

* internal search test 2

* CL

* CL2
  • Loading branch information
pirog committed Mar 5, 2024
1 parent 0bce875 commit 669d9c7
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 153 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
## v1.0.0-beta.40 - [TBD](https://github.com/lando/vitepress-theme-default-plus/releases/tag/v1.0.0-beta.40)
## v1.0.0-beta.40 - [March 5, 2024](https://github.com/lando/vitepress-theme-default-plus/releases/tag/v1.0.0-beta.40)

## New Features

* Added `mergeWith` for more explicit contrubutor merging
* Updated to `vitepress@1.0.0-rc.44`

## Fixes

* Changed member data to only render if available [#27](https://github.com/lando/vitepress-theme-default-plus/pull/27)
* Fixed Algolia search from displaying contrib information in source text, requires reindexing on Algolia end
* Fixed Algolia search from attempting to route to internal pages that are actually external

## Internal

* Changed `VPLTeamMembersItem.vue` to wrap name in `div` instead of `h1`

## v1.0.0-beta.39 - [February 17, 2024](https://github.com/lando/vitepress-theme-default-plus/releases/tag/v1.0.0-beta.39)

Expand Down
87 changes: 87 additions & 0 deletions components/VPLAlgoliaSearchBox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<template>
<div id="docsearch" />
</template>


<script setup>
import docsearch from '@docsearch/js';
import {useData, useRoute, useRouter} from 'vitepress';
import {nextTick, onMounted, watch} from 'vue';
const props = defineProps({
algolia: {
type: Object,
default: () => ({}),
},
});
const router = useRouter();
const route = useRoute();
const {site, localeIndex, lang} = useData();
onMounted(update);
watch(localeIndex, update);
async function update() {
await nextTick();
const options = {
...props.algolia,
...props.algolia.locales?.[localeIndex.value],
};
const rawFacetFilters = options.searchParameters?.facetFilters ?? [];
const facetFilters = [
...(Array.isArray(rawFacetFilters)
? rawFacetFilters
: [rawFacetFilters]
).filter(f => !f.startsWith('lang:')),
`lang:${lang.value}`,
];
initialize({
...options,
searchParameters: {
...options.searchParameters,
facetFilters,
},
});
}
function initialize(userOptions = {}) {
const options = Object.assign({}, userOptions, {
container: '#docsearch',
navigator: {
navigate({itemUrl}) {
const {pathname: hitPathname} = new URL(window.location.origin + itemUrl);
// router doesn't handle same-page navigation so we use the native
// browser location API for anchor navigation
if (route.path === hitPathname) window.location.assign(window.location.origin + itemUrl);
else router.go(itemUrl);
},
},
transformItems(items) {
console.log(items);
return items.map(item => Object.assign({}, item, {url: getRelativePath(item.url)}));
},
hitComponent({hit, children}) {
return {
__v: null,
type: 'a',
ref: undefined,
constructor: undefined,
target: '_blank',
key: undefined,
props: {href: hit.url, children, target: '_self'},
};
},
});
docsearch(options);
}
function getRelativePath(url) {
const {pathname, hash} = new URL(url, location.origin);
return pathname.replace(/\.html$/, site.value.cleanUrls ? '' : '.html') + hash;
}
</script>
4 changes: 2 additions & 2 deletions components/VPLTeamMembersItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
</Link>
</figure>
<div class="data">
<h1 class="name">
<div class="name">
{{ member.name }}
</h1>
</div>
<p
v-if="member.title || member.org"
class="affiliation"
Expand Down
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export async function defineConfig(userConfig = {}, defaults = {}) {

// vite
vite.resolve.alias.push(...[
{find: /^.*\/VPAlgoliaSearchBox\.vue$/, replacement: fileURLToPath(new URL('./components/VPLAlgoliaSearchBox.vue', import.meta.url))},
{find: /^.*\/VPDocFooter\.vue$/, replacement: fileURLToPath(new URL('./components/VPLDocFooter.vue', import.meta.url))},
{find: /^.*\/VPLink\.vue$/, replacement: fileURLToPath(new URL('./components/VPLLink.vue', import.meta.url))},
{find: /^.*\/VPMenuGroup\.vue$/, replacement: fileURLToPath(new URL('./components/VPLMenuGroup.vue', import.meta.url))},
Expand Down
Loading

0 comments on commit 669d9c7

Please sign in to comment.