Skip to content

Commit

Permalink
docs: fix and improve search result display on website (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
iisakkirotko authored and maartenbreddels committed Apr 8, 2024
1 parent c2d5a53 commit de4ec69
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions solara/website/assets/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ blockquote p:last-child {
background-color: var(--dark-color-primary-lightest);
}

/* Algolia search results styling */
.algolia-docsearch-suggestion--highlight {
color: var(--color-primary);
font-weight: 700;
}

/* API PAGE REFACTOR STYLE */

.v-sheet.api-search-container{
Expand Down
34 changes: 32 additions & 2 deletions solara/website/components/algolia_api.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
</v-list-item-content>
</v-list-item>
</v-list>
<v-list v-else>
<v-list v-else :style="{width: menuWidth + 'px'}">
<v-list-item-group v-model="item">
<v-list-item v-for="(element, index) in this.results.hits" :key="element['url']">
<v-list-item-content>
<v-list-item-title>{{ element.hierarchy[element.type] }}</v-list-item-title>
<v-list-item-title>
{{ element.hierarchy.lvl1 }}
</v-list-item-title>
<v-list-item-subtitle v-if="element.hierarchy.lvl2 !== null">
{{ element.hierarchy.lvl2 }}
</v-list-item-subtitle>
<v-list-item-subtitle v-html="getSnippet(element)"></v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</v-list-item-group>
Expand All @@ -49,6 +55,9 @@ module.exports = {
this.algoliasearch = (await this.import([`https://cdn.jsdelivr.net/npm/[email protected]/dist/algoliasearch-lite.umd.js`]))[0];
this.initSearch();
window.search = this;
this.updateMenuWidth();
window.addEventListener('resize', this.updateMenuWidth);
},
watch: {
query ( value ) {
Expand Down Expand Up @@ -97,6 +106,26 @@ module.exports = {
this.$set(this.results, []);
}
},
getSnippet( element ) {
if (element.type == "content") {
return element._highlightResult.content.value;
}
let snippet = element._highlightResult.hierarchy[element.type].value;
if (snippet.matchLevel === "none" ) {
snippet = element._highlightResult.hierarchy["lvl" + parseInt(element.type[3] - 1)].value
}
return snippet;
},
updateMenuWidth() {
// Ensure the element is rendered and has dimensions
this.$nextTick(() => {
const activator = this.$refs.search;
if (activator && activator.$el) {
// Update the menuWidth with the activator's width
this.menuWidth = activator.$el.offsetWidth;
}
});
},
import(dependencies) {
return this.loadRequire().then(
() => {
Expand Down Expand Up @@ -151,6 +180,7 @@ module.exports = {
item: null,
show_results: false,
mac: false,
menuWidth: 0,
}
},
}
Expand Down

0 comments on commit de4ec69

Please sign in to comment.