2121// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222// SOFTWARE.
2323
24- import cn from ' clsx' ;
24+ import cn from " clsx" ;
2525// flexsearch types are incorrect, they were overwritten in tsconfig.json
26- import { Document } from ' flexsearch' ;
27- import { useRouter } from ' next/router' ;
28- import type { SearchData } from ' nextra' ;
29- import type { ReactElement , ReactNode } from ' react' ;
30- import { useCallback , useState } from ' react' ;
31- import ExternalIcon from ' ./ExternalIcon' ;
32- import { HighlightMatches } from ' ./HighlightMatches' ;
33- import { Search } from ' ./Search' ;
34- import { SearchResult } from ' ./types' ;
26+ import { Document } from " flexsearch" ;
27+ import { useRouter } from " next/router" ;
28+ import type { SearchData } from " nextra" ;
29+ import type { ReactElement , ReactNode } from " react" ;
30+ import { useCallback , useState } from " react" ;
31+ import ExternalIcon from " ./ExternalIcon" ;
32+ import { HighlightMatches } from " ./HighlightMatches" ;
33+ import { Search } from " ./Search" ;
34+ import { SearchResult } from " ./types" ;
3535
3636// Diff: Inlined definitions
37- export const DEFAULT_LOCALE = ' en-US' ;
37+ export const DEFAULT_LOCALE = " en-US" ;
3838
3939type SectionIndex = {
40- id : string ;
41- url : string ;
42- title : string ;
43- pageId : string ;
44- content : string ;
45- display ?: string ;
46- }
40+ id : string ;
41+ url : string ;
42+ title : string ;
43+ pageId : string ;
44+ content : string ;
45+ display ?: string ;
46+ } ;
4747
4848type PageIndex = {
49- id : number ;
50- title : string ;
51- content : string ;
52- }
49+ id : number ;
50+ title : string ;
51+ content : string ;
52+ } ;
5353
5454// Diff: Additional index for blog posts
55- type BlogIndex =
56- {
57- id : number ;
58- title : string ;
59- content : string ;
60- url : string ;
61- summary : string ;
62- }
55+ type BlogIndex = {
56+ id : number ;
57+ title : string ;
58+ content : string ;
59+ url : string ;
60+ summary : string ;
61+ } ;
6362
6463type Result = {
6564 _page_rk : number ;
@@ -71,26 +70,26 @@ type Result = {
7170
7271// This can be global for better caching.
7372const indexes : {
74- // tuple is PageIndex, SectionIndex
73+ // tuple is PageIndex, SectionIndex
7574 [ locale : string ] : [ Document , Document ] ;
7675} = { } ;
7776
7877// Diff: Index for blog posts
7978// Associated type is BlogIndex
8079const blogIndex = new Document ( {
8180 cache : 100 ,
82- tokenize : ' forward' ,
81+ tokenize : " forward" ,
8382 document : {
84- id : 'id' ,
85- index : ' content' ,
86- store : [ ' title' , ' url' , ' summary' ] ,
83+ id : "id" ,
84+ index : " content" ,
85+ store : [ " title" , " url" , " summary" ] ,
8786 } ,
8887} ) ;
8988
9089// Caches promises that load the index
9190const loadIndexesPromises = new Map < string , Promise < void > > ( ) ;
9291const loadIndexes = ( basePath : string , locale : string ) : Promise < void > => {
93- const key = basePath + '@' + locale ;
92+ const key = basePath + "@" + locale ;
9493 if ( loadIndexesPromises . has ( key ) ) {
9594 return loadIndexesPromises . get ( key ) ! ;
9695 }
@@ -101,16 +100,16 @@ const loadIndexes = (basePath: string, locale: string): Promise<void> => {
101100
102101// Diff: Function for loading blog posts
103102const loadBlogData = async ( basePath : string | undefined ) => {
104- const response = await fetch ( `${ basePath ?? '' } /feed.json` , {
105- cache : ' force-cache' ,
103+ const response = await fetch ( `${ basePath ?? "" } /feed.json` , {
104+ cache : " force-cache" ,
106105 } ) ;
107106 const content = await response . json ( ) ;
108107
109108 return content . items . map ( ( item , i ) => {
110109 return {
111110 id : i ,
112111 title : item . title ,
113- content : item [ ' content_html' ] ,
112+ content : item [ " content_html" ] ,
114113 url : item . url ,
115114 summary : item . summary ,
116115 } ;
@@ -119,10 +118,10 @@ const loadBlogData = async (basePath: string | undefined) => {
119118
120119const loadIndexesImpl = async (
121120 basePath : string ,
122- locale : string
121+ locale : string ,
123122) : Promise < void > => {
124123 const response = await fetch (
125- `${ basePath } /_next/static/chunks/nextra-data-${ locale } .json`
124+ `${ basePath } /_next/static/chunks/nextra-data-${ locale } .json` ,
126125 ) ;
127126 const searchData = ( await response . json ( ) ) as SearchData ;
128127 // Diff: Load blog data
@@ -131,11 +130,11 @@ const loadIndexesImpl = async (
131130 // Associated type is PageIndex
132131 const pageIndex = new Document ( {
133132 cache : 100 ,
134- tokenize : ' full' ,
133+ tokenize : " full" ,
135134 document : {
136- id : 'id' ,
137- index : ' content' ,
138- store : [ ' title' ] ,
135+ id : "id" ,
136+ index : " content" ,
137+ store : [ " title" ] ,
139138 } ,
140139 context : {
141140 resolution : 9 ,
@@ -147,12 +146,12 @@ const loadIndexesImpl = async (
147146 // Associated type is SectionIndex
148147 const sectionIndex = new Document ( {
149148 cache : 100 ,
150- tokenize : ' full' ,
149+ tokenize : " full" ,
151150 document : {
152- id : 'id' ,
153- index : ' content' ,
154- tag : ' pageId' ,
155- store : [ ' title' , ' content' , ' url' , ' display' ] ,
151+ id : "id" ,
152+ index : " content" ,
153+ tag : " pageId" ,
154+ store : [ " title" , " content" , " url" , " display" ] ,
156155 } ,
157156 context : {
158157 resolution : 9 ,
@@ -164,14 +163,14 @@ const loadIndexesImpl = async (
164163 let pageId = 0 ;
165164
166165 for ( const [ route , structurizedData ] of Object . entries ( searchData ) ) {
167- let pageContent = '' ;
166+ let pageContent = "" ;
168167 ++ pageId ;
169168
170169 for ( const [ key , content ] of Object . entries ( structurizedData . data ) ) {
171- const [ headingId , headingValue ] = key . split ( '#' ) ;
172- const url = route + ( headingId ? '#' + headingId : '' ) ;
170+ const [ headingId , headingValue ] = key . split ( "#" ) ;
171+ const url = route + ( headingId ? "#" + headingId : "" ) ;
173172 const title = headingValue || structurizedData . title ;
174- const paragraphs = content . split ( '\n' ) ;
173+ const paragraphs = content . split ( "\n" ) ;
175174
176175 sectionIndex . add ( {
177176 id : url ,
@@ -220,7 +219,7 @@ export function Flexsearch({
220219 const [ loading , setLoading ] = useState ( false ) ;
221220 const [ error , setError ] = useState ( false ) ;
222221 const [ results , setResults ] = useState < SearchResult [ ] > ( [ ] ) ;
223- const [ search , setSearch ] = useState ( '' ) ;
222+ const [ search , setSearch ] = useState ( "" ) ;
224223
225224 const doSearch = ( search : string ) => {
226225 if ( ! search ) return ;
@@ -260,17 +259,17 @@ export function Flexsearch({
260259 }
261260 const { url, title } = doc ;
262261 const content = doc . display || doc . content ;
263- if ( occurred [ url + '@' + content ] ) continue ;
264- occurred [ url + '@' + content ] = true ;
262+ if ( occurred [ url + "@" + content ] ) continue ;
263+ occurred [ url + "@" + content ] = true ;
265264 results . push ( {
266265 _page_rk : i ,
267266 _section_rk : j ,
268267 route : url ,
269268 prefix : isFirstItemOfPage && (
270269 < div
271270 className = { cn (
272- ' nx-mx-2.5 nx-mb-2 nx-mt-6 nx-select-none nx-border-b nx-border-black/10 nx-px-2.5 nx-pb-1.5 nx-text-xs nx-font-semibold nx-uppercase nx-text-gray-500 first:nx-mt-0 dark:nx-border-white/20 dark:nx-text-gray-300' ,
273- ' contrast-more:nx-border-gray-600 contrast-more:nx-text-gray-900 contrast-more:dark:nx-border-gray-50 contrast-more:dark:nx-text-gray-50'
271+ " nx-mx-2.5 nx-mb-2 nx-mt-6 nx-select-none nx-border-b nx-border-black/10 nx-px-2.5 nx-pb-1.5 nx-text-xs nx-font-semibold nx-uppercase nx-text-gray-500 first:nx-mt-0 dark:nx-border-white/20 dark:nx-text-gray-300" ,
272+ " contrast-more:nx-border-gray-600 contrast-more:nx-text-gray-900 contrast-more:dark:nx-border-gray-50 contrast-more:dark:nx-text-gray-50" ,
274273 ) }
275274 >
276275 { result . doc . title }
@@ -336,9 +335,9 @@ export function Flexsearch({
336335 prefix : (
337336 < div
338337 className = { cn (
339- ' nx-mx-2.5 nx-mb-2 nx-mt-6 nx-select-none nx-border-b nx-border-black/10 nx-px-2.5 nx-pb-1.5 nx-text-xs nx-font-semibold nx-uppercase nx-text-gray-500 first:nx-mt-0 dark:nx-border-white/20 dark:nx-text-gray-300' ,
340- ' contrast-more:nx-border-gray-600 contrast-more:nx-text-gray-900 contrast-more:dark:nx-border-gray-50 contrast-more:dark:nx-text-gray-50' ,
341- ' flex gap-1 items-center'
338+ " nx-mx-2.5 nx-mb-2 nx-mt-6 nx-select-none nx-border-b nx-border-black/10 nx-px-2.5 nx-pb-1.5 nx-text-xs nx-font-semibold nx-uppercase nx-text-gray-500 first:nx-mt-0 dark:nx-border-white/20 dark:nx-text-gray-300" ,
339+ " contrast-more:nx-border-gray-600 contrast-more:nx-text-gray-900 contrast-more:dark:nx-border-gray-50 contrast-more:dark:nx-text-gray-50" ,
340+ " flex gap-1 items-center" ,
342341 ) }
343342 >
344343 AuthZed Blog < ExternalIcon className = "h-4" />
@@ -374,7 +373,7 @@ export function Flexsearch({
374373 setLoading ( false ) ;
375374 }
376375 } ,
377- [ locale , basePath ]
376+ [ locale , basePath ] ,
378377 ) ;
379378
380379 const handleChange = async ( value : string ) => {
0 commit comments