1
- import { Drawing , YearDrawingSets , DayDrawingSets } from '../types'
1
+ import { Drawing , YearDrawingSets , DayDrawingSets , DayDrawingSetsByYear } from '../types'
2
2
3
3
export const drawingYears : number [ ] = [
4
4
2000 ,
@@ -24,22 +24,29 @@ export const yearDrawingSets: YearDrawingSets = drawingYears
24
24
. reverse ( )
25
25
. reduce ( ( accumulator , year ) => {
26
26
const rawYearSet = require ( `./drawings/${ year } .json` )
27
- const processedYearSet = rawYearSet . map ( ( drawing : any ) => {
27
+ const processedYearSet : Drawing [ ] = rawYearSet . map ( ( drawing : any ) => {
28
28
const [ year , number ] = drawing . id . split ( '.' )
29
29
return { ...drawing , year, number }
30
30
} )
31
- accumulator [ year ] = ( processedYearSet as Drawing [ ] ) . sort ( ( a , b ) => b . number - a . number )
31
+ accumulator [ year ] = processedYearSet . sort ( ( a , b ) => b . number - a . number )
32
32
return accumulator
33
- } , { } as Partial < YearDrawingSets > ) as YearDrawingSets
33
+ } , { } as any ) as YearDrawingSets
34
34
35
35
export const drawings : Drawing [ ] = drawingYears . reduce ( ( accumulator , year ) => {
36
36
return [ ...accumulator , ...yearDrawingSets [ year ] ] as Drawing [ ]
37
37
} , [ ] as Drawing [ ] )
38
38
39
39
export const dayDrawingSets : DayDrawingSets = drawings . reduce ( ( accumulator , drawing ) => {
40
40
if ( ! accumulator [ drawing . date ] ) accumulator [ drawing . date ] = [ ]
41
- accumulator [ drawing . date ] ! . push ( drawing )
41
+ accumulator [ drawing . date ] . push ( drawing )
42
42
return accumulator
43
- } , { } as Partial < DayDrawingSets > ) as DayDrawingSets
43
+ } , { } as any ) as DayDrawingSets
44
44
45
45
export const drawingDays : string [ ] = Object . keys ( dayDrawingSets ) . sort ( ) . reverse ( )
46
+
47
+ export const dayDrawingSetsByYear : DayDrawingSetsByYear = drawingDays . reduce ( ( accumulator , date ) => {
48
+ const year = parseInt ( date . slice ( 0 , 4 ) , 10 )
49
+ if ( ! accumulator [ year ] ) accumulator [ year ] = { }
50
+ accumulator [ year ] [ date ] = dayDrawingSets [ date ]
51
+ return accumulator
52
+ } , { } as any ) as DayDrawingSetsByYear
0 commit comments