summaryrefslogtreecommitdiffstats
path: root/src/components/PostPreview/PostPreview.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-24 19:35:12 +0200
committerGitHub <noreply@github.com>2022-05-24 19:35:12 +0200
commitc85ab5ad43ccf52881ee224672c41ec30021cf48 (patch)
tree8058808d9bfca19383f120c46b34d99ff2f89f63 /src/components/PostPreview/PostPreview.tsx
parent52404177c07a2aab7fc894362fb3060dff2431a0 (diff)
parent11b9de44a4b2f305a6a484187805e429b2767118 (diff)
refactor: use storybook and atomic design (#16)
BREAKING CHANGE: rewrite most of the Typescript types, so the content format (the meta in particular) needs to be updated.
Diffstat (limited to 'src/components/PostPreview/PostPreview.tsx')
-rw-r--r--src/components/PostPreview/PostPreview.tsx120
1 files changed, 0 insertions, 120 deletions
diff --git a/src/components/PostPreview/PostPreview.tsx b/src/components/PostPreview/PostPreview.tsx
deleted file mode 100644
index 0b9e332..0000000
--- a/src/components/PostPreview/PostPreview.tsx
+++ /dev/null
@@ -1,120 +0,0 @@
-import { ButtonLink } from '@components/Buttons';
-import { ArrowIcon } from '@components/Icons';
-import PostMeta from '@components/PostMeta/PostMeta';
-import { TitleLevel } from '@ts/types/app';
-import { ArticleMeta, ArticlePreview } from '@ts/types/articles';
-import { settings } from '@utils/config';
-import Image from 'next/image';
-import Link from 'next/link';
-import { FormattedMessage } from 'react-intl';
-import { BlogPosting, WithContext } from 'schema-dts';
-import styles from './PostPreview.module.scss';
-import Script from 'next/script';
-
-const PostPreview = ({
- post,
- titleLevel,
-}: {
- post: ArticlePreview;
- titleLevel: TitleLevel;
-}) => {
- const TitleTag = `h${titleLevel}` as keyof JSX.IntrinsicElements;
- const {
- commentCount,
- dates,
- featuredImage,
- info,
- intro,
- slug,
- thematics,
- title,
- topics,
- } = post;
-
- const meta: ArticleMeta = {
- commentCount: commentCount ? commentCount : 0,
- dates: dates,
- readingTime: info.readingTime,
- thematics: thematics,
- topics: topics,
- wordsCount: info.wordsCount,
- };
-
- const publicationDate = new Date(dates.publication);
- const updateDate = new Date(dates.update);
-
- const schemaJsonLd: WithContext<BlogPosting> = {
- '@context': 'https://schema.org',
- '@type': 'BlogPosting',
- name: title,
- description: intro,
- articleBody: intro,
- author: { '@id': `${settings.url}/#branding` },
- commentCount: commentCount ? commentCount : 0,
- copyrightYear: publicationDate.getFullYear(),
- creator: { '@id': `${settings.url}/#branding` },
- dateCreated: publicationDate.toISOString(),
- dateModified: updateDate.toISOString(),
- datePublished: publicationDate.toISOString(),
- editor: { '@id': `${settings.url}/#branding` },
- headline: title,
- image: featuredImage?.sourceUrl,
- inLanguage: settings.locales.defaultLocale,
- isBasedOn: `${settings.url}/article/${slug}`,
- isPartOf: { '@id': `${settings.url}/blog` },
- license: 'https://creativecommons.org/licenses/by-sa/4.0/deed.fr',
- thumbnailUrl: featuredImage?.sourceUrl,
- };
-
- return (
- <>
- <Script
- id="schema-post-preview"
- type="application/ld+json"
- dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }}
- />
- <article className={styles.wrapper}>
- {featuredImage && Object.keys(featuredImage).length > 0 && (
- <div className={styles.cover}>
- <Image
- src={featuredImage.sourceUrl}
- alt={featuredImage.altText}
- layout="fill"
- objectFit="contain"
- />
- </div>
- )}
- <header className={styles.header}>
- <TitleTag className={styles.title}>
- <Link href={`/article/${slug}`}>
- <a>{title}</a>
- </Link>
- </TitleTag>
- </header>
- <div
- className={styles.body}
- dangerouslySetInnerHTML={{ __html: intro }}
- ></div>
- <footer className={styles.footer}>
- <ButtonLink target={`/article/${slug}`} position="left">
- <FormattedMessage
- defaultMessage="Read more<a11y> about {title}</a11y>"
- description="PostPreview: read more link"
- id="bkbrN7"
- values={{
- title,
- a11y: (chunks: string) => (
- <span className="screen-reader-text">{chunks}</span>
- ),
- }}
- />
- <ArrowIcon />
- </ButtonLink>
- </footer>
- <PostMeta meta={meta} />
- </article>
- </>
- );
-};
-
-export default PostPreview;