aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/blog/index.tsx
blob: 70579822ca85470fd2747b618b1c187036952931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;