File size: 1,686 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// @flow
import React from 'react';
import Head from 'src/components/head';
import getThreadLink from 'src/helpers/get-thread-link';
import generateMetaInfo from 'shared/generate-meta-info';
import type { ThreadInfoType } from 'shared/graphql/fragments/thread/threadInfo';

type Props = {
  thread: ThreadInfoType,
};

const ThreadHead = (props: Props) => {
  const { thread } = props;
  const {
    metaImage,
    type,
    community,
    content,
    createdAt,
    modifiedAt,
    author,
  } = thread;
  const { title, description } = generateMetaInfo({
    type: 'thread',
    data: {
      title: content.title,
      body: content.body,
      type: type,
      communityName: community.name,
    },
  });

  return (
    <Head
      title={title}
      description={description}
      type="article"
      image={metaImage}
      key={title}
    >
      <link
        rel="canonical"
        href={`https://spectrum.chat${getThreadLink(thread)}`}
      />
      {metaImage && <meta name="twitter:card" content="summary_large_image" />}
      <meta
        property="article:published_time"
        content={new Date(createdAt).toISOString()}
      />
      <meta
        property="article:modified_time"
        content={new Date(modifiedAt || createdAt).toISOString()}
      />
      <meta
        property="article:author"
        content={`https://spectrum.chat/users/@${author.user.username}`}
      />
      <meta
        property="article:section"
        content={`${community.name} community`}
      />
      {community.redirect && community.noindex && (
        <meta name="robots" content="noindex, nofollow" />
      )}
    </Head>
  );
};

export default ThreadHead;