aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/PostMeta/PostMeta.tsx
blob: 7fba0be49493ab83f2cf6529a1d1c4b863c24cdc (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
import {
  Author,
  CommentsCount,
  Dates,
  PostsCount,
  ReadingTime,
  Thematics,
  Topics,
  Website,
} from '@components/MetaItems';
import { MetaKind } from '@ts/types/app';
import { ArticleMeta } from '@ts/types/articles';
import { useRouter } from 'next/router';
import styles from './PostMeta.module.scss';

const PostMeta = ({
  meta,
  kind = 'list',
}: {
  meta: ArticleMeta;
  kind?: MetaKind;
}) => {
  const {
    author,
    commentCount,
    dates,
    readingTime,
    results,
    thematics,
    topics,
    website,
    wordsCount,
  } = meta;
  const { asPath } = useRouter();
  const isThematic = () => asPath.includes('/thematique/');

  const wrapperClass = styles[`wrapper--${kind}`];

  return (
    <dl className={wrapperClass}>
      {author && <Author name={author.name} kind={kind} />}
      {dates && (
        <Dates
          publication={dates.publication}
          update={dates.update}
          kind={kind}
        />
      )}
      {readingTime !== undefined && wordsCount !== undefined && (
        <ReadingTime time={readingTime} words={wordsCount} kind={kind} />
      )}
      {results !== undefined && <PostsCount total={results} kind={kind} />}
      {!isThematic() && thematics && thematics.length > 0 && (
        <Thematics list={thematics} kind={kind} />
      )}
      {isThematic() && topics && topics.length > 0 && (
        <Topics list={topics} kind={kind} />
      )}
      {website && <Website url={website} kind={kind} />}
      {commentCount !== undefined && (
        <CommentsCount total={commentCount} kind={kind} />
      )}
    </dl>
  );
};

export default PostMeta;