File tree Expand file tree Collapse file tree 3 files changed +25
-7
lines changed
packages/gitbook/src/components/Search Expand file tree Collapse file tree 3 files changed +25
-7
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " gitbook " : patch
3+ ---
4+
5+ Fix UX issue about highlighting the search term in search result sections
Original file line number Diff line number Diff line change @@ -56,13 +56,19 @@ git clone https://github.com/gitbookIO/gitbook.git
5656bun install
5757```
5858
59- 4 . Start your local development server.
59+ 4 . Run build.
60+
61+ ```
62+ bun build:v2
63+ ```
64+
65+ 5 . Start your local development server.
6066
6167```
6268bun dev:v2
6369```
6470
65- 5 . Open a published GitBook space in your web browser, prefixing it with ` http://localhost:3000/ ` .
71+ 6 . Open a published GitBook space in your web browser, prefixing it with ` http://localhost:3000/ ` .
6672
6773examples:
6874
Original file line number Diff line number Diff line change @@ -66,11 +66,7 @@ export const SearchSectionResultItem = React.forwardRef(function SearchSectionRe
6666 < HighlightQuery query = { query } text = { item . title } />
6767 </ p >
6868 ) : null }
69- { item . body ? (
70- < p className = { tcls ( 'text-sm' , 'line-clamp-3' , 'relative' ) } >
71- < HighlightQuery query = { query } text = { item . body } />
72- </ p >
73- ) : null }
69+ { item . body ? highlightQueryInBody ( item . body , query ) : null }
7470 </ div >
7571 < div
7672 className = { tcls (
@@ -90,3 +86,14 @@ export const SearchSectionResultItem = React.forwardRef(function SearchSectionRe
9086 </ Link >
9187 ) ;
9288} ) ;
89+
90+ function highlightQueryInBody ( body : string , query : string ) {
91+ const idx = body . indexOf ( query ) ;
92+
93+ // Ensure the query to be highlighted is visible in the body.
94+ return (
95+ < p className = { tcls ( 'text-sm' , 'line-clamp-3' , 'relative' ) } >
96+ < HighlightQuery query = { query } text = { idx < 20 ? body : `...${ body . slice ( idx - 15 ) } ` } />
97+ </ p >
98+ ) ;
99+ }
You can’t perform that action at this time.
0 commit comments