aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-23 14:07:02 +0200
committerArmand Philippot <git@armandphilippot.com>2022-05-23 16:00:13 +0200
commit34e216546151eaf8a0a3cbb0bc8b65dae4c63bf2 (patch)
treebff34f8a1dc65f0559ddf851433f242edb092824 /src
parent0f8f963ba3eccd7fd94785bf7fb216b6287cec57 (diff)
refactor: reduce the number of data transformation
Diffstat (limited to 'src')
-rw-r--r--src/components/molecules/layout/card.tsx22
-rw-r--r--src/components/organisms/layout/cards-list.tsx36
-rw-r--r--src/components/organisms/layout/comment.fixture.tsx41
-rw-r--r--src/components/organisms/layout/comment.stories.tsx28
-rw-r--r--src/components/organisms/layout/comment.test.tsx39
-rw-r--r--src/components/organisms/layout/comment.tsx98
-rw-r--r--src/components/organisms/layout/comments-list.fixture.tsx106
-rw-r--r--src/components/organisms/layout/comments-list.stories.tsx59
-rw-r--r--src/components/organisms/layout/comments-list.test.tsx64
-rw-r--r--src/components/organisms/layout/comments-list.tsx11
-rw-r--r--src/components/organisms/layout/posts-list.fixture.tsx61
-rw-r--r--src/components/organisms/layout/posts-list.stories.tsx64
-rw-r--r--src/components/organisms/layout/posts-list.test.tsx64
-rw-r--r--src/components/organisms/layout/posts-list.tsx4
-rw-r--r--src/components/organisms/layout/summary.fixture.tsx25
-rw-r--r--src/components/organisms/layout/summary.stories.tsx28
-rw-r--r--src/components/organisms/layout/summary.test.tsx44
-rw-r--r--src/components/organisms/layout/summary.tsx73
-rw-r--r--src/components/templates/page/page-layout.stories.tsx121
-rw-r--r--src/components/templates/page/page-layout.test.tsx13
-rw-r--r--src/pages/article/[slug].tsx43
-rw-r--r--src/pages/blog/index.tsx75
-rw-r--r--src/pages/blog/page/[number].tsx66
-rw-r--r--src/pages/projets/[slug].tsx14
-rw-r--r--src/pages/projets/index.tsx4
-rw-r--r--src/pages/recherche/index.tsx76
-rw-r--r--src/pages/sujet/[slug].tsx28
-rw-r--r--src/pages/thematique/[slug].tsx28
-rw-r--r--src/services/graphql/articles.query.ts7
-rw-r--r--src/services/graphql/articles.ts3
-rw-r--r--src/services/graphql/thematics.query.ts9
-rw-r--r--src/services/graphql/thematics.ts1
-rw-r--r--src/services/graphql/topics.query.ts9
-rw-r--r--src/services/graphql/topics.ts1
-rw-r--r--src/ts/types/app.ts5
-rw-r--r--src/ts/types/mdx.ts5
-rw-r--r--src/ts/types/raw-data.ts3
-rw-r--r--src/utils/helpers/pages.ts49
38 files changed, 456 insertions, 971 deletions
diff --git a/src/components/molecules/layout/card.tsx b/src/components/molecules/layout/card.tsx
index e465f76..68e364a 100644
--- a/src/components/molecules/layout/card.tsx
+++ b/src/components/molecules/layout/card.tsx
@@ -1,5 +1,6 @@
import ButtonLink from '@components/atoms/buttons/button-link';
import Heading, { type HeadingLevel } from '@components/atoms/headings/heading';
+import { type Image } from '@ts/types/app';
import { FC } from 'react';
import ResponsiveImage, {
type ResponsiveImageProps,
@@ -7,25 +8,6 @@ import ResponsiveImage, {
import styles from './card.module.scss';
import Meta, { type MetaData } from './meta';
-export type Cover = {
- /**
- * The cover alternative text.
- */
- alt: string;
- /**
- * The cover height.
- */
- height: number;
- /**
- * The cover source.
- */
- src: string;
- /**
- * The cover width.
- */
- width: number;
-};
-
export type CardProps = {
/**
* Set additional classnames to the card wrapper.
@@ -34,7 +16,7 @@ export type CardProps = {
/**
* The card cover.
*/
- cover?: Cover;
+ cover?: Image;
/**
* The cover fit. Default: cover.
*/
diff --git a/src/components/organisms/layout/cards-list.tsx b/src/components/organisms/layout/cards-list.tsx
index 0168bb2..1feddd0 100644
--- a/src/components/organisms/layout/cards-list.tsx
+++ b/src/components/organisms/layout/cards-list.tsx
@@ -10,32 +10,24 @@ export type CardsListItem = Omit<
CardProps,
'className' | 'coverFit' | 'titleLevel'
> & {
- id: string;
-};
-
-export type CardsListProps = {
- /**
- * Set additional classnames to the list wrapper.
- */
- className?: string;
- /**
- * The cover fit.
- */
- coverFit?: CardProps['coverFit'];
/**
- * The cards data.
+ * The card id.
*/
- items: CardsListItem[];
- /**
- * The list kind. Either ordered or unordered.
- */
- kind?: ListProps['kind'];
- /**
- * The title level (hn).
- */
- titleLevel: CardProps['titleLevel'];
+ id: string;
};
+export type CardsListProps = Pick<CardProps, 'coverFit' | 'titleLevel'> &
+ Pick<ListProps, 'kind'> & {
+ /**
+ * Set additional classnames to the list wrapper.
+ */
+ className?: string;
+ /**
+ * The cards data.
+ */
+ items: CardsListItem[];
+ };
+
/**
* CardsList component
*
diff --git a/src/components/organisms/layout/comment.fixture.tsx b/src/components/organisms/layout/comment.fixture.tsx
new file mode 100644
index 0000000..0118139
--- /dev/null
+++ b/src/components/organisms/layout/comment.fixture.tsx
@@ -0,0 +1,41 @@
+import { getFormattedDate, getFormattedTime } from '@utils/helpers/dates';
+import { CommentProps } from './comment';
+
+export const author = {
+ avatar: {
+ alt: 'Author avatar',
+ height: 480,
+ src: 'http://placeimg.com/640/480',
+ width: 640,
+ },
+ name: 'Armand',
+ website: 'https://www.armandphilippot.com/',
+};
+
+export const content =
+ 'Harum aut cumque iure fugit neque sequi cupiditate repudiandae laudantium. Ratione aut assumenda qui illum voluptas accusamus quis officiis exercitationem. Consectetur est harum eius perspiciatis officiis nihil. Aut corporis minima debitis adipisci possimus debitis et.';
+
+export const date = '2021-04-03 23:04:24';
+
+export const meta = {
+ author,
+ date,
+};
+
+export const id = 5;
+
+export const saveComment = async () => {
+ /** Do nothing. */
+};
+
+export const data: CommentProps = {
+ approved: true,
+ content,
+ id,
+ meta,
+ parentId: 0,
+ saveComment,
+};
+
+export const formattedDate = getFormattedDate(date);
+export const formattedTime = getFormattedTime(date);
diff --git a/src/components/organisms/layout/comment.stories.tsx b/src/components/organisms/layout/comment.stories.tsx
index fa4bba9..7a8ac95 100644
--- a/src/components/organisms/layout/comment.stories.tsx
+++ b/src/components/organisms/layout/comment.stories.tsx
@@ -1,5 +1,6 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
import CommentComponent from './comment';
+import { data } from './comment.fixture';
const saveComment = async () => {
/** Do nothing. */
@@ -9,7 +10,7 @@ const saveComment = async () => {
* Comment - Storybook Meta
*/
export default {
- title: 'Organisms/Layout',
+ title: 'Organisms/Layout/Comment',
component: CommentComponent,
args: {
canReply: true,
@@ -110,17 +111,18 @@ const Template: ComponentStory<typeof CommentComponent> = (args) => (
);
/**
- * Layout Stories - Comment
+ * Layout Stories - Approved
*/
-export const Comment = Template.bind({});
-Comment.args = {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Armand',
- url: 'https://www.armandphilippot.com/',
- },
- content:
- 'Harum aut cumque iure fugit neque sequi cupiditate repudiandae laudantium. Ratione aut assumenda qui illum voluptas accusamus quis officiis exercitationem. Consectetur est harum eius perspiciatis officiis nihil. Aut corporis minima debitis adipisci possimus debitis et.',
- id: 2,
- publication: '2021-04-03 23:04:24',
+export const Approved = Template.bind({});
+Approved.args = {
+ ...data,
+};
+
+/**
+ * Layout Stories - Unapproved
+ */
+export const Unapproved = Template.bind({});
+Unapproved.args = {
+ ...data,
+ approved: false,
};
diff --git a/src/components/organisms/layout/comment.test.tsx b/src/components/organisms/layout/comment.test.tsx
index 02a51dc..490a52b 100644
--- a/src/components/organisms/layout/comment.test.tsx
+++ b/src/components/organisms/layout/comment.test.tsx
@@ -1,48 +1,31 @@
import { render, screen } from '@test-utils';
-import { getFormattedDate, getFormattedTime } from '@utils/helpers/dates';
import Comment from './comment';
-
-const author = {
- avatar: 'http://placeimg.com/640/480',
- name: 'Your name',
- url: 'https://www.example.test/',
-};
-const content =
- 'Harum aut cumque iure fugit neque sequi cupiditate repudiandae laudantium. Ratione aut assumenda qui illum voluptas accusamus quis officiis exercitationem. Consectetur est harum eius perspiciatis officiis nihil. Aut corporis minima debitis adipisci possimus debitis et.';
-const publication = '2021-04-03 23:04:24';
-const id = 5;
-const saveComment = async () => {
- /** Do nothing. */
-};
-const data = {
+import {
author,
- content,
+ data,
+ formattedDate,
+ formattedTime,
id,
- publication,
- saveComment,
-};
-
-const formattedDate = getFormattedDate(publication);
-const formattedTime = getFormattedTime(publication);
+} from './comment.fixture';
describe('Comment', () => {
it('renders an avatar', () => {
- render(<Comment {...data} />);
+ render(<Comment canReply={true} {...data} />);
expect(
screen.getByRole('img', { name: 'Your name avatar' })
).toBeInTheDocument();
});
it('renders the author website url', () => {
- render(<Comment {...data} />);
+ render(<Comment canReply={true} {...data} />);
expect(screen.getByRole('link', { name: author.name })).toHaveAttribute(
'href',
- author.url
+ author.website
);
});
it('renders a permalink to the comment', () => {
- render(<Comment {...data} />);
+ render(<Comment canReply={true} {...data} />);
expect(
screen.getByRole('link', {
name: `${formattedDate} at ${formattedTime}`,
@@ -51,12 +34,12 @@ describe('Comment', () => {
});
it('renders a reply button', () => {
- render(<Comment {...data} canReply={true} />);
+ render(<Comment canReply={true} {...data} />);
expect(screen.getByRole('button', { name: 'Reply' })).toBeInTheDocument();
});
it('does not render a reply button', () => {
- render(<Comment {...data} canReply={false} />);
+ render(<Comment canReply={false} {...data} />);
expect(
screen.queryByRole('button', { name: 'Reply' })
).not.toBeInTheDocument();
diff --git a/src/components/organisms/layout/comment.tsx b/src/components/organisms/layout/comment.tsx
index 6df393b..1dc2c71 100644
--- a/src/components/organisms/layout/comment.tsx
+++ b/src/components/organisms/layout/comment.tsx
@@ -1,6 +1,7 @@
import Button from '@components/atoms/buttons/button';
import Link from '@components/atoms/links/link';
import Meta from '@components/molecules/layout/meta';
+import { type Comment as CommentType } from '@ts/types/app';
import useSettings from '@utils/hooks/use-settings';
import Image from 'next/image';
import Script from 'next/script';
@@ -25,32 +26,16 @@ export type CommentAuthor = {
url?: string;
};
-export type CommentProps = Pick<CommentFormProps, 'Notice' | 'saveComment'> & {
- /**
- * The comment author data.
- */
- author: CommentAuthor;
- /**
- * Enable or disable the reply button. Default: true.
- */
- canReply?: boolean;
- /**
- * The comment body.
- */
- content: string;
- /**
- * The comment id.
- */
- id: number | string;
- /**
- * The comment parent id.
- */
- parentId?: number | string;
- /**
- * The comment date and time separated with a space.
- */
- publication: string;
-};
+export type CommentProps = Pick<
+ CommentType,
+ 'approved' | 'content' | 'id' | 'meta' | 'parentId'
+> &
+ Pick<CommentFormProps, 'Notice' | 'saveComment'> & {
+ /**
+ * Enable or disable the reply button. Default: true.
+ */
+ canReply?: boolean;
+ };
/**
* Comment component
@@ -58,19 +43,34 @@ export type CommentProps = Pick<CommentFormProps, 'Notice' | 'saveComment'> & {
* Render a single comment.
*/
const Comment: FC<CommentProps> = ({
- author,
+ approved,
canReply = true,
content,
id,
+ meta,
Notice,
parentId,
- publication,
saveComment,
...props
}) => {
const intl = useIntl();
+ const { website } = useSettings();
const [isReplying, setIsReplying] = useState<boolean>(false);
- const [publicationDate, publicationTime] = publication.split(' ');
+
+ if (!approved) {
+ return (
+ <div className={styles.wrapper}>
+ {intl.formatMessage({
+ defaultMessage: 'This comment is awaiting moderation...',
+ description: 'Comment: awaiting moderation',
+ id: '6a1Uo6',
+ })}
+ </div>
+ );
+ }
+
+ const { author, date } = meta;
+ const [publicationDate, publicationTime] = date.split(' ');
const avatarAltText = intl.formatMessage(
{
@@ -97,8 +97,6 @@ const Comment: FC<CommentProps> = ({
id: '2fD5CI',
});
- const { website } = useSettings();
-
const commentSchema: WithContext<CommentSchema> = {
'@context': 'https://schema.org',
'@id': `${website.url}/#comment-${id}`,
@@ -110,17 +108,17 @@ const Comment: FC<CommentProps> = ({
author: {
'@type': 'Person',
name: author.name,
- image: author.avatar,
- url: author.url,
+ image: author.avatar?.src,
+ url: author.website,
},
creator: {
'@type': 'Person',
name: author.name,
- image: author.avatar,
- url: author.url,
+ image: author.avatar?.src,
+ url: author.website,
},
- dateCreated: publication,
- datePublished: publication,
+ dateCreated: date,
+ datePublished: date,
text: content,
};
@@ -136,17 +134,19 @@ const Comment: FC<CommentProps> = ({
className={`${styles.wrapper} ${styles['wrapper--comment']}`}
>
<header className={styles.header}>
- <div className={styles.avatar}>
- <Image
- src={author.avatar}
- alt={avatarAltText}
- layout="fill"
- objectFit="cover"
- {...props}
- />
- </div>
- {author.url ? (
- <Link href={author.url} className={styles.author}>
+ {author.avatar && (
+ <div className={styles.avatar}>
+ <Image
+ src={author.avatar?.src}
+ alt={avatarAltText}
+ layout="fill"
+ objectFit="cover"
+ {...props}
+ />
+ </div>
+ )}
+ {author.website ? (
+ <Link href={author.website} className={styles.author}>
{author.name}
</Link>
) : (
@@ -181,7 +181,7 @@ const Comment: FC<CommentProps> = ({
{isReplying && (
<CommentForm
Notice={Notice}
- parentId={id as number}
+ parentId={id}
saveComment={saveComment}
title={formTitle}
className={`${styles.wrapper} ${styles['wrapper--form']}`}
diff --git a/src/components/organisms/layout/comments-list.fixture.tsx b/src/components/organisms/layout/comments-list.fixture.tsx
new file mode 100644
index 0000000..2618f77
--- /dev/null
+++ b/src/components/organisms/layout/comments-list.fixture.tsx
@@ -0,0 +1,106 @@
+import { Comment } from '@ts/types/app';
+
+export const comments: Comment[] = [
+ {
+ approved: true,
+ content:
+ 'Voluptas ducimus inventore. Libero ut et doloribus. Earum nostrum ab. Aliquam rem dolores omnis voluptate. Sunt aut ut et.',
+ id: 1,
+ meta: {
+ author: {
+ avatar: {
+ alt: 'Author 1 avatar',
+ height: 480,
+ src: 'http://placeimg.com/640/480',
+ width: 640,
+ },
+ name: 'Author 1',
+ },
+ date: '2021-04-03 18:04:11',
+ },
+ parentId: 0,
+ replies: [],
+ },
+ {
+ approved: true,
+ content:
+ 'Sit sed error quasi voluptatem velit voluptas aut. Aut debitis eveniet. Praesentium dolores quia voluptate vero quis dicta quasi vel. Aut voluptas accusantium ut aut quidem consectetur itaque laboriosam occaecati.',
+ id: 2,
+ meta: {
+ author: {
+ avatar: {
+ alt: 'Author 2 avatar',
+ height: 480,
+ src: 'http://placeimg.com/640/480',
+ width: 640,
+ },
+ name: 'Author 2',
+ website: '#',
+ },
+ date: '2021-04-03 23:30:20',
+ },
+ parentId: 0,
+ replies: [
+ {
+ approved: true,
+ content:
+ 'Vel ullam in porro tempore. Maiores quos quia magnam beatae nemo libero velit numquam. Sapiente aliquid cumque. Velit neque in adipisci aut assumenda voluptates earum. Autem esse autem provident in tempore. Aut distinctio dolor qui repellat et et adipisci velit aspernatur.',
+ id: 4,
+ meta: {
+ author: {
+ avatar: {
+ alt: 'Author 4 avatar',
+ height: 480,
+ src: 'http://placeimg.com/640/480',
+ width: 640,
+ },
+ name: 'Author 4',
+ },
+ date: '2021-04-03 23:04:24',
+ },
+ parentId: 2,
+ replies: [],
+ },
+ {
+ approved: true,
+ content:
+ 'Sed non omnis. Quam porro est. Quae tempore quae. Exercitationem eos non velit voluptatem velit voluptas iusto. Sit debitis qui ipsam quo asperiores numquam veniam praesentium ut.',
+ id: 5,
+ meta: {
+ author: {
+ avatar: {
+ alt: 'Author 1 avatar',
+ height: 480,
+ src: 'http://placeimg.com/640/480',
+ width: 640,
+ },
+ name: 'Author 1',
+ },
+ date: '2021-04-04 08:05:14',
+ },
+ parentId: 2,
+ replies: [],
+ },
+ ],
+ },
+ {
+ approved: false,
+ content:
+ 'Natus consequatur maiores aperiam dolore eius nesciunt ut qui et. Ab ea nobis est. Eaque dolor corrupti id aut. Impedit architecto autem qui neque rerum ab dicta dignissimos voluptates.',
+ id: 3,
+ meta: {
+ author: {
+ avatar: {
+ alt: 'Author 3',
+ height: 480,
+ src: 'http://placeimg.com/640/480',
+ width: 640,
+ },
+ name: 'Author 3',
+ },
+ date: '2021-09-13 13:24:54',
+ },
+ parentId: 0,
+ replies: [],
+ },
+];
diff --git a/src/components/organisms/layout/comments-list.stories.tsx b/src/components/organisms/layout/comments-list.stories.tsx
index 22cc9d9..5ed0f2a 100644
--- a/src/components/organisms/layout/comments-list.stories.tsx
+++ b/src/components/organisms/layout/comments-list.stories.tsx
@@ -1,5 +1,6 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
-import CommentsListComponent, { type Comment } from './comments-list';
+import CommentsListComponent from './comments-list';
+import { comments } from './comments-list.fixture';
const saveComment = async () => {
/** Do nothing. */
@@ -71,62 +72,6 @@ const Template: ComponentStory<typeof CommentsListComponent> = (args) => (
<CommentsListComponent {...args} />
);
-const comments: Comment[] = [
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 1',
- },
- content:
- 'Voluptas ducimus inventore. Libero ut et doloribus. Earum nostrum ab. Aliquam rem dolores omnis voluptate. Sunt aut ut et.',
- id: 1,
- publication: '2021-04-03 18:04:11',
- },
- {
- child: [
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 4',
- },
- content:
- 'Vel ullam in porro tempore. Maiores quos quia magnam beatae nemo libero velit numquam. Sapiente aliquid cumque. Velit neque in adipisci aut assumenda voluptates earum. Autem esse autem provident in tempore. Aut distinctio dolor qui repellat et et adipisci velit aspernatur.',
- id: 4,
- publication: '2021-04-03 23:04:24',
- },
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 1',
- },
- content:
- 'Sed non omnis. Quam porro est. Quae tempore quae. Exercitationem eos non velit voluptatem velit voluptas iusto. Sit debitis qui ipsam quo asperiores numquam veniam praesentium ut.',
- id: 5,
- publication: '2021-04-04 08:05:14',
- },
- ],
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 2',
- url: '#',
- },
- content:
- 'Sit sed error quasi voluptatem velit voluptas aut. Aut debitis eveniet. Praesentium dolores quia voluptate vero quis dicta quasi vel. Aut voluptas accusantium ut aut quidem consectetur itaque laboriosam occaecati.',
- id: 2,
- publication: '2021-04-03 23:30:20',
- },
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 3',
- },
- content:
- 'Natus consequatur maiores aperiam dolore eius nesciunt ut qui et. Ab ea nobis est. Eaque dolor corrupti id aut. Impedit architecto autem qui neque rerum ab dicta dignissimos voluptates.',
- id: 3,
- publication: '2021-09-13 13:24:54',
- },
-];
-
/**
* Layout Stories - Without child comments
*/
diff --git a/src/components/organisms/layout/comments-list.test.tsx b/src/components/organisms/layout/comments-list.test.tsx
index e135ec9..b0a2467 100644
--- a/src/components/organisms/layout/comments-list.test.tsx
+++ b/src/components/organisms/layout/comments-list.test.tsx
@@ -1,65 +1,7 @@
import { render } from '@test-utils';
-import CommentsList, { type Comment } from './comments-list';
-
-const comments: Comment[] = [
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 1',
- },
- content:
- 'Voluptas ducimus inventore. Libero ut et doloribus. Earum nostrum ab. Aliquam rem dolores omnis voluptate. Sunt aut ut et.',
- id: 1,
- publication: '2021-04-03 18:04:11',
- },
- {
- child: [
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 4',
- },
- content:
- 'Vel ullam in porro tempore. Maiores quos quia magnam beatae nemo libero velit numquam. Sapiente aliquid cumque. Velit neque in adipisci aut assumenda voluptates earum. Autem esse autem provident in tempore. Aut distinctio dolor qui repellat et et adipisci velit aspernatur.',
- id: 4,
- publication: '2021-04-03 23:04:24',
- },
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 1',
- },
- content:
- 'Sed non omnis. Quam porro est. Quae tempore quae. Exercitationem eos non velit voluptatem velit voluptas iusto. Sit debitis qui ipsam quo asperiores numquam veniam praesentium ut.',
- id: 5,
- publication: '2021-04-04 08:05:14',
- },
- ],
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 2',
- url: '#',
- },
- content:
- 'Sit sed error quasi voluptatem velit voluptas aut. Aut debitis eveniet. Praesentium dolores quia voluptate vero quis dicta quasi vel. Aut voluptas accusantium ut aut quidem consectetur itaque laboriosam occaecati.',
- id: 2,
- publication: '2021-04-03 23:30:20',
- },
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 3',
- },
- content:
- 'Natus consequatur maiores aperiam dolore eius nesciunt ut qui et. Ab ea nobis est. Eaque dolor corrupti id aut. Impedit architecto autem qui neque rerum ab dicta dignissimos voluptates.',
- id: 3,
- publication: '2021-05-13 13:24:54',
- },
-];
-
-const saveComment = async () => {
- /** Do nothing. */
-};
+import { saveComment } from './comment.fixture';
+import CommentsList from './comments-list';
+import { comments } from './comments-list.fixture';
describe('CommentsList', () => {
it('renders a comments list', () => {
diff --git a/src/components/organisms/layout/comments-list.tsx b/src/components/organisms/layout/comments-list.tsx
index f04354c..97eccb7 100644
--- a/src/components/organisms/layout/comments-list.tsx
+++ b/src/components/organisms/layout/comments-list.tsx
@@ -1,13 +1,10 @@
import SingleComment, {
type CommentProps,
} from '@components/organisms/layout/comment';
+import { Comment } from '@ts/types/app';
import { FC } from 'react';
import styles from './comments-list.module.scss';
-export type Comment = Omit<CommentProps, 'canReply' | 'saveComment'> & {
- child?: Comment[];
-};
-
export type CommentsListProps = Pick<CommentProps, 'Notice' | 'saveComment'> & {
/**
* An array of comments.
@@ -42,7 +39,7 @@ const CommentsList: FC<CommentsListProps> = ({
): JSX.Element[] => {
const isLastLevel = startLevel === depth;
- return commentsList.map(({ child, ...comment }) => (
+ return commentsList.map(({ replies, ...comment }) => (
<li key={comment.id} className={styles.item}>
<SingleComment
canReply={!isLastLevel}
@@ -50,8 +47,8 @@ const CommentsList: FC<CommentsListProps> = ({
saveComment={saveComment}
{...comment}
/>
- {child && !isLastLevel && (
- <ol className={styles.list}>{getItems(child, startLevel + 1)}</ol>
+ {replies && !isLastLevel && (
+ <ol className={styles.list}>{getItems(replies, startLevel + 1)}</ol>
)}
</li>
));
diff --git a/src/components/organisms/layout/posts-list.fixture.tsx b/src/components/organisms/layout/posts-list.fixture.tsx
new file mode 100644
index 0000000..b0afdf8
--- /dev/null
+++ b/src/components/organisms/layout/posts-list.fixture.tsx
@@ -0,0 +1,61 @@
+import { type Post } from './posts-list';
+
+export const introPost1 =
+ 'Esse et voluptas sapiente modi impedit unde et. Ducimus nulla ea impedit sit placeat nihil assumenda. Rem est fugiat amet quo hic. Corrupti fuga quod animi autem dolorem ullam corrupti vel aut.';
+
+export const introPost2 =
+ 'Illum quae asperiores quod aut necessitatibus itaque excepturi voluptas. Incidunt exercitationem ullam saepe alias consequatur sed. Quam veniam quaerat voluptatum earum quia quisquam fugiat sed perspiciatis. Et velit saepe est recusandae facilis eos eum ipsum.';
+
+export const introPost3 =
+ 'Sunt aperiam ut rem impedit dolor id sit. Reprehenderit ipsum iusto fugiat. Quaerat laboriosam magnam facilis. Totam sint aliquam voluptatem in quis laborum sunt eum. Enim aut debitis officiis porro iure quia nihil voluptas ipsum. Praesentium quis necessitatibus cumque quia qui velit quos dolorem.';
+
+export const cover = {
+ alt: 'cover',
+ height: 480,
+ src: 'http://placeimg.com/640/480',
+ width: 640,
+};
+
+export const posts: Post[] = [
+ {
+ intro: introPost1,
+ id: 'post-1',
+ meta: {
+ cover,
+ dates: { publication: '2022-02-26' },
+ wordsCount: introPost1.split(' ').length,
+ thematics: [
+ { id: 1, name: 'Cat 1', slug: '#' },
+ { id: 2, name: 'Cat 2', slug: '#' },
+ ],
+ commentsCount: 1,
+ },
+ title: 'Ratione velit fuga',
+ url: '#',
+ },
+ {
+ intro: introPost2,
+ id: 'post-2',
+ meta: {
+ dates: { publication: '2022-02-20' },
+ wordsCount: introPost2.split(' ').length,
+ thematics: [{ id: 2, name: 'Cat 2', slug: '#' }],
+ commentsCount: 0,
+ },
+ title: 'Debitis laudantium laudantium',
+ url: '#',
+ },
+ {
+ intro: introPost3,
+ id: 'post-3',
+ meta: {
+ cover,
+ dates: { publication: '2021-12-20' },
+ wordsCount: introPost3.split(' ').length,
+ thematics: [{ id: 1, name: 'Cat 1', slug: '#' }],
+ commentsCount: 3,
+ },
+ title: 'Quaerat ut corporis',
+ url: '#',
+ },
+];
diff --git a/src/components/organisms/layout/posts-list.stories.tsx b/src/components/organisms/layout/posts-list.stories.tsx
index 360d441..68e3dc0 100644
--- a/src/components/organisms/layout/posts-list.stories.tsx
+++ b/src/components/organisms/layout/posts-list.stories.tsx
@@ -1,5 +1,6 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
-import PostsList, { type Post } from './posts-list';
+import PostsList from './posts-list';
+import { posts } from './posts-list.fixture';
/**
* PostsList - Storybook Meta
@@ -154,67 +155,6 @@ const Template: ComponentStory<typeof PostsList> = (args) => (
<PostsList {...args} />
);
-const excerpt1 =
- 'Esse et voluptas sapiente modi impedit unde et. Ducimus nulla ea impedit sit placeat nihil assumenda. Rem est fugiat amet quo hic. Corrupti fuga quod animi autem dolorem ullam corrupti vel aut.';
-const excerpt2 =
- 'Illum quae asperiores quod aut necessitatibus itaque excepturi voluptas. Incidunt exercitationem ullam saepe alias consequatur sed. Quam veniam quaerat voluptatum earum quia quisquam fugiat sed perspiciatis. Et velit saepe est recusandae facilis eos eum ipsum.';
-const excerpt3 =
- 'Sunt aperiam ut rem impedit dolor id sit. Reprehenderit ipsum iusto fugiat. Quaerat laboriosam magnam facilis. Totam sint aliquam voluptatem in quis laborum sunt eum. Enim aut debitis officiis porro iure quia nihil voluptas ipsum. Praesentium quis necessitatibus cumque quia qui velit quos dolorem.';
-
-const posts: Post[] = [
- {
- excerpt: excerpt1,
- id: 'post-1',
- meta: {
- dates: { publication: '2022-02-26' },
- readingTime: { wordsCount: excerpt1.split(' ').length },
- thematics: [
- { id: 'cat-1', name: 'Cat 1', url: '#' },
- { id: 'cat-2', name: 'Cat 2', url: '#' },
- ],
- commentsCount: 1,
- },
- title: 'Ratione velit fuga',
- url: '#',
- cover: {
- alt: 'cover',
- height: 480,
- src: 'http://placeimg.com/640/480',
- width: 640,
- },
- },
- {
- excerpt: excerpt2,
- id: 'post-2',
- meta: {
- dates: { publication: '2022-02-20' },
- readingTime: { wordsCount: excerpt2.split(' ').length },
- thematics: [{ id: 'cat-2', name: 'Cat 2', url: '#' }],
- commentsCount: 0,
- },
- title: 'Debitis laudantium laudantium',
- url: '#',
- },
- {
- excerpt: excerpt3,
- id: 'post-3',
- meta: {
- dates: { publication: '2021-12-20' },
- readingTime: { wordsCount: excerpt3.split(' ').length },
- thematics: [{ id: 'cat-1', name: 'Cat 1', url: '#' }],
- commentsCount: 3,
- },
- title: 'Quaerat ut corporis',
- url: '#',
- cover: {
- alt: 'cover',
- height: 480,
- src: 'http://placeimg.com/640/480',
- width: 640,
- },
- },
-];
-
/**
* PostsList Stories - Default
*/
diff --git a/src/components/organisms/layout/posts-list.test.tsx b/src/components/organisms/layout/posts-list.test.tsx
index dfb9825..1bab466 100644
--- a/src/components/organisms/layout/posts-list.test.tsx
+++ b/src/components/organisms/layout/posts-list.test.tsx
@@ -1,66 +1,6 @@
import { render, screen } from '@test-utils';
-import PostsList, { Post } from './posts-list';
-
-const excerpt1 =
- 'Esse et voluptas sapiente modi impedit unde et. Ducimus nulla ea impedit sit placeat nihil assumenda. Rem est fugiat amet quo hic. Corrupti fuga quod animi autem dolorem ullam corrupti vel aut.';
-const excerpt2 =
- 'Illum quae asperiores quod aut necessitatibus itaque excepturi voluptas. Incidunt exercitationem ullam saepe alias consequatur sed. Quam veniam quaerat voluptatum earum quia quisquam fugiat sed perspiciatis. Et velit saepe est recusandae facilis eos eum ipsum.';
-const excerpt3 =
- 'Sunt aperiam ut rem impedit dolor id sit. Reprehenderit ipsum iusto fugiat. Quaerat laboriosam magnam facilis. Totam sint aliquam voluptatem in quis laborum sunt eum. Enim aut debitis officiis porro iure quia nihil voluptas ipsum. Praesentium quis necessitatibus cumque quia qui velit quos dolorem.';
-
-const posts: Post[] = [
- {
- excerpt: excerpt1,
- id: 'post-1',
- meta: {
- dates: { publication: '2022-02-26' },
- readingTime: { wordsCount: excerpt1.split(' ').length },
- thematics: [
- { id: 'cat-1', name: 'Cat 1', url: '#' },
- { id: 'cat-2', name: 'Cat 2', url: '#' },
- ],
- commentsCount: 1,
- },
- title: 'Ratione velit fuga',
- url: '#',
- cover: {
- alt: 'cover',
- height: 480,
- src: 'http://placeimg.com/640/480',
- width: 640,
- },
- },
- {
- excerpt: excerpt2,
- id: 'post-2',
- meta: {
- dates: { publication: '2022-02-20' },
- readingTime: { wordsCount: excerpt2.split(' ').length },
- thematics: [{ id: 'cat-2', name: 'Cat 2', url: '#' }],
- commentsCount: 0,
- },
- title: 'Debitis laudantium laudantium',
- url: '#',
- },
- {
- excerpt: excerpt3,
- id: 'post-3',
- meta: {
- dates: { publication: '2021-12-20' },
- readingTime: { wordsCount: excerpt3.split(' ').length },
- thematics: [{ id: 'cat-1', name: 'Cat 1', url: '#' }],
- commentsCount: 3,
- },
- title: 'Quaerat ut corporis',
- url: '#',
- cover: {
- alt: 'cover',
- height: 480,
- src: 'http://placeimg.com/640/480',
- width: 640,
- },
- },
-];
+import PostsList from './posts-list';
+import { posts } from './posts-list.fixture';
describe('PostsList', () => {
it('renders the correct number of posts', () => {
diff --git a/src/components/organisms/layout/posts-list.tsx b/src/components/organisms/layout/posts-list.tsx
index 608130e..91fc62d 100644
--- a/src/components/organisms/layout/posts-list.tsx
+++ b/src/components/organisms/layout/posts-list.tsx
@@ -3,7 +3,7 @@ import Heading, { type HeadingLevel } from '@components/atoms/headings/heading';
import ProgressBar from '@components/atoms/loaders/progress-bar';
import Spinner from '@components/atoms/loaders/spinner';
import Pagination, {
- PaginationProps,
+ type PaginationProps,
} from '@components/molecules/nav/pagination';
import useIsMounted from '@utils/hooks/use-is-mounted';
import useSettings from '@utils/hooks/use-settings';
@@ -12,7 +12,7 @@ import { useIntl } from 'react-intl';
import styles from './posts-list.module.scss';
import Summary, { type SummaryProps } from './summary';
-export type Post = SummaryProps & {
+export type Post = Omit<SummaryProps, 'titleLevel'> & {
/**
* The post id.
*/
diff --git a/src/components/organisms/layout/summary.fixture.tsx b/src/components/organisms/layout/summary.fixture.tsx
new file mode 100644
index 0000000..fbc46a5
--- /dev/null
+++ b/src/components/organisms/layout/summary.fixture.tsx
@@ -0,0 +1,25 @@
+import { type SummaryMeta } from './summary';
+
+export const cover = {
+ alt: 'A cover',
+ height: 480,
+ src: 'http://placeimg.com/640/480',
+ width: 640,
+};
+
+export const intro =
+ 'Perspiciatis quasi libero nemo non eligendi nam minima. Deleniti expedita tempore. Praesentium explicabo molestiae eaque consectetur vero. Quae nostrum quisquam similique. Ut hic est quas ut esse quisquam nobis.';
+
+export const meta: SummaryMeta = {
+ dates: { publication: '2022-04-11' },
+ wordsCount: intro.split(' ').length,
+ thematics: [
+ { id: 1, name: 'Cat 1', slug: '#' },
+ { id: 2, name: 'Cat 2', slug: '#' },
+ ],
+ commentsCount: 1,
+};
+
+export const title = 'Odio odit necessitatibus';
+
+export const url = '#';
diff --git a/src/components/organisms/layout/summary.stories.tsx b/src/components/organisms/layout/summary.stories.tsx
index 2512051..0b91e24 100644
--- a/src/components/organisms/layout/summary.stories.tsx
+++ b/src/components/organisms/layout/summary.stories.tsx
@@ -1,5 +1,6 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
import Summary from './summary';
+import { cover, intro, meta } from './summary.fixture';
/**
* Summary - Storybook Meta
@@ -83,32 +84,12 @@ const Template: ComponentStory<typeof Summary> = (args) => (
<Summary {...args} />
);
-const cover = {
- alt: 'A cover',
- height: 480,
- src: 'http://placeimg.com/640/480',
- width: 640,
-};
-
-const excerpt =
- 'Perspiciatis quasi libero nemo non eligendi nam minima. Deleniti expedita tempore. Praesentium explicabo molestiae eaque consectetur vero. Quae nostrum quisquam similique. Ut hic est quas ut esse quisquam nobis.';
-
-const meta = {
- dates: { publication: '2022-04-11' },
- readingTime: { wordsCount: excerpt.split(' ').length },
- thematics: [
- { id: 'cat-1', name: 'Cat 1', url: '#' },
- { id: 'cat-2', name: 'Cat 2', url: '#' },
- ],
- commentsCount: 1,
-};
-
/**
* Summary Stories - Default
*/
export const Default = Template.bind({});
Default.args = {
- excerpt,
+ intro,
meta,
title: 'Odio odit necessitatibus',
url: '#',
@@ -119,9 +100,8 @@ Default.args = {
*/
export const WithCover = Template.bind({});
WithCover.args = {
- cover,
- excerpt,
- meta,
+ intro,
+ meta: { ...meta, cover },
title: 'Odio odit necessitatibus',
url: '#',
};
diff --git a/src/components/organisms/layout/summary.test.tsx b/src/components/organisms/layout/summary.test.tsx
index 9e34254..7617c26 100644
--- a/src/components/organisms/layout/summary.test.tsx
+++ b/src/components/organisms/layout/summary.test.tsx
@@ -1,35 +1,12 @@
import { render, screen } from '@test-utils';
import Summary from './summary';
-
-const cover = {
- alt: 'A cover',
- height: 480,
- src: 'http://placeimg.com/640/480',
- width: 640,
-};
-
-const excerpt =
- 'Perspiciatis quasi libero nemo non eligendi nam minima. Deleniti expedita tempore. Praesentium explicabo molestiae eaque consectetur vero. Quae nostrum quisquam similique. Ut hic est quas ut esse quisquam nobis.';
-
-const meta = {
- dates: { publication: '2022-04-11' },
- readingTime: { wordsCount: excerpt.split(' ').length },
- thematics: [
- { id: 'cat-1', name: 'Cat 1', url: '#' },
- { id: 'cat-2', name: 'Cat 2', url: '#' },
- ],
- commentsCount: 1,
-};
-
-const title = 'Odio odit necessitatibus';
-
-const url = '#';
+import { cover, intro, meta, title, url } from './summary.fixture';
describe('Summary', () => {
it('renders a title wrapped in a h2 element', () => {
render(
<Summary
- excerpt={excerpt}
+ intro={intro}
meta={meta}
title={title}
titleLevel={2}
@@ -42,16 +19,15 @@ describe('Summary', () => {
});
it('renders an excerpt', () => {
- render(<Summary excerpt={excerpt} meta={meta} title={title} url={url} />);
- expect(screen.getByText(excerpt)).toBeInTheDocument();
+ render(<Summary intro={intro} meta={meta} title={title} url={url} />);
+ expect(screen.getByText(intro)).toBeInTheDocument();
});
it('renders a cover', () => {
render(
<Summary
- cover={cover}
- excerpt={excerpt}
- meta={meta}
+ intro={intro}
+ meta={{ ...meta, cover }}
title={title}
url={url}
/>
@@ -60,19 +36,19 @@ describe('Summary', () => {
});
it('renders a link to the full post', () => {
- render(<Summary excerpt={excerpt} meta={meta} title={title} url={url} />);
+ render(<Summary intro={intro} meta={meta} title={title} url={url} />);
expect(screen.getByRole('link', { name: title })).toBeInTheDocument();
});
it('renders a read more link', () => {
- render(<Summary excerpt={excerpt} meta={meta} title={title} url={url} />);
+ render(<Summary intro={intro} meta={meta} title={title} url={url} />);
expect(
screen.getByRole('link', { name: `Read more about ${title}` })
).toBeInTheDocument();
});
it('renders some meta', () => {
- render(<Summary excerpt={excerpt} meta={meta} title={title} url={url} />);
- expect(screen.getByText(meta.thematics[0].name)).toBeInTheDocument();
+ render(<Summary intro={intro} meta={meta} title={title} url={url} />);
+ expect(screen.getByText(meta.thematics![0].name)).toBeInTheDocument();
});
});
diff --git a/src/components/organisms/layout/summary.tsx b/src/components/organisms/layout/summary.tsx
index 3831c0c..ca51cd6 100644
--- a/src/components/organisms/layout/summary.tsx
+++ b/src/components/organisms/layout/summary.tsx
@@ -6,7 +6,7 @@ import ResponsiveImage, {
type ResponsiveImageProps,
} from '@components/molecules/images/responsive-image';
import Meta, { type MetaData } from '@components/molecules/layout/meta';
-import { type Dates } from '@ts/types/app';
+import { type Article, type Meta as MetaType } from '@ts/types/app';
import useReadingTime from '@utils/hooks/use-reading-time';
import { FC, ReactNode } from 'react';
import { useIntl } from 'react-intl';
@@ -17,44 +17,23 @@ export type Cover = Pick<
'alt' | 'src' | 'width' | 'height'
>;
-export type SummaryMetaLink = {
- id: number | string;
- name: string;
- url: string;
-};
-
-export type SummaryMetaReadingTime = {
- wordsCount: number;
- onlyMinutes?: boolean;
-};
-
-export type SummaryMeta = {
- author?: string;
- commentsCount?: number;
- dates: Dates;
- readingTime: SummaryMetaReadingTime;
- thematics?: SummaryMetaLink[];
- topics?: SummaryMetaLink[];
-};
+export type SummaryMeta = Pick<
+ MetaType<'article'>,
+ | 'author'
+ | 'commentsCount'
+ | 'cover'
+ | 'dates'
+ | 'thematics'
+ | 'topics'
+ | 'wordsCount'
+>;
-export type SummaryProps = {
+export type SummaryProps = Pick<Article, 'intro' | 'title'> & {
/**
- * The post cover.
- */
- cover?: Cover;
- /**
- * The post excerpt.
- */
- excerpt: string;
- /**
- * The post meta.
+ * The post metadata.
*/
meta: SummaryMeta;
/**
- * The post title.
- */
- title: string;
- /**
* The heading level (hn).
*/
titleLevel?: HeadingLevel;
@@ -70,8 +49,7 @@ export type SummaryProps = {
* Render a page summary.
*/
const Summary: FC<SummaryProps> = ({
- cover,
- excerpt,
+ intro,
meta,
title,
titleLevel = 2,
@@ -91,14 +69,13 @@ const Summary: FC<SummaryProps> = ({
),
}
);
- const { wordsCount, onlyMinutes } = meta.readingTime;
- const readingTime = useReadingTime(wordsCount, onlyMinutes);
-
- const getMeta = (data: SummaryMeta): MetaData => {
- const { author, commentsCount, dates, thematics, topics } = data;
+ const { author, commentsCount, cover, dates, thematics, topics, wordsCount } =
+ meta;
+ const readingTime = useReadingTime(wordsCount, true);
+ const getMeta = (): MetaData => {
return {
- author,
+ author: author?.name,
publication: { date: dates.publication },
update:
dates.update && dates.publication !== dates.update
@@ -106,12 +83,12 @@ const Summary: FC<SummaryProps> = ({
: undefined,
readingTime,
thematics: thematics?.map((thematic) => (
- <Link key={thematic.id} href={thematic.url}>
+ <Link key={thematic.id} href={thematic.slug}>
{thematic.name}
</Link>
)),
topics: topics?.map((topic) => (
- <Link key={topic.id} href={topic.url}>
+ <Link key={topic.id} href={topic.slug}>
{topic.name}
</Link>
)),
@@ -134,11 +111,7 @@ const Summary: FC<SummaryProps> = ({
</Link>
</header>
<div className={styles.body}>
- {typeof excerpt === 'string' ? (
- <div dangerouslySetInnerHTML={{ __html: excerpt }} />
- ) : (
- excerpt
- )}
+ <div dangerouslySetInnerHTML={{ __html: intro }} />
<ButtonLink target={url} className={styles['read-more']}>
<>
{readMore}
@@ -148,7 +121,7 @@ const Summary: FC<SummaryProps> = ({
</div>
<footer className={styles.footer}>
<Meta
- data={getMeta(meta)}
+ data={getMeta()}
layout="column"
itemsLayout="stacked"
withSeparator={false}
diff --git a/src/components/templates/page/page-layout.stories.tsx b/src/components/templates/page/page-layout.stories.tsx
index bc1d7b6..88e3785 100644
--- a/src/components/templates/page/page-layout.stories.tsx
+++ b/src/components/templates/page/page-layout.stories.tsx
@@ -1,7 +1,9 @@
import ButtonLink from '@components/atoms/buttons/button-link';
import Heading from '@components/atoms/headings/heading';
import Link from '@components/atoms/links/link';
+import { comments } from '@components/organisms/layout/comments-list.fixture';
import PostsList from '@components/organisms/layout/posts-list';
+import { posts } from '@components/organisms/layout/posts-list.fixture';
import LinksListWidget from '@components/organisms/widgets/links-list-widget';
import Sharing from '@components/organisms/widgets/sharing';
import { ComponentMeta, ComponentStory } from '@storybook/react';
@@ -267,62 +269,6 @@ const postBreadcrumb = [
{ id: 'post', url: '#', name: pageTitle },
];
-const comments = [
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 1',
- },
- content:
- 'Voluptas ducimus inventore. Libero ut et doloribus. Earum nostrum ab. Aliquam rem dolores omnis voluptate. Sunt aut ut et.',
- id: 1,
- publication: '2021-04-03 18:04:11',
- },
- {
- child: [
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 4',
- },
- content:
- 'Vel ullam in porro tempore. Maiores quos quia magnam beatae nemo libero velit numquam. Sapiente aliquid cumque. Velit neque in adipisci aut assumenda voluptates earum. Autem esse autem provident in tempore. Aut distinctio dolor qui repellat et et adipisci velit aspernatur.',
- id: 4,
- publication: '2021-04-03 23:04:24',
- },
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 1',
- },
- content:
- 'Sed non omnis. Quam porro est. Quae tempore quae. Exercitationem eos non velit voluptatem velit voluptas iusto. Sit debitis qui ipsam quo asperiores numquam veniam praesentium ut.',
- id: 5,
- publication: '2021-04-04 08:05:14',
- },
- ],
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 2',
- url: '#',
- },
- content:
- 'Sit sed error quasi voluptatem velit voluptas aut. Aut debitis eveniet. Praesentium dolores quia voluptate vero quis dicta quasi vel. Aut voluptas accusantium ut aut quidem consectetur itaque laboriosam occaecati.',
- id: 2,
- publication: '2021-04-03 23:30:20',
- },
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 3',
- },
- content:
- 'Natus consequatur maiores aperiam dolore eius nesciunt ut qui et. Ab ea nobis est. Eaque dolor corrupti id aut. Impedit architecto autem qui neque rerum ab dicta dignissimos voluptates.',
- id: 3,
- publication: '2021-09-13 13:24:54',
- },
-];
-
/**
* Page Layout Stories - Post
*/
@@ -393,7 +339,7 @@ Post.args = {
/>,
],
withToC: true,
- comments,
+ comments: comments,
allowComments: true,
};
@@ -402,67 +348,6 @@ const postsListBreadcrumb = [
{ id: 'blog', url: '#', name: 'Blog' },
];
-const excerpt1 =
- 'Esse et voluptas sapiente modi impedit unde et. Ducimus nulla ea impedit sit placeat nihil assumenda. Rem est fugiat amet quo hic. Corrupti fuga quod animi autem dolorem ullam corrupti vel aut.';
-const excerpt2 =
- 'Illum quae asperiores quod aut necessitatibus itaque excepturi voluptas. Incidunt exercitationem ullam saepe alias consequatur sed. Quam veniam quaerat voluptatum earum quia quisquam fugiat sed perspiciatis. Et velit saepe est recusandae facilis eos eum ipsum.';
-const excerpt3 =
- 'Sunt aperiam ut rem impedit dolor id sit. Reprehenderit ipsum iusto fugiat. Quaerat laboriosam magnam facilis. Totam sint aliquam voluptatem in quis laborum sunt eum. Enim aut debitis officiis porro iure quia nihil voluptas ipsum. Praesentium quis necessitatibus cumque quia qui velit quos dolorem.';
-
-const posts = [
- {
- excerpt: excerpt1,
- id: 'post-1',
- meta: {
- dates: { publication: '2022-02-26' },
- readingTime: { wordsCount: excerpt1.split(' ').length },
- thematics: [
- { id: 'cat-1', name: 'Cat 1', url: '#' },
- { id: 'cat-2', name: 'Cat 2', url: '#' },
- ],
- commentsCount: 1,
- },
- title: 'Ratione velit fuga',
- url: '#',
- cover: {
- alt: 'cover',
- height: 480,
- src: 'http://placeimg.com/640/480',
- width: 640,
- },
- },
- {
- excerpt: excerpt2,
- id: 'post-2',
- meta: {
- dates: { publication: '2022-02-20' },
- readingTime: { wordsCount: excerpt2.split(' ').length },
- thematics: [{ id: 'cat-2', name: 'Cat 2', url: '#' }],
- commentsCount: 0,
- },
- title: 'Debitis laudantium laudantium',
- url: '#',
- },
- {
- excerpt: excerpt3,
- id: 'post-3',
- meta: {
- dates: { publication: '2021-12-20' },
- readingTime: { wordsCount: excerpt3.split(' ').length },
- thematics: [{ id: 'cat-1', name: 'Cat 1', url: '#' }],
- commentsCount: 3,
- },
- title: 'Quaerat ut corporis',
- url: '#',
- cover: {
- alt: 'cover',
- height: 480,
- src: 'http://placeimg.com/640/480',
- width: 640,
- },
- },
-];
-
const blogCategories = [
{ name: 'Cat 1', url: '#' },
{
diff --git a/src/components/templates/page/page-layout.test.tsx b/src/components/templates/page/page-layout.test.tsx
index a0c8923..f2d07d7 100644
--- a/src/components/templates/page/page-layout.test.tsx
+++ b/src/components/templates/page/page-layout.test.tsx
@@ -1,3 +1,4 @@
+import { comments } from '@components/organisms/layout/comments-list.fixture';
import { render, screen } from '@test-utils';
import { BreadcrumbList } from 'schema-dts';
import PageLayout from './page-layout';
@@ -88,18 +89,6 @@ describe('PageLayout', () => {
});
it('renders the comments list', () => {
- const comments = [
- {
- author: {
- avatar: 'http://placeimg.com/640/480',
- name: 'Author 1',
- },
- content:
- 'Voluptas ducimus inventore. Libero ut et doloribus. Earum nostrum ab. Aliquam rem dolores omnis voluptate. Sunt aut ut et.',
- id: 1,
- publication: '2021-04-03 18:04:11',
- },
- ];
render(
<PageLayout
breadcrumb={breadcrumb}
diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx
index 812fffe..2878538 100644
--- a/src/pages/article/[slug].tsx
+++ b/src/pages/article/[slug].tsx
@@ -18,11 +18,8 @@ import {
type NextPageWithLayout,
} from '@ts/types/app';
import { loadTranslation, type Messages } from '@utils/helpers/i18n';
-import useAddClassName from '@utils/hooks/use-add-classname';
-import useAttributes from '@utils/hooks/use-attributes';
import useBreadcrumb from '@utils/hooks/use-breadcrumb';
import usePrism, { type OptionalPrismPlugin } from '@utils/hooks/use-prism';
-import useQuerySelectorAll from '@utils/hooks/use-query-selector-all';
import useReadingTime from '@utils/hooks/use-reading-time';
import useSettings from '@utils/hooks/use-settings';
import { GetStaticPaths, GetStaticProps } from 'next';
@@ -66,12 +63,15 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({
title,
url: `/article/${slug}`,
});
- const readingTime = useReadingTime(wordsCount || 0, true);
+ const readingTime = useReadingTime(wordsCount, true);
const headerMeta: PageLayoutProps['headerMeta'] = {
author: author?.name,
publication: { date: dates.publication },
- update: dates.update ? { date: dates.update } : undefined,
+ update:
+ dates.update && dates.publication !== dates.update
+ ? { date: dates.update }
+ : undefined,
readingTime,
thematics:
thematics &&
@@ -167,35 +167,6 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({
'@graph': [webpageSchema, blogSchema, blogPostSchema],
};
- /**
- * Convert the comments list to the right format.
- *
- * @param {Comment[]} list - The comments list.
- * @returns {PageLayoutProps['comments']} - The formatted comments list.
- */
- const getCommentsList = (list: Comment[]): PageLayoutProps['comments'] => {
- return list.map((comment) => {
- const {
- content: commentBody,
- id: commentId,
- meta: commentMeta,
- parentId,
- replies,
- } = comment;
- const { author: commentAuthor, date } = commentMeta;
- const { name, avatar, website: authorUrl } = commentAuthor;
-
- return {
- author: { name, avatar: avatar!.src, url: authorUrl },
- content: commentBody,
- id: commentId,
- publication: date,
- child: getCommentsList(replies),
- parentId,
- };
- });
- };
-
const prismPlugins: OptionalPrismPlugin[] = ['command-line', 'line-numbers'];
const { attributes, className } = usePrism({ plugins: prismPlugins });
const lineNumbersClassName = className
@@ -254,7 +225,7 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({
bodyClassName={styles.body}
breadcrumb={breadcrumbItems}
breadcrumbSchema={breadcrumbSchema}
- comments={data && getCommentsList(data)}
+ comments={data}
footerMeta={footerMeta}
headerMeta={headerMeta}
id={id as number}
@@ -314,7 +285,7 @@ export const getStaticPaths: GetStaticPaths = async () => {
return {
paths,
- fallback: true,
+ fallback: false,
};
};
diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx
index 90f56be..dd04fad 100644
--- a/src/pages/blog/index.tsx
+++ b/src/pages/blog/index.tsx
@@ -1,34 +1,27 @@
import Notice from '@components/atoms/layout/notice';
-import PostsList, { type Post } from '@components/organisms/layout/posts-list';
+import PostsList from '@components/organisms/layout/posts-list';
import LinksListWidget from '@components/organisms/widgets/links-list-widget';
import { getLayout } from '@components/templates/layout/layout';
import PageLayout from '@components/templates/page/page-layout';
import { type EdgesResponse } from '@services/graphql/api';
-import {
- getArticleFromRawData,
- getArticles,
- getTotalArticles,
-} from '@services/graphql/articles';
+import { getArticles, getTotalArticles } from '@services/graphql/articles';
import {
getThematicsPreview,
getTotalThematics,
} from '@services/graphql/thematics';
import { getTopicsPreview, getTotalTopics } from '@services/graphql/topics';
+import { type NextPageWithLayout } from '@ts/types/app';
import {
- type Article,
- type Meta,
- type NextPageWithLayout,
-} from '@ts/types/app';
-import {
- RawThematicPreview,
- RawTopicPreview,
type RawArticle,
+ type RawThematicPreview,
+ type RawTopicPreview,
} from '@ts/types/raw-data';
import { settings } from '@utils/config';
import { loadTranslation, type Messages } from '@utils/helpers/i18n';
import {
getLinksListItems,
getPageLinkFromRawData,
+ getPostsList,
} from '@utils/helpers/pages';
import useBreadcrumb from '@utils/hooks/use-breadcrumb';
import usePagination from '@utils/hooks/use-pagination';
@@ -119,62 +112,6 @@ const BlogPage: NextPageWithLayout<BlogPageProps> = ({
'@graph': [webpageSchema, blogSchema],
};
- /**
- * Retrieve the formatted meta.
- *
- * @param {Meta<'article'>} meta - The article meta.
- * @returns {Post['meta']} The formatted meta.
- */
- const getPostMeta = (meta: Meta<'article'>): Post['meta'] => {
- const { commentsCount, dates, thematics, wordsCount } = meta;
-
- return {
- commentsCount,
- dates,
- readingTime: { wordsCount: wordsCount || 0, onlyMinutes: true },
- thematics: thematics?.map((thematic) => {
- return { ...thematic, url: `/thematique/${thematic.slug}` };
- }),
- };
- };
-
- /**
- * Retrieve the formatted posts.
- *
- * @param {Article[]} posts - An array of articles.
- * @returns {Post[]} An array of formatted posts.
- */
- const getPosts = (posts: Article[]): Post[] => {
- return posts.map((post) => {
- return {
- ...post,
- cover: post.meta.cover,
- excerpt: post.intro,
- meta: getPostMeta(post.meta),
- url: `/article/${post.slug}`,
- };
- });
- };
-
- /**
- * Retrieve the posts list from raw data.
- *
- * @param {EdgesResponse<RawArticle>[]} rawData - The raw data.
- * @returns {Post[]} An array of posts.
- */
- const getPostsList = (rawData: EdgesResponse<RawArticle>[]): Post[] => {
- const articlesList: RawArticle[] = [];
- rawData.forEach((articleData) =>
- articleData.edges.forEach((edge) => {
- articlesList.push(edge.node);
- })
- );
-
- return getPosts(
- articlesList.map((article) => getArticleFromRawData(article))
- );
- };
-
const {
data,
error,
diff --git a/src/pages/blog/page/[number].tsx b/src/pages/blog/page/[number].tsx
index e8c93f7..8f50ddd 100644
--- a/src/pages/blog/page/[number].tsx
+++ b/src/pages/blog/page/[number].tsx
@@ -1,10 +1,9 @@
-import PostsList, { type Post } from '@components/organisms/layout/posts-list';
+import PostsList from '@components/organisms/layout/posts-list';
import LinksListWidget from '@components/organisms/widgets/links-list-widget';
import { getLayout } from '@components/templates/layout/layout';
import PageLayout from '@components/templates/page/page-layout';
import { type EdgesResponse } from '@services/graphql/api';
import {
- getArticleFromRawData,
getArticles,
getArticlesEndCursor,
getTotalArticles,
@@ -14,11 +13,7 @@ import {
getTotalThematics,
} from '@services/graphql/thematics';
import { getTopicsPreview, getTotalTopics } from '@services/graphql/topics';
-import {
- type Article,
- type Meta,
- type NextPageWithLayout,
-} from '@ts/types/app';
+import { type NextPageWithLayout } from '@ts/types/app';
import {
type RawArticle,
type RawThematicPreview,
@@ -29,6 +24,7 @@ import { loadTranslation, type Messages } from '@utils/helpers/i18n';
import {
getLinksListItems,
getPageLinkFromRawData,
+ getPostsList,
} from '@utils/helpers/pages';
import useBreadcrumb from '@utils/hooks/use-breadcrumb';
import useRedirection from '@utils/hooks/use-redirection';
@@ -131,62 +127,6 @@ const BlogPage: NextPageWithLayout<BlogPageProps> = ({
'@graph': [webpageSchema, blogSchema],
};
- /**
- * Retrieve the formatted meta.
- *
- * @param {Meta<'article'>} meta - The article meta.
- * @returns {Post['meta']} The formatted meta.
- */
- const getPostMeta = (meta: Meta<'article'>): Post['meta'] => {
- const { commentsCount, dates, thematics, wordsCount } = meta;
-
- return {
- commentsCount,
- dates,
- readingTime: { wordsCount: wordsCount || 0, onlyMinutes: true },
- thematics: thematics?.map((thematic) => {
- return { ...thematic, url: `/thematique/${thematic.slug}` };
- }),
- };
- };
-
- /**
- * Retrieve the formatted posts.
- *
- * @param {Article[]} posts - An array of articles.
- * @returns {Post[]} An array of formatted posts.
- */
- const getPosts = (posts: Article[]): Post[] => {
- return posts.map((post) => {
- return {
- ...post,
- cover: post.meta.cover,
- excerpt: post.intro,
- meta: getPostMeta(post.meta),
- url: `/article/${post.slug}`,
- };
- });
- };
-
- /**
- * Retrieve the posts list from raw data.
- *
- * @param {EdgesResponse<RawArticle>[]} rawData - The raw data.
- * @returns {Post[]} An array of posts.
- */
- const getPostsList = (rawData: EdgesResponse<RawArticle>[]): Post[] => {
- const articlesList: RawArticle[] = [];
- rawData.forEach((articleData) =>
- articleData.edges.forEach((edge) => {
- articlesList.push(edge.node);
- })
- );
-
- return getPosts(
- articlesList.map((article) => getArticleFromRawData(article))
- );
- };
-
const thematicsListTitle = intl.formatMessage({
defaultMessage: 'Thematics',
description: 'BlogPage: thematics list widget title',
diff --git a/src/pages/projets/[slug].tsx b/src/pages/projets/[slug].tsx
index e9b36fa..27c715d 100644
--- a/src/pages/projets/[slug].tsx
+++ b/src/pages/projets/[slug].tsx
@@ -1,14 +1,18 @@
import Link from '@components/atoms/links/link';
-import SocialLink, { SocialWebsite } from '@components/atoms/links/social-link';
+import SocialLink, {
+ type SocialWebsite,
+} from '@components/atoms/links/social-link';
import Spinner from '@components/atoms/loaders/spinner';
import ResponsiveImage from '@components/molecules/images/responsive-image';
import Code from '@components/molecules/layout/code';
import Gallery from '@components/organisms/images/gallery';
-import Overview, { OverviewMeta } from '@components/organisms/layout/overview';
+import Overview, {
+ type OverviewMeta,
+} from '@components/organisms/layout/overview';
import Sharing from '@components/organisms/widgets/sharing';
import { getLayout } from '@components/templates/layout/layout';
import PageLayout, {
- PageLayoutProps,
+ type PageLayoutProps,
} from '@components/templates/page/page-layout';
import styles from '@styles/pages/project.module.scss';
import {
@@ -16,11 +20,11 @@ import {
type ProjectPreview,
type Repos,
} from '@ts/types/app';
-import { loadTranslation, Messages } from '@utils/helpers/i18n';
+import { loadTranslation, type Messages } from '@utils/helpers/i18n';
import { getProjectData, getProjectFilenames } from '@utils/helpers/projects';
import { capitalize } from '@utils/helpers/strings';
import useBreadcrumb from '@utils/hooks/use-breadcrumb';
-import useGithubApi, { RepoData } from '@utils/hooks/use-github-api';
+import useGithubApi, { type RepoData } from '@utils/hooks/use-github-api';
import useSettings from '@utils/hooks/use-settings';
import { MDXComponents, NestedMDXComponents } from 'mdx/types';
import { GetStaticPaths, GetStaticProps } from 'next';
diff --git a/src/pages/projets/index.tsx b/src/pages/projets/index.tsx
index d500b6b..9ca289a 100644
--- a/src/pages/projets/index.tsx
+++ b/src/pages/projets/index.tsx
@@ -1,13 +1,13 @@
import Link from '@components/atoms/links/link';
import CardsList, {
- CardsListItem,
+ type CardsListItem,
} from '@components/organisms/layout/cards-list';
import { getLayout } from '@components/templates/layout/layout';
import PageLayout from '@components/templates/page/page-layout';
import PageContent, { meta } from '@content/pages/projects.mdx';
import styles from '@styles/pages/projects.module.scss';
import { type NextPageWithLayout, type ProjectCard } from '@ts/types/app';
-import { loadTranslation, Messages } from '@utils/helpers/i18n';
+import { loadTranslation, type Messages } from '@utils/helpers/i18n';
import { getProjectsCard } from '@utils/helpers/projects';
import useBreadcrumb from '@utils/hooks/use-breadcrumb';
import useSettings from '@utils/hooks/use-settings';
diff --git a/src/pages/recherche/index.tsx b/src/pages/recherche/index.tsx
index 8895015..c69d931 100644
--- a/src/pages/recherche/index.tsx
+++ b/src/pages/recherche/index.tsx
@@ -1,34 +1,26 @@
import Notice from '@components/atoms/layout/notice';
import Spinner from '@components/atoms/loaders/spinner';
-import PostsList, { type Post } from '@components/organisms/layout/posts-list';
+import PostsList from '@components/organisms/layout/posts-list';
import LinksListWidget from '@components/organisms/widgets/links-list-widget';
import { getLayout } from '@components/templates/layout/layout';
import PageLayout from '@components/templates/page/page-layout';
-import { type EdgesResponse } from '@services/graphql/api';
-import {
- getArticleFromRawData,
- getArticles,
- getTotalArticles,
-} from '@services/graphql/articles';
+import { getArticles, getTotalArticles } from '@services/graphql/articles';
import {
getThematicsPreview,
getTotalThematics,
} from '@services/graphql/thematics';
import { getTopicsPreview, getTotalTopics } from '@services/graphql/topics';
+import { type NextPageWithLayout } from '@ts/types/app';
import {
- type Article,
- type Meta,
- type NextPageWithLayout,
-} from '@ts/types/app';
-import {
- RawThematicPreview,
- RawTopicPreview,
type RawArticle,
+ type RawThematicPreview,
+ type RawTopicPreview,
} from '@ts/types/raw-data';
import { loadTranslation, type Messages } from '@utils/helpers/i18n';
import {
getLinksListItems,
getPageLinkFromRawData,
+ getPostsList,
} from '@utils/helpers/pages';
import useBreadcrumb from '@utils/hooks/use-breadcrumb';
import useDataFromAPI from '@utils/hooks/use-data-from-api';
@@ -146,62 +138,6 @@ const SearchPage: NextPageWithLayout<SearchPageProps> = ({
);
/**
- * Retrieve the formatted meta.
- *
- * @param {Meta<'article'>} meta - The article meta.
- * @returns {Post['meta']} The formatted meta.
- */
- const getPostMeta = (meta: Meta<'article'>): Post['meta'] => {
- const { commentsCount, dates, thematics, wordsCount } = meta;
-
- return {
- commentsCount,
- dates,
- readingTime: { wordsCount: wordsCount || 0, onlyMinutes: true },
- thematics: thematics?.map((thematic) => {
- return { ...thematic, url: `/thematique/${thematic.slug}` };
- }),
- };
- };
-
- /**
- * Retrieve the formatted posts.
- *
- * @param {Article[]} posts - An array of articles.
- * @returns {Post[]} An array of formatted posts.
- */
- const getPosts = (posts: Article[]): Post[] => {
- return posts.map((post) => {
- return {
- ...post,
- cover: post.meta.cover,
- excerpt: post.intro,
- meta: getPostMeta(post.meta),
- url: `/article/${post.slug}`,
- };
- });
- };
-
- /**
- * Retrieve the posts list from raw data.
- *
- * @param {EdgesResponse<RawArticle>[]} rawData - The raw data.
- * @returns {Post[]} An array of posts.
- */
- const getPostsList = (rawData: EdgesResponse<RawArticle>[]): Post[] => {
- const articlesList: RawArticle[] = [];
- rawData.forEach((articleData) =>
- articleData.edges.forEach((edge) => {
- articlesList.push(edge.node);
- })
- );
-
- return getPosts(
- articlesList.map((article) => getArticleFromRawData(article))
- );
- };
-
- /**
* Load more posts handler.
*/
const loadMore = () => {
diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx
index b4845eb..95843cd 100644
--- a/src/pages/sujet/[slug].tsx
+++ b/src/pages/sujet/[slug].tsx
@@ -1,6 +1,6 @@
import Heading from '@components/atoms/headings/heading';
import ResponsiveImage from '@components/molecules/images/responsive-image';
-import PostsList, { type Post } from '@components/organisms/layout/posts-list';
+import PostsList from '@components/organisms/layout/posts-list';
import LinksListWidget from '@components/organisms/widgets/links-list-widget';
import { getLayout } from '@components/templates/layout/layout';
import PageLayout, {
@@ -14,7 +14,6 @@ import {
} from '@services/graphql/topics';
import styles from '@styles/pages/topic.module.scss';
import {
- type Article,
type NextPageWithLayout,
type PageLink,
type Topic,
@@ -23,7 +22,7 @@ import { loadTranslation, type Messages } from '@utils/helpers/i18n';
import {
getLinksListItems,
getPageLinkFromRawData,
- getPostMeta,
+ getPostsWithUrl,
} from '@utils/helpers/pages';
import useBreadcrumb from '@utils/hooks/use-breadcrumb';
import useSettings from '@utils/hooks/use-settings';
@@ -109,27 +108,6 @@ const TopicPage: NextPageWithLayout<TopicPageProps> = ({
'@graph': [webpageSchema, articleSchema],
};
- const getPosts = (array: Article[]): Post[] => {
- return array.map((article) => {
- const {
- intro: articleIntro,
- meta: articleMeta,
- slug: articleSlug,
- ...remainingData
- } = article;
-
- const { cover: articleCover, ...remainingMeta } = articleMeta;
-
- return {
- cover: articleCover,
- excerpt: articleIntro,
- meta: getPostMeta(remainingMeta),
- url: `/article/${articleSlug}`,
- ...remainingData,
- };
- });
- };
-
const topicsListTitle = intl.formatMessage({
defaultMessage: 'Other topics',
description: 'TopicPage: other topics list widget title',
@@ -206,7 +184,7 @@ const TopicPage: NextPageWithLayout<TopicPageProps> = ({
</Heading>
<PostsList
baseUrl="/sujet/page/"
- posts={getPosts(articles)}
+ posts={getPostsWithUrl(articles)}
total={articles.length}
titleLevel={3}
byYear={true}
diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx
index ce4eccf..a91483e 100644
--- a/src/pages/thematique/[slug].tsx
+++ b/src/pages/thematique/[slug].tsx
@@ -1,5 +1,5 @@
import Heading from '@components/atoms/headings/heading';
-import PostsList, { type Post } from '@components/organisms/layout/posts-list';
+import PostsList from '@components/organisms/layout/posts-list';
import LinksListWidget from '@components/organisms/widgets/links-list-widget';
import { getLayout } from '@components/templates/layout/layout';
import PageLayout, {
@@ -12,7 +12,6 @@ import {
getTotalThematics,
} from '@services/graphql/thematics';
import {
- type Article,
type NextPageWithLayout,
type PageLink,
type Thematic,
@@ -21,7 +20,7 @@ import { loadTranslation, type Messages } from '@utils/helpers/i18n';
import {
getLinksListItems,
getPageLinkFromRawData,
- getPostMeta,
+ getPostsWithUrl,
} from '@utils/helpers/pages';
import useBreadcrumb from '@utils/hooks/use-breadcrumb';
import useSettings from '@utils/hooks/use-settings';
@@ -99,27 +98,6 @@ const ThematicPage: NextPageWithLayout<ThematicPageProps> = ({
'@graph': [webpageSchema, articleSchema],
};
- const getPosts = (array: Article[]): Post[] => {
- return array.map((article) => {
- const {
- intro: articleIntro,
- meta: articleMeta,
- slug: articleSlug,
- ...remainingData
- } = article;
-
- const { cover, ...remainingMeta } = articleMeta;
-
- return {
- cover,
- excerpt: articleIntro,
- meta: getPostMeta(remainingMeta),
- url: `/article/${articleSlug}`,
- ...remainingData,
- };
- });
- };
-
const thematicsListTitle = intl.formatMessage({
defaultMessage: 'Other thematics',
description: 'ThematicPage: other thematics list widget title',
@@ -187,7 +165,7 @@ const ThematicPage: NextPageWithLayout<ThematicPageProps> = ({
</Heading>
<PostsList
baseUrl="/thematique/page/"
- posts={getPosts(articles)}
+ posts={getPostsWithUrl(articles)}
total={articles.length}
titleLevel={3}
byYear={true}
diff --git a/src/services/graphql/articles.query.ts b/src/services/graphql/articles.query.ts
index 7bd0901..3e1f575 100644
--- a/src/services/graphql/articles.query.ts
+++ b/src/services/graphql/articles.query.ts
@@ -56,7 +56,6 @@ export const articleBySlugQuery = `query PostBy($slug: ID!) {
}
}
info {
- readingTime
wordsCount
}
modified
@@ -90,11 +89,6 @@ export const articlesQuery = `query Articles($after: String = "", $first: Int =
}
}
}
- author {
- node {
- name
- }
- }
commentCount
contentParts {
beforeMore
@@ -113,7 +107,6 @@ export const articlesQuery = `query Articles($after: String = "", $first: Int =
}
}
info {
- readingTime
wordsCount
}
modified
diff --git a/src/services/graphql/articles.ts b/src/services/graphql/articles.ts
index f130872..f0ba4e4 100644
--- a/src/services/graphql/articles.ts
+++ b/src/services/graphql/articles.ts
@@ -71,13 +71,12 @@ export const getArticleFromRawData = (data: RawArticle): Article => {
id: databaseId,
intro: contentParts.beforeMore,
meta: {
- author: getAuthorFromRawData(author.node, 'page'),
+ author: author && getAuthorFromRawData(author.node, 'page'),
commentsCount: commentCount || 0,
cover: featuredImage?.node
? getImageFromRawData(featuredImage.node)
: undefined,
dates: { publication: date, update: modified },
- readingTime: info.readingTime,
seo: {
description: seo?.metaDesc || '',
title: seo?.title || '',
diff --git a/src/services/graphql/thematics.query.ts b/src/services/graphql/thematics.query.ts
index 3b3ebd6..5a82133 100644
--- a/src/services/graphql/thematics.query.ts
+++ b/src/services/graphql/thematics.query.ts
@@ -15,13 +15,6 @@ export const thematicBySlugQuery = `query ThematicBy($slug: ID!) {
}
}
}
- author {
- node {
- gravatarUrl
- name
- url
- }
- }
commentCount
contentParts {
beforeMore
@@ -40,7 +33,6 @@ export const thematicBySlugQuery = `query ThematicBy($slug: ID!) {
}
}
info {
- readingTime
wordsCount
}
modified
@@ -67,7 +59,6 @@ export const thematicBySlugQuery = `query ThematicBy($slug: ID!) {
}
}
info {
- readingTime
wordsCount
}
modified
diff --git a/src/services/graphql/thematics.ts b/src/services/graphql/thematics.ts
index e526db8..fd9d9f5 100644
--- a/src/services/graphql/thematics.ts
+++ b/src/services/graphql/thematics.ts
@@ -117,7 +117,6 @@ export const getThematicFromRawData = (data: RawThematic): Thematic => {
? getImageFromRawData(featuredImage.node)
: undefined,
dates: { publication: date, update: modified },
- readingTime: info.readingTime,
seo: {
description: seo?.metaDesc || '',
title: seo?.title || '',
diff --git a/src/services/graphql/topics.query.ts b/src/services/graphql/topics.query.ts
index 4574256..57b2569 100644
--- a/src/services/graphql/topics.query.ts
+++ b/src/services/graphql/topics.query.ts
@@ -16,13 +16,6 @@ export const topicBySlugQuery = `query TopicBy($slug: ID!) {
}
}
}
- author {
- node {
- gravatarUrl
- name
- url
- }
- }
commentCount
contentParts {
beforeMore
@@ -41,7 +34,6 @@ export const topicBySlugQuery = `query TopicBy($slug: ID!) {
}
}
info {
- readingTime
wordsCount
}
modified
@@ -68,7 +60,6 @@ export const topicBySlugQuery = `query TopicBy($slug: ID!) {
}
}
info {
- readingTime
wordsCount
}
modified
diff --git a/src/services/graphql/topics.ts b/src/services/graphql/topics.ts
index 3c92442..277580f 100644
--- a/src/services/graphql/topics.ts
+++ b/src/services/graphql/topics.ts
@@ -119,7 +119,6 @@ export const getTopicFromRawData = (data: RawTopic): Topic => {
: undefined,
dates: { publication: date, update: modified },
website: acfTopics.officialWebsite,
- readingTime: info.readingTime,
seo: {
description: seo?.metaDesc || '',
title: seo?.title || '',
diff --git a/src/ts/types/app.ts b/src/ts/types/app.ts
index feff5a5..cb5429b 100644
--- a/src/ts/types/app.ts
+++ b/src/ts/types/app.ts
@@ -44,7 +44,7 @@ export type Comment = {
content: string;
id: number;
meta: CommentMeta;
- parentId: number;
+ parentId?: number;
replies: Comment[];
};
@@ -80,7 +80,6 @@ export type Meta<T extends PageKind> = {
cover?: Image;
dates: Dates;
license?: T extends 'project' ? string : never;
- readingTime?: number;
repos?: T extends 'project' ? Repos : never;
seo: SEO;
tagline?: T extends 'project' ? string : never;
@@ -88,7 +87,7 @@ export type Meta<T extends PageKind> = {
thematics?: T extends 'article' | 'topic' ? PageLink[] : never;
topics?: T extends 'article' | 'thematic' ? PageLink[] : never;
website?: T extends 'topic' ? string : never;
- wordsCount?: number;
+ wordsCount: number;
};
export type Page<T extends PageKind> = {
diff --git a/src/ts/types/mdx.ts b/src/ts/types/mdx.ts
index 6b72f21..16538c1 100644
--- a/src/ts/types/mdx.ts
+++ b/src/ts/types/mdx.ts
@@ -11,10 +11,7 @@ export type MDXPageMeta = Pick<Meta<'page'>, 'cover' | 'dates' | 'seo'> & {
title: string;
};
-export type MDXProjectMeta = Omit<
- Meta<'project'>,
- 'readingTime' | 'wordsCount'
-> & {
+export type MDXProjectMeta = Exclude<Meta<'project'>, 'wordsCount'> & {
intro: string;
title: string;
};
diff --git a/src/ts/types/raw-data.ts b/src/ts/types/raw-data.ts
index ba6d596..dc3db90 100644
--- a/src/ts/types/raw-data.ts
+++ b/src/ts/types/raw-data.ts
@@ -25,7 +25,6 @@ export type ContentParts = {
};
export type Info = {
- readingTime: number;
wordsCount: number;
};
@@ -66,7 +65,7 @@ export type RawArticlePreview = Pick<
>;
export type RawPage = {
- author: NodeResponse<RawAuthor<'page'>>;
+ author?: NodeResponse<RawAuthor<'page'>>;
contentParts: ContentParts;
databaseId: number;
date: string;
diff --git a/src/utils/helpers/pages.ts b/src/utils/helpers/pages.ts
index 62337db..1a388e1 100644
--- a/src/utils/helpers/pages.ts
+++ b/src/utils/helpers/pages.ts
@@ -1,7 +1,10 @@
import { type Post } from '@components/organisms/layout/posts-list';
import { type LinksListItems } from '@components/organisms/widgets/links-list-widget';
-import { type Meta, type PageLink } from '@ts/types/app';
+import { type EdgesResponse } from '@services/graphql/api';
+import { getArticleFromRawData } from '@services/graphql/articles';
+import { type Article, type PageLink } from '@ts/types/app';
import {
+ type RawArticle,
type RawThematicPreview,
type RawTopicPreview,
} from '@ts/types/raw-data';
@@ -52,23 +55,35 @@ export const getLinksListItems = (
};
/**
- * Retrieve the formatted meta.
+ * Retrieve the posts list with the article URL.
*
- * @param {Meta<'article'>} meta - The article meta.
- * @returns {Post['meta']} The formatted meta.
+ * @param {Article[]} posts - An array of articles.
+ * @returns {Post[]} An array of posts with full article URL.
*/
-export const getPostMeta = (meta: Meta<'article'>): Post['meta'] => {
- const { commentsCount, dates, thematics, topics, wordsCount } = meta;
+export const getPostsWithUrl = (posts: Article[]): Post[] => {
+ return posts.map((post) => {
+ return {
+ ...post,
+ url: `/article/${post.slug}`,
+ };
+ });
+};
- return {
- commentsCount,
- dates,
- readingTime: { wordsCount: wordsCount || 0, onlyMinutes: true },
- thematics: thematics?.map((thematic) => {
- return { ...thematic, url: `/thematique/${thematic.slug}` };
- }),
- topics: topics?.map((topic) => {
- return { ...topic, url: `/sujet/${topic.slug}` };
- }),
- };
+/**
+ * Retrieve the posts list from raw data.
+ *
+ * @param {EdgesResponse<RawArticle>[]} rawData - The raw data.
+ * @returns {Post[]} An array of posts.
+ */
+export const getPostsList = (rawData: EdgesResponse<RawArticle>[]): Post[] => {
+ const articlesList: RawArticle[] = [];
+ rawData.forEach((articleData) =>
+ articleData.edges.forEach((edge) => {
+ articlesList.push(edge.node);
+ })
+ );
+
+ return getPostsWithUrl(
+ articlesList.map((article) => getArticleFromRawData(article))
+ );
};