Skip to content

Commit

Permalink
Merge pull request #12054 from guardian/sort-tag-pages-by-timestamp
Browse files Browse the repository at this point in the history
Sort tag pages by `webPublicationDate`
  • Loading branch information
DanielCliftonGuardian authored Aug 2, 2024
2 parents cfd330a + 8e632bb commit 34a5fe2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion dotcom-rendering/src/model/groupTrailsByDates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,19 @@ export const groupTrailsByDates = (
.sort((a, b) => b.epoch - a.epoch)
.map(({ groupedTrail }) => groupedTrail);

return sortedGroupedTrails;
const sortedGroupedTrailsByTime = sortedGroupedTrails.map(
(groupedTrail) => {
groupedTrail.trails.sort((a, b) => {
if (b.webPublicationDate && a.webPublicationDate) {
return (
new Date(b.webPublicationDate).getTime() -
new Date(a.webPublicationDate).getTime()
);
}
return 0;
});
return groupedTrail;
},
);
return sortedGroupedTrailsByTime;
};

0 comments on commit 34a5fe2

Please sign in to comment.