@@ -3,14 +3,27 @@ import fs from 'fs';
3
3
import { useEffect , useState } from "react" ;
4
4
import { HOST , VALID_YEARS } from '../constants.js' ;
5
5
6
- const SAMPLE_REGEX = / \( y o u r p u z z l e i n p u t \) [ \s \S ] * ?< c o d e > ( [ \s \S ] + ?) < \/ c o d e > / ;
7
-
8
6
const decode = ( str : string ) => {
9
7
return str
10
8
. replaceAll ( '>' , '>' )
11
- . replaceAll ( '<' , '<' ) ;
9
+ . replaceAll ( '<' , '<' )
10
+ . replaceAll ( '<code>' , '' )
11
+ . replaceAll ( '</code>' , '' )
12
+ . replaceAll ( '<em>' , '' )
13
+ . replaceAll ( '</em>' , '' )
14
+ ;
12
15
} ;
13
16
17
+ const findLongest = ( str : string [ ] ) => {
18
+ let longest = ''
19
+ str . forEach ( ( s : string ) => {
20
+ if ( s . length > longest . length ) {
21
+ longest = s
22
+ }
23
+ } )
24
+ return longest
25
+ }
26
+
14
27
export const useInputFile = ( year : string , day : string , inp : string , ts : number ) : AppFile => {
15
28
const [ name , setName ] = useState < string > ( '' )
16
29
const [ size , setSize ] = useState < number > ( 0 )
@@ -56,9 +69,10 @@ export const useInputFile = (year: string, day: string, inp: string, ts: number)
56
69
}
57
70
} ) . then ( res => {
58
71
if ( res . data ) {
72
+ const SAMPLE_REGEX = / < c o d e > ( < e m > ) ? ( [ \s \S ] + ?) ( < \/ e m > ) ? < \/ c o d e > / g;
59
73
const matches = res . data . match ( SAMPLE_REGEX ) ;
60
74
if ( matches ) {
61
- fs . writeFileSync ( file , decode ( matches [ 1 ] ) . trim ( ) ) ;
75
+ fs . writeFileSync ( file , decode ( findLongest ( matches ) ) . trim ( ) ) ;
62
76
const stats = fs . statSync ( file )
63
77
setSize ( stats . size ) ;
64
78
}
0 commit comments