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
56
56
bun install
57
57
```
58
58
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.
60
66
61
67
```
62
68
bun dev:v2
63
69
```
64
70
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/ ` .
66
72
67
73
examples:
68
74
Original file line number Diff line number Diff line change @@ -66,11 +66,7 @@ export const SearchSectionResultItem = React.forwardRef(function SearchSectionRe
66
66
< HighlightQuery query = { query } text = { item . title } />
67
67
</ p >
68
68
) : 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 }
74
70
</ div >
75
71
< div
76
72
className = { tcls (
@@ -90,3 +86,14 @@ export const SearchSectionResultItem = React.forwardRef(function SearchSectionRe
90
86
</ Link >
91
87
) ;
92
88
} ) ;
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