1- import { Drawing , YearDrawingSets , DayDrawingSets } from '../types'
1+ import { Drawing , YearDrawingSets , DayDrawingSets , DayDrawingSetsByYear } from '../types'
22
33export const drawingYears : number [ ] = [
44 2000 ,
@@ -24,22 +24,29 @@ export const yearDrawingSets: YearDrawingSets = drawingYears
2424 . reverse ( )
2525 . reduce ( ( accumulator , year ) => {
2626 const rawYearSet = require ( `./drawings/${ year } .json` )
27- const processedYearSet = rawYearSet . map ( ( drawing : any ) => {
27+ const processedYearSet : Drawing [ ] = rawYearSet . map ( ( drawing : any ) => {
2828 const [ year , number ] = drawing . id . split ( '.' )
2929 return { ...drawing , year, number }
3030 } )
31- accumulator [ year ] = ( processedYearSet as Drawing [ ] ) . sort ( ( a , b ) => b . number - a . number )
31+ accumulator [ year ] = processedYearSet . sort ( ( a , b ) => b . number - a . number )
3232 return accumulator
33- } , { } as Partial < YearDrawingSets > ) as YearDrawingSets
33+ } , { } as any ) as YearDrawingSets
3434
3535export const drawings : Drawing [ ] = drawingYears . reduce ( ( accumulator , year ) => {
3636 return [ ...accumulator , ...yearDrawingSets [ year ] ] as Drawing [ ]
3737} , [ ] as Drawing [ ] )
3838
3939export const dayDrawingSets : DayDrawingSets = drawings . reduce ( ( accumulator , drawing ) => {
4040 if ( ! accumulator [ drawing . date ] ) accumulator [ drawing . date ] = [ ]
41- accumulator [ drawing . date ] ! . push ( drawing )
41+ accumulator [ drawing . date ] . push ( drawing )
4242 return accumulator
43- } , { } as Partial < DayDrawingSets > ) as DayDrawingSets
43+ } , { } as any ) as DayDrawingSets
4444
4545export 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