diff --git a/src/pages/news/index.tsx b/src/pages/news/index.tsx index 795a5ac..6f6c131 100644 --- a/src/pages/news/index.tsx +++ b/src/pages/news/index.tsx @@ -9,6 +9,7 @@ import { getPostsPreview } from "graphql/operations"; import { GetPostsPreviewQuery } from "graphql/operations-types"; import { GetStaticPropsContext } from "next"; import { AppStaticProps, getAppStaticProps } from "queries/getAppStaticProps"; +import { prettyDate } from "queries/helpers"; interface NewsProps extends AppStaticProps { posts: GetPostsPreviewQuery["posts"]["data"]; @@ -16,6 +17,17 @@ interface NewsProps extends AppStaticProps { export default function News(props: NewsProps): JSX.Element { const { langui, posts } = props; + + posts + .sort((a, b) => { + const dateA = + a.attributes.date === null ? "9999" : prettyDate(a.attributes.date); + const dateB = + b.attributes.date === null ? "9999" : prettyDate(b.attributes.date); + return dateA.localeCompare(dateB); + }) + .reverse(); + const subPanel = (