@@ -7,17 +7,38 @@ interface Publication {
77 id : number ;
88 title : string ;
99 doi : string ;
10+ year : number ; // Add year field
1011}
1112
1213export default function Publications ( ) {
1314 const [ publications , setPublications ] = useState < Publication [ ] > ( [ ] ) ;
15+ const [ groupedPublications , setGroupedPublications ] = useState < { [ year : number ] : Publication [ ] } > ( { } ) ;
1416
1517 useEffect ( ( ) => {
1618 fetch ( "/data/publication.json" )
1719 . then ( ( response ) => response . json ( ) )
18- . then ( ( data ) => setPublications ( data ) ) ;
20+ . then ( ( data ) => {
21+ setPublications ( data ) ;
22+
23+ // Group publications by year
24+ const grouped = data . reduce ( ( acc : { [ year : number ] : Publication [ ] } , pub : Publication ) => {
25+ const year = pub . year ;
26+ if ( ! acc [ year ] ) {
27+ acc [ year ] = [ ] ;
28+ }
29+ acc [ year ] . push ( pub ) ;
30+ return acc ;
31+ } , { } ) ;
32+
33+ setGroupedPublications ( grouped ) ;
34+ } ) ;
1935 } , [ ] ) ;
2036
37+ // Get sorted years in descending order (newest first)
38+ const sortedYears = Object . keys ( groupedPublications )
39+ . map ( Number )
40+ . sort ( ( a , b ) => b - a ) ;
41+
2142 return (
2243 < >
2344 < div className = "flex flex-col w-full" >
@@ -30,16 +51,31 @@ export default function Publications() {
3051 < hr className = "border-t border-gray-600 w-11/12 md:w-3/4 mx-auto mb-8" />
3152 < div className = "flex flex-col w-full" >
3253 < div className = "flex flex-col w-11/12 md:w-3/4 mx-auto" >
33- < ul className = "list-disc pl-5 space-y-4" >
34- { publications . map ( ( publication ) => (
35- < li key = { publication . id } >
36- { publication . title } { " " }
37- < Link href = { publication . doi } target = "_blank" rel = "noopener noreferrer" className = "text-blue-500 hover:underline" >
38- (DOI)
39- </ Link >
40- </ li >
41- ) ) }
42- </ ul >
54+ { sortedYears . map ( ( year ) => (
55+ < div key = { year } className = "mb-8" >
56+ { /* Year sub-header */ }
57+ < h2 className = "text-xl md:text-2xl font-semibold mb-4 text-gray-800" >
58+ { year }
59+ </ h2 >
60+
61+ { /* Publications for this year */ }
62+ < ul className = "list-disc pl-5 space-y-4" >
63+ { groupedPublications [ year ] . map ( ( publication ) => (
64+ < li key = { publication . id } >
65+ { publication . title } { " " }
66+ < Link
67+ href = { publication . doi }
68+ target = "_blank"
69+ rel = "noopener noreferrer"
70+ className = "text-blue-500 hover:underline"
71+ >
72+ (DOI)
73+ </ Link >
74+ </ li >
75+ ) ) }
76+ </ ul >
77+ </ div >
78+ ) ) }
4379 </ div >
4480 </ div >
4581 </ >
0 commit comments