aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/cv.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-22 17:45:03 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-22 17:46:32 +0100
commit0ac690339083f01a0b12a74ec117eeccd055e932 (patch)
tree539ffee3b35b086a8c035e5abc916ab603fe0001 /src/pages/cv.tsx
parentd4045fbcbfa8208ec31539744417f315f1f6fad8 (diff)
refactor(components,pages): extract MDX components mapping from pages
Instead of repeating the overriding on each pages, we should define it in one place and reuse it in pages. By default it is not possible to override native HTML tags with MDX so I added a plugin in next config to allow it.
Diffstat (limited to 'src/pages/cv.tsx')
-rw-r--r--src/pages/cv.tsx108
1 files changed, 3 insertions, 105 deletions
diff --git a/src/pages/cv.tsx b/src/pages/cv.tsx
index fd19a83..edf267d 100644
--- a/src/pages/cv.tsx
+++ b/src/pages/cv.tsx
@@ -1,30 +1,24 @@
/* eslint-disable max-statements */
-import type { MDXComponents } from 'mdx/types';
import type { GetStaticProps } from 'next';
import Head from 'next/head';
import NextImage from 'next/image';
import { useRouter } from 'next/router';
import Script from 'next/script';
-import React, {
- type AnchorHTMLAttributes,
- type HTMLAttributes,
- type ReactNode,
-} from 'react';
+import React, { type ReactNode } from 'react';
import { useIntl } from 'react-intl';
import {
getLayout,
Heading,
ImageWidget,
Link,
- List,
SocialMediaWidget,
- ListItem,
Page,
PageHeader,
PageSidebar,
TocWidget,
PageBody,
} from '../components';
+import { mdxComponents } from '../components/mdx';
import CVContent, { data, meta } from '../content/pages/cv.mdx';
import type { NextPageWithLayout } from '../types';
import { CONFIG } from '../utils/config';
@@ -37,102 +31,6 @@ import {
import { loadTranslation } from '../utils/helpers/server';
import { useBreadcrumb, useHeadingsTree } from '../utils/hooks';
-const ExternalLink = ({
- children = '',
- href = '',
- ...props
-}: AnchorHTMLAttributes<HTMLAnchorElement>) => (
- <Link {...props} isExternal href={href}>
- {children}
- </Link>
-);
-
-const H1 = ({
- children = '',
- ...props
-}: HTMLAttributes<HTMLHeadingElement>) => (
- <Heading {...props} level={1}>
- {children}
- </Heading>
-);
-
-const H2 = ({
- children = '',
- ...props
-}: HTMLAttributes<HTMLHeadingElement>) => (
- <Heading {...props} level={2}>
- {children}
- </Heading>
-);
-
-const H3 = ({
- children = '',
- ...props
-}: HTMLAttributes<HTMLHeadingElement>) => (
- <Heading {...props} level={3}>
- {children}
- </Heading>
-);
-
-const H4 = ({
- children = '',
- ...props
-}: HTMLAttributes<HTMLHeadingElement>) => (
- <Heading {...props} level={4}>
- {children}
- </Heading>
-);
-
-const H5 = ({
- children = '',
- ...props
-}: HTMLAttributes<HTMLHeadingElement>) => (
- <Heading {...props} level={5}>
- {children}
- </Heading>
-);
-
-const H6 = ({
- children = '',
- ...props
-}: HTMLAttributes<HTMLHeadingElement>) => (
- <Heading {...props} level={6}>
- {children}
- </Heading>
-);
-
-const OrderedList = ({
- children,
- ...props
-}: HTMLAttributes<HTMLUListElement>) => (
- <List {...props} isOrdered spacing="2xs">
- {children}
- </List>
-);
-
-const UnorderedList = ({
- children,
- ...props
-}: HTMLAttributes<HTMLUListElement>) => (
- <List {...props} spacing="2xs">
- {children}
- </List>
-);
-
-const components: MDXComponents = {
- a: ExternalLink,
- h1: H1,
- h2: H2,
- h3: H3,
- h4: H4,
- h5: H5,
- h6: H6,
- li: ({ ref, ...props }) => <ListItem {...props} />,
- Link,
- ol: OrderedList,
- ul: UnorderedList,
-};
-
/**
* CV page.
*/
@@ -258,7 +156,7 @@ const CVPage: NextPageWithLayout = () => {
/>
</PageSidebar>
<PageBody ref={ref}>
- <CVContent components={components} />
+ <CVContent components={mdxComponents} />
</PageBody>
<PageSidebar>
<ImageWidget