@@ -4,24 +4,22 @@ const allPosts = await getCollection("post");
44
55const { count } = Astro .props ;
66
7- function parseDate(dateStr ) {
8- const [month, day, year] = dateStr .split (" " );
9- return new Date (` ${month } ${parseInt (day )}, ${year } ` );
10- }
7+ const formatter = new Intl .DateTimeFormat (" en-US" , {
8+ month: " short" ,
9+ day: " numeric" ,
10+ year: " numeric" ,
11+ });
1112
1213const sortedPosts = allPosts
13- .map ((post ) => ({
14- ... post ,
15- date: parseDate (post .data .dateFormatted ),
16- }))
17- .sort ((a , b ) => b .date .getTime () - a .date .getTime ());
14+ .sort ((a , b ) => b .data .date .getTime () - a .data .date .getTime ());
1815
19- const postsLoop = sortedPosts .slice (0 , count ).map ((post ) => {
20- return {
21- ... (post .data || {}),
22- link: ` /post/${post .slug } ` ,
23- };
24- });
16+ const postsLoop = sortedPosts .slice (0 , count ).map ((post ) => ({
17+ title: post .data .title ,
18+ description: post .data .description ,
19+ dateISO: post .data .date .toISOString (),
20+ dateFormatted: formatter .format (post .data .date ),
21+ link: ` /post/${post .slug } ` ,
22+ }));
2523---
2624
2725{
@@ -85,7 +83,7 @@ const postsLoop = sortedPosts.slice(0, count).map((post) => {
8583 <span >{ post .description } </span >
8684 </p >
8785 <div class = " mt-2.5 text-xs font-medium text-neutral-800 dark:text-neutral-300" >
88- Posted on { post .dateFormatted }
86+ < time datetime = { post . dateISO } > Posted on { post .dateFormatted } </ time >
8987 </div >
9088 </div >
9189 </div >
0 commit comments