Format dates and sort archive posts descending by date

This commit is contained in:
2020-10-05 21:48:04 -05:00
parent de315b92d6
commit 11e571dc17

View File

@@ -11,10 +11,13 @@ export default function Archive({ data }) {
}); });
const yearGroupsHtml = yearGroups.map(yg => { const yearGroupsHtml = yearGroups.map(yg => {
yg.edges.sort(function(a,b) {
return new Date(b.node.frontmatter.date) - new Date(a.node.frontmatter.date);
});
const postListItems = yg.edges.map(({node}) => { const postListItems = yg.edges.map(({node}) => {
return ( return (
<li> <li>
<a href={node.fields.slug}>{node.frontmatter.date} - {node.frontmatter.title}</a> <a href={node.fields.slug}>{node.frontmatter.shortDate} - {node.frontmatter.title}</a>
</li> </li>
); );
}); });
@@ -48,7 +51,8 @@ export const query = graphql`
} }
frontmatter { frontmatter {
title title
date(formatString: "MMM Do") date
shortDate: date(formatString: "MM/DD")
} }
} }
} }