@@ -2,21 +2,42 @@ import React from "react"
22import { Link , graphql } from "gatsby"
33import Layout from "@components/layout"
44import SEO from "@components/seo"
5+ import { groupBy , orderBy } from "es-toolkit/array"
56
6- const ProjectPage = ( { data } ) => {
7+ const BlogPage = ( { data } ) => {
78 const edges = data ?. allMarkdownRemark ?. edges ?? [ ]
9+
10+ const groups = groupBy ( edges , ( post ) => {
11+ const rawDate = post ?. node ?. frontmatter ?. date
12+ const year = rawDate ? new Date ( rawDate ) . getFullYear ( ) : NaN
13+ return Number . isFinite ( year ) ? String ( year ) : "Unknown"
14+ } )
15+
16+ const yearGroups = orderBy (
17+ Object . entries ( groups ) ,
18+ [ ( [ year ] ) => ( year === "Unknown" ? - Infinity : Number ( year ) ) ] ,
19+ [ "desc" ]
20+ )
21+
822 return (
923 < Layout >
1024 < SEO title = "Blog" />
11- < ul >
12- { edges . map ( ( post ) => (
13- < li key = { post . node . id } className = "project-list" >
14- < Link to = { post . node . frontmatter . path } >
15- < h2 > { post . node . frontmatter . title } </ h2 >
16- </ Link >
17- </ li >
25+ < div className = "blog-list" >
26+ { yearGroups . map ( ( [ year , posts ] ) => (
27+ < section key = { year } className = "year-group" >
28+ < h2 className = "year" > { year } </ h2 >
29+ < ul className = "year-list" >
30+ { posts . map ( ( { node } ) => (
31+ < li key = { node . id } className = "year-item" >
32+ < Link to = { node . frontmatter . path } >
33+ { node . frontmatter . title }
34+ </ Link >
35+ </ li >
36+ ) ) }
37+ </ ul >
38+ </ section >
1839 ) ) }
19- </ ul >
40+ </ div >
2041 </ Layout >
2142 )
2243}
@@ -30,7 +51,6 @@ export const pageQuery = graphql`
3051 edges {
3152 node {
3253 id
33- excerpt(pruneLength: 250)
3454 frontmatter {
3555 path
3656 title
@@ -43,4 +63,4 @@ export const pageQuery = graphql`
4363 }
4464`
4565
46- export default ProjectPage
66+ export default BlogPage
0 commit comments