From 0fa8ae55c52852c34c9143a6ec43c954c6404df1 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Wed, 15 Dec 2021 12:16:34 +0100
Subject: chore: retrieve posts list on blog page

---
 src/pages/blog/index.tsx | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 src/pages/blog/index.tsx

(limited to 'src/pages/blog/index.tsx')

diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx
new file mode 100644
index 0000000..7057982
--- /dev/null
+++ b/src/pages/blog/index.tsx
@@ -0,0 +1,48 @@
+import { ReactElement } from 'react';
+import { GetStaticProps } from 'next';
+import Head from 'next/head';
+import { t } from '@lingui/macro';
+import Layout from '@components/Layouts/Layout';
+import { seo } from '@config/seo';
+import { config } from '@config/website';
+import { getPublishedPosts } from '@services/graphql/blog';
+import { NextPageWithLayout } from '@ts/types/app';
+import { BlogPageProps } from '@ts/types/blog';
+import { loadTranslation } from '@utils/helpers/i18n';
+import PostsList from '@components/PostsList/PostsList';
+
+const Blog: NextPageWithLayout<BlogPageProps> = ({ data }) => {
+  const { posts, pageInfo } = data;
+
+  return (
+    <>
+      <Head>
+        <title>{seo.blog.title}</title>
+        <meta name="description" content={seo.blog.description} />
+      </Head>
+      <h1>{t`Blog`}</h1>
+      <PostsList posts={posts} titleLevel={2} />
+    </>
+  );
+};
+
+Blog.getLayout = function getLayout(page: ReactElement) {
+  return <Layout>{page}</Layout>;
+};
+
+export const getStaticProps: GetStaticProps = async (context) => {
+  const translation = await loadTranslation(
+    context.locale!,
+    process.env.NODE_ENV === 'production'
+  );
+  const data = await getPublishedPosts(config.postsPerPage);
+
+  return {
+    props: {
+      data,
+      translation,
+    },
+  };
+};
+
+export default Blog;
-- 
cgit v1.2.3

