@@ -138,9 +138,9 @@ const Dictionary: React.FC = () => {
138
138
modes . push ( item ) ;
139
139
} else if ( item && typeof item === 'object' ) {
140
140
const s = ( item as any ) . sourceLanguage ;
141
- const t = ( item as any ) . targetLanguage ;
142
- if ( typeof s === 'string' && typeof t === 'string' ) {
143
- modes . push ( `${ s } |${ t } ` ) ;
141
+ const tLang = ( item as any ) . targetLanguage ;
142
+ if ( typeof s === 'string' && typeof tLang === 'string' ) {
143
+ modes . push ( `${ s } |${ tLang } ` ) ;
144
144
}
145
145
}
146
146
} ) ;
@@ -152,9 +152,9 @@ const Dictionary: React.FC = () => {
152
152
modes . push ( item ) ;
153
153
} else if ( item && typeof item === 'object' ) {
154
154
const s = ( item as any ) . sourceLanguage ;
155
- const t = ( item as any ) . targetLanguage ;
156
- if ( typeof s === 'string' && typeof t === 'string' ) {
157
- modes . push ( `${ s } |${ t } ` ) ;
155
+ const tLang = ( item as any ) . targetLanguage ;
156
+ if ( typeof s === 'string' && typeof tLang === 'string' ) {
157
+ modes . push ( `${ s } |${ tLang } ` ) ;
158
158
}
159
159
}
160
160
} ) ;
@@ -278,9 +278,19 @@ const Dictionary: React.FC = () => {
278
278
279
279
const parse = ( resp : any ) : Entry [ ] => {
280
280
const raw = resp . data . responseData ?. lookupResults ?? resp . data . responseData ?. searchResults ?? [ ] ;
281
- return ( raw as Array < Record < string , string [ ] > > ) . flatMap ( ( o ) =>
282
- Object . entries ( o ) . map ( ( [ head , defs ] ) => ( { head, defs } ) ) ,
283
- ) ;
281
+ return ( raw as Array < Record < string , any > > ) . flatMap ( ( o ) => {
282
+ const extraTagsArr : string [ ] = Array . isArray ( o [ 'extra-tags' ] ) ? o [ 'extra-tags' ] : [ ] ;
283
+ return Object . entries ( o )
284
+ . filter ( ( [ head ] ) => head !== 'extra-tags' )
285
+ . map (
286
+ ( [ head , defs ] ) =>
287
+ ( {
288
+ head,
289
+ defs,
290
+ extraTags : extraTagsArr ,
291
+ } as Entry ) ,
292
+ ) ;
293
+ } ) ;
284
294
} ;
285
295
286
296
try {
@@ -290,7 +300,7 @@ const Dictionary: React.FC = () => {
290
300
291
301
const reverseRaw = parse ( respRev ) ;
292
302
revParsed = reverseRaw . flatMap ( ( { head, defs } ) =>
293
- defs . map ( ( d ) => ( { head : d . replace ( / ^ \s * \d + \. \s * / , '' ) , defs : [ head ] } ) ) ,
303
+ defs . map ( ( d ) => ( { head : d . replace ( / ^ \s * \d + \. \s * / , '' ) , defs : [ head ] } as Entry ) ) ,
294
304
) ;
295
305
const uniqueHeads = Array . from ( new Set ( revParsed . map ( ( r ) => r . head ) ) ) ;
296
306
const headResponses = await Promise . all (
@@ -306,7 +316,7 @@ const Dictionary: React.FC = () => {
306
316
) ,
307
317
) ;
308
318
} ) ;
309
- setReverseResults ( uniqueHeads . map ( ( h ) => ( { head : h , defs : enriched [ h ] } ) ) ) ;
319
+ setReverseResults ( uniqueHeads . map ( ( h ) => ( { head : h , defs : enriched [ h ] } as Entry ) ) ) ;
310
320
311
321
const cleanedWord = rawWord
312
322
. replace ( / < [ ^ > ] + > / g, '' )
@@ -411,8 +421,17 @@ const Dictionary: React.FC = () => {
411
421
try {
412
422
const resp = await bsReq ;
413
423
const raw = resp . data . responseData ?. searchResults ?? [ ] ;
414
- const parsed = ( raw as Array < Record < string , string [ ] > > ) . flatMap ( ( o ) =>
415
- Object . entries ( o ) . map ( ( [ hd , defs ] ) => ( { head : hd , defs } ) ) ,
424
+ const parsed = ( raw as Array < Record < string , any > > ) . flatMap ( ( o ) =>
425
+ Object . entries ( o )
426
+ . filter ( ( [ head ] ) => head !== 'extra-tags' )
427
+ . map (
428
+ ( [ hd , defs ] ) =>
429
+ ( {
430
+ head : hd ,
431
+ defs,
432
+ extraTags : Array . isArray ( o [ 'extra-tags' ] ) ? o [ 'extra-tags' ] : [ ] ,
433
+ } as Entry ) ,
434
+ ) ,
416
435
) ;
417
436
bilsearchParsed [ mode ] [ sim ] = parsed ;
418
437
} catch {
@@ -534,8 +553,17 @@ const Dictionary: React.FC = () => {
534
553
try {
535
554
const resp = await bsReq ;
536
555
const raw = resp . data . responseData ?. searchResults ?? [ ] ;
537
- const parsed = ( raw as Array < Record < string , string [ ] > > ) . flatMap ( ( o ) =>
538
- Object . entries ( o ) . map ( ( [ hd , defs ] ) => ( { head : hd , defs } ) ) ,
556
+ const parsed = ( raw as Array < Record < string , any > > ) . flatMap ( ( o ) =>
557
+ Object . entries ( o )
558
+ . filter ( ( [ head ] ) => head !== 'extra-tags' )
559
+ . map (
560
+ ( [ hd , defs ] ) =>
561
+ ( {
562
+ head : hd ,
563
+ defs,
564
+ extraTags : Array . isArray ( o [ 'extra-tags' ] ) ? o [ 'extra-tags' ] : [ ] ,
565
+ } as Entry ) ,
566
+ ) ,
539
567
) ;
540
568
bilsearchParsed [ mode ] [ sim ] = parsed ;
541
569
} catch {
@@ -596,11 +624,7 @@ const Dictionary: React.FC = () => {
596
624
) ;
597
625
598
626
const grouped : Record < string , Entry [ ] > = React . useMemo ( ( ) => {
599
- const all : Entry [ ] = [
600
- ...results . map ( ( r ) => ( { head : r . head , defs : r . defs } ) ) ,
601
- ...reverseResults . map ( ( r ) => ( { head : r . head , defs : r . defs } ) ) ,
602
- ...embeddingResults . map ( ( e ) => ( { head : e . head , defs : e . defs , similarTo : ( e as any ) . similarTo } ) ) ,
603
- ] ;
627
+ const all : Entry [ ] = [ ...results , ...reverseResults , ...embeddingResults ] ;
604
628
const map : Record < string , Entry [ ] > = { } ;
605
629
all . forEach ( ( e ) => {
606
630
const surface = e . head . replace ( / < [ ^ > ] + > / g, '' ) ;
@@ -609,6 +633,7 @@ const Dictionary: React.FC = () => {
609
633
head : e . head ,
610
634
defs : e . defs . map ( ( d ) => d . replace ( / < [ ^ > ] + > / g, '' ) ) ,
611
635
...( e . similarTo ? { similarTo : e . similarTo } : { } ) ,
636
+ ...( e . extraTags ? { extraTags : e . extraTags } : { } ) ,
612
637
} as Entry ) ;
613
638
} ) ;
614
639
return map ;
@@ -663,6 +688,7 @@ const Dictionary: React.FC = () => {
663
688
surface = { surface }
664
689
entries = { entries }
665
690
lang = { srcLang }
691
+ searchWord = { searchWord }
666
692
onDefinitionClick = { ( def ) => {
667
693
setSearchWord ( def ) ;
668
694
setSrcLang ( tgtLang ) ;
0 commit comments