11<template >
22 <section v-if =" data.length" class =" drawer-main__search-results" >
3- <template v-for =" (i ) in visibleResults " :key =" i " >
4- <div class =" search-result" @click =" gotTo(parseUrl(i .url))" >
5- <div class =" search-result__title" v-html =" getTitleForArticle(i .title)" ></div >
6- <div class =" search-result__breadcrumb" v-html =" getBreadcrumbsForArticle(i .title)" ></div >
7- <div class =" search-result__text" v-html =" formatPreviewMarkdown(i .preview)" ></div >
3+ <template v-for =" (item , index ) in visibleResults " :key =" item . objectID || index " >
4+ <div class =" search-result" @click =" gotTo(parseUrl(item .url))" >
5+ <div class =" search-result__title" v-html =" getTitleForArticle(item .title)" ></div >
6+ <div class =" search-result__breadcrumb" v-html =" getBreadcrumbsForArticle(item .title)" ></div >
7+ <div class =" search-result__text" v-html =" formatPreviewMarkdown(item .preview)" ></div >
88 </div >
99 </template >
10+ <div v-if =" countOfHiddenResults > 0" class =" show-more" @click =" showAllHiddenResult" >
11+ <p >Show {{ countOfHiddenResults }} more results</p >
12+ </div >
1013 </section >
1114 <div v-else >
1215 <p v-if =" !modelValue.length" class =" no_results" >Write your search query, then press Enter or click the search button.</p >
1720import { computed , inject , ref } from " vue" ;
1821import { marked } from " marked" ;
1922
20- // Create a new renderer instance
2123const renderer = new marked.Renderer ();
2224
23- // Redefine how headers are processed
2425renderer .heading = function (text ) {
2526 // check if text is a string
2627 if (typeof text !== " string" ) {
@@ -29,13 +30,15 @@ renderer.heading = function (text) {
2930 return ` <strong>${ text} </strong>` ;
3031};
3132
32- // Define image rendering to exclude images
3333renderer .image = function () {
34- return " " ; // Exclude image tags by returning an empty string
34+ return " " ;
3535};
3636
3737const formatPreviewMarkdown = (markdown ) => {
38- return marked (markdown, { renderer });
38+ let md = marked (markdown, { renderer });
39+ // remove all <br> tags
40+ md = md .replace (/ <br>/ g , " " );
41+ return md;
3942};
4043
4144const props = defineProps ({
@@ -49,7 +52,7 @@ const props = defineProps({
4952 },
5053});
5154
52- const { MAX_VISIBLE_RESULT , MAX_VISIBLE_ROWS } = inject (' themeConfig' );
55+ const { MAX_VISIBLE_RESULT } = inject (' themeConfig' );
5356const isShowAllResult = ref (false );
5457
5558const gotTo = (url ) => {
@@ -82,10 +85,6 @@ const showAllHiddenResult = () => {
8285 isShowAllResult .value = true ;
8386};
8487
85- const collapseResults = () => {
86- isShowAllResult .value = false ;
87- };
88-
8988const getTitleForArticle = (title ) => {
9089 let sliced = title .split (" ->" ).map ((part ) => part .trim ());
9190 return sliced .pop ();
@@ -102,35 +101,26 @@ const getBreadcrumbsForArticle = (title) => {
102101< style lang= " stylus" >
103102@import " ../../styles/config.styl" ;
104103
105- .algolia - docsearch- suggestion-- highlight {
106- background: $drawerHighlightTextBgColor ! important;
107- color: $drawerHighlightTextColor ! important;
108- }
109-
110104.drawer - main__search- results {
111105 display: grid;
112- grid- template- columns: repeat (auto- fill, minmax (300px , 1fr ));
113- column - gap: $drawerSearchColumnGap;
114- row - gap : $drawerSearchRowGap;
106+ grid- template- columns: repeat (auto- fill, minmax (280px , 1fr )); // Flexible grid with min width
107+ gap: 1 . 5rem ; // Increased gap for better spacing
108+ padding : 1rem ; // Padding around the results area
115109}
116110
117111.search - result {
118112 padding: 1rem ;
119113 border: 1px solid $drawerSearchBorderColor;
120- border- radius: 8px ;
121- display: flex;
122- flex- direction: column;
123- align- items: flex- start;
124- justify- content: flex- start;
125- gap: $drawerOneSearchResultGap;
126- width: 100 % ;
127- cursor: pointer;
114+ border- radius: 10px ; // More rounded corners
115+ background: $searchResultBackgroundColor; // Added background color for better visibility
116+ box- shadow: 0 2px 4px rgba (0 , 0 , 0 , 0.1 ); // Shadow for elevation
128117 transition: box- shadow 0 .3s ease, transform 0 .3s ease;
118+ cursor: pointer;
119+ overflow: hidden;
129120
130121 & : hover {
131- box- shadow: 0 4px 8px rgba (0 , 0 , 0 , 0.1 );
122+ box- shadow: 0 4px 8px rgba (0 , 0 , 0 , 0.2 ); // Increased shadow on hover
132123 transform: translateY (- 2px );
133-
134124 .search - result__title {
135125 color: $mainColor;
136126 text- decoration: underline;
@@ -140,51 +130,54 @@ const getBreadcrumbsForArticle = (title) => {
140130 & __title {
141131 font- size: $drawerSearchResultTitleFontSize;
142132 font- weight: $drawerSearchResultTitleWeight;
143- line- height: $drawerSearchResultTitleLineHeight;
144133 color: $drawerSearchResultTitleColor;
145134 margin: 0 ;
135+ line- height: 1.4 ; // Increased line height for better readability
146136 }
147137
148138 & __text {
149139 font- size: $drawerSearchResultTextFontSize;
150140 line- height: $drawerSearchResultTextLineHeight;
151141 color: $drawerSearchResultTextColor;
152- margin: 0 ;
142+ margin: 0 . 5rem 0 ; // Added margin for spacing
153143 overflow: hidden;
154144 display: - webkit- box;
155145 - webkit- box- orient: vertical;
156- - webkit- line- clamp: v - bind ( MAX_VISIBLE_ROWS );
146+ - webkit- line- clamp: 3 ; // Limit preview text lines for coherence
157147 - webkit- box- decoration- break: clone;
158148 box- decoration- break: clone;
159149 }
160150
161151 & __breadcrumb {
162152 font- size: $drawerSearchResultBreadcrumbTextSize;
163- line- height: $drawerSearchResultBreadcrumbLineHeight;
164153 color: $drawerSearchResultBreadcrumbColor;
165154 margin: 0 ;
166155 }
167156}
168157
169- .no_results {
170- font- size: 1 .5625rem ;
158+ .show - more {
171159 text- align: center;
160+ margin: 1rem 0 ;
161+ cursor: pointer;
172162
173- & __link {
163+ p {
174164 color: $mainColor;
175- & : hover {
176- text- decoration: underline;
177- }
165+ font- weight: bold;
178166 }
179167}
180168
169+ .no_results {
170+ font- size: 1 .5625rem ;
171+ text- align: center;
172+ }
173+
181174@media (max - width : $mobileBreakpoint ) {
182175 .drawer - main__search- results {
183- grid- template- columns: repeat ( 1 , 1fr );
176+ grid- template- columns: 1fr ; // Single column on mobile
184177 }
185178
186179 .no_results {
187180 font- size: 1 .25rem ;
188181 }
189182}
190- < / style>
183+ < / style>
0 commit comments