Format dates and sort archive posts descending by date
This commit is contained in:
@@ -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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user