aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/index.tsx
blob: 291d011e9d55c39671a0bb2405bde4bacb000b2d (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
import { MDXComponents } from 'mdx/types';
import { GetStaticProps } from 'next';
import Head from 'next/head';
import Script from 'next/script';
import { ReactElement } from 'react';
import { useIntl } from 'react-intl';
import FeedIcon from '../assets/images/icon-feed.svg';
import ButtonLink from '../components/atoms/buttons/button-link';
import Envelop from '../components/atoms/icons/envelop';
import Column from '../components/atoms/layout/column';
import Section, { type SectionProps } from '../components/atoms/layout/section';
import List, { type ListItem } from '../components/atoms/lists/list';
import ResponsiveImage from '../components/molecules/images/responsive-image';
import Columns, {
  type ColumnsProps,
} from '../components/molecules/layout/columns';
import CardsList, {
  type CardsListItem,
} from '../components/organisms/layout/cards-list';
import { getLayout } from '../components/templates/layout/layout';
import HomePageContent from '../content/pages/homepage.mdx';
import { getArticlesCard } from '../services/graphql/articles';
import styles from '../styles/pages/home.module.scss';
import { type ArticleCard, type NextPageWithLayout } from '../types/app';
import { loadTranslation, type Messages } from '../utils/helpers/i18n';
import { getSchemaJson, getWebPageSchema } from '../utils/helpers/schema-org';
import useBreadcrumb from '../utils/hooks/use-breadcrumb';
import useSettings from '../utils/hooks/use-settings';

/**
 * Retrieve a list of coding links.
 *
 * @returns {JSX.Element} - A list of links.
 */
const CodingLinks = (): JSX.Element => {
  const intl = useIntl();
  const links: ListItem[] = [
    {
      id: 'web-development',
      value: (
        <ButtonLink target="/thematique/developpement-web">
          {intl.formatMessage({
            defaultMessage: 'Web development',
            description: 'HomePage: link to web development thematic',
            id: 'vkF/RP',
          })}
        </ButtonLink>
      ),
    },
    {
      id: 'projects',
      value: (
        <ButtonLink target="/projets">
          {intl.formatMessage({
            defaultMessage: 'Projects',
            description: 'HomePage: link to projects',
            id: 'N44SOc',
          })}
        </ButtonLink>
      ),
    },
  ];

  return <List kind="flex" items={links} className={styles.list} />;
};

/**
 * Retrieve a list of Coldark repositories.
 *
 * @returns {JSX.Element} - A list of links.
 */
const ColdarkRepos = (): JSX.Element => {
  const intl = useIntl();
  const links: ListItem[] = [
    {
      id: 'coldark-github',
      value: (
        <ButtonLink
          target="https://github.com/ArmandPhilippot/coldark"
          external={true}
        >
          {intl.formatMessage({
            defaultMessage: 'Github',
            description: 'HomePage: Github link',
            id: '3f3PzH',
          })}
        </ButtonLink>
      ),
    },
    {
      id: 'coldark-gitlab',
      value: (
        <ButtonLink
          target="https://gitlab.com/ArmandPhilippot/coldark"
          external={true}
        >
          {intl.formatMessage({
            defaultMessage: 'Gitlab',
            description: 'HomePage: Gitlab link',
            id: '7AnwZ7',
          })}
        </ButtonLink>
      ),
    },
  ];

  return <List kind="flex" items={links} className={styles.list} />;
};

/**
 * Retrieve a list of links related to Free thematic.
 *
 * @returns {JSX.Element} - A list of links.
 */
const LibreLinks = (): JSX.Element => {
  const intl = useIntl();
  const links: ListItem[] = [
    {
      id: 'free',
      value: (
        <ButtonLink target="/thematique/libre">
          {intl.formatMessage({
            defaultMessage: 'Free',
            description: 'HomePage: link to free thematic',
            id: 'w8GrOf',
          })}
        </ButtonLink>
      ),
    },
    {
      id: 'linux',
      value: (
        <ButtonLink target="/thematique/linux">
          {intl.formatMessage({
            defaultMessage: 'Linux',
            description: 'HomePage: link to Linux thematic',
            id: 'jASD7k',
          })}
        </ButtonLink>
      ),
    },
  ];

  return <List kind="flex" items={links} className={styles.list} />;
};

/**
 * Retrieve the Shaarli link.
 *
 * @returns {JSX.Element} - A list of links
 */
const ShaarliLink = (): JSX.Element => {
  const intl = useIntl();
  const links: ListItem[] = [
    {
      id: 'shaarli',
      value: (
        <ButtonLink target="https://shaarli.armandphilippot.com/">
          {intl.formatMessage({
            defaultMessage: 'Shaarli',
            description: 'HomePage: link to Shaarli',
            id: 'i5L19t',
          })}
        </ButtonLink>
      ),
    },
  ];

  return <List kind="flex" items={links} className={styles.list} />;
};

/**
 * Retrieve the additional links.
 *
 * @returns {JSX.Element} - A list of links.
 */
const MoreLinks = (): JSX.Element => {
  const intl = useIntl();
  const links: ListItem[] = [
    {
      id: 'contact-me',
      value: (
        <ButtonLink target="/contact">
          <Envelop aria-hidden={true} className={styles.icon} />
          {intl.formatMessage({
            defaultMessage: 'Contact me',
            description: 'HomePage: contact button text',
            id: 'sO/Iwj',
          })}
        </ButtonLink>
      ),
    },
    {
      id: 'rss-feed',
      value: (
        <ButtonLink target="/feed">
          <FeedIcon
            aria-hidden={true}
            className={`${styles.icon} ${styles['icon--feed']}`}
          />
          {intl.formatMessage({
            defaultMessage: 'Subscribe',
            description: 'HomePage: RSS feed subscription text',
            id: 'T4YA64',
          })}
        </ButtonLink>
      ),
    },
  ];

  return <List kind="flex" items={links} className={styles.list} />;
};

const StyledColumns = (props: ColumnsProps) => {
  return <Columns className={styles.columns} {...props} />;
};

type HomeProps = {
  recentPosts: ArticleCard[];
  translation?: Messages;
};

/**
 * Home page.
 */
const HomePage: NextPageWithLayout<HomeProps> = ({ recentPosts }) => {
  const intl = useIntl();
  const { schema: breadcrumbSchema } = useBreadcrumb({
    title: '',
    url: `/`,
  });

  /**
   * Get a cards list of recent posts.
   *
   * @returns {JSX.Element} - The cards list.
   */
  const getRecentPosts = (): JSX.Element => {
    const posts: CardsListItem[] = recentPosts.map((post) => {
      return {
        cover: post.cover,
        id: post.slug,
        meta: { publication: { date: post.dates.publication } },
        title: post.title,
        url: `/article/${post.slug}`,
      };
    });

    return (
      <CardsList
        items={posts}
        titleLevel={3}
        className={`${styles.list} ${styles['list--cards']}`}
      />
    );
  };

  /**
   * Create the page sections.
   *
   * @param {object} obj - An object containing the section body.
   * @param {ReactElement[]} obj.children - The section body.
   * @returns {JSX.Element} A section element.
   */
  const getSection = ({
    children,
    variant,
  }: {
    children: ReactElement[];
    variant: SectionProps['variant'];
  }): JSX.Element => {
    const [headingEl, ...content] = children;
    const title = headingEl.props.children;

    return (
      <Section
        title={title}
        content={content}
        variant={variant}
        className={styles.section}
      />
    );
  };

  const components: MDXComponents = {
    CodingLinks,
    ColdarkRepos,
    Column,
    Columns: StyledColumns,
    Image: ResponsiveImage,
    LibreLinks,
    MoreLinks,
    RecentPosts: getRecentPosts,
    Section: getSection,
    ShaarliLink,
  };

  const { website } = useSettings();

  const pageTitle = intl.formatMessage(
    {
      defaultMessage: '{websiteName} | Front-end developer: WordPress/React',
      description: 'HomePage: SEO - Page title',
      id: 'PXp2hv',
    },
    { websiteName: website.name }
  );
  const pageDescription = intl.formatMessage(
    {
      defaultMessage:
        '{websiteName} is a front-end developer located in France. He codes and he writes mostly about web development and open-source.',
      description: 'HomePage: SEO - Meta description',
      id: 'tMuNTy',
    },
    { websiteName: website.name }
  );
  const webpageSchema = getWebPageSchema({
    description: pageDescription,
    locale: website.locales.default,
    slug: '',
    title: pageTitle,
  });
  const schemaJsonLd = getSchemaJson([webpageSchema]);

  return (
    <>
      <Head>
        <title>{pageTitle}</title>
        <meta name="description" content={pageDescription} />
        <meta property="og:url" content={website.url} />
        <meta property="og:title" content={pageTitle} />
        <meta property="og:description" content={pageDescription} />
      </Head>
      <Script
        id="schema-homepage"
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }}
      />
      <Script
        id="schema-breadcrumb"
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(breadcrumbSchema) }}
      />
      <HomePageContent components={components} />
    </>
  );
};

HomePage.getLayout = (page) =>
  getLayout(page, { isHome: true, withExtraPadding: false });

export const getStaticProps: GetStaticProps<HomeProps> = async ({ locale }) => {
  const translation = await loadTranslation(locale);
  const recentPosts = await getArticlesCard({ first: 3 });

  return {
    props: {
      recentPosts,
      translation,
    },
  };
};

export default HomePage;