-
Notifications
You must be signed in to change notification settings - Fork 9
/
Post.js
68 lines (59 loc) · 1.81 KB
/
Post.js
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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { routerShape } from 'found/lib/PropTypes';
import { Article, Title, Content } from '@wonderboymusic/graphql-wordpress-components/lib/Post';
import Media from 'containers/Media';
import ContentNode from 'components/ContentNode';
import { dateRegex } from 'utils/regex';
import PostLink from './PostLink';
/* eslint-disable react/no-danger */
export default class Post extends Component {
static propTypes = {
post: PropTypes.shape({
id: PropTypes.string,
slug: PropTypes.string,
date: PropTypes.string,
title: PropTypes.object,
content: PropTypes.object,
excerpt: PropTypes.object,
featuredMedia: PropTypes.object,
}).isRequired,
};
static contextTypes = {
router: routerShape.isRequired,
};
content = null;
bindRef = node => {
this.content = node;
};
onEmbedClick = () => e => {
e.preventDefault();
const { id, date } = this.props.post;
const [, year, month, day] = dateRegex.exec(date);
const url = `/${year}/${month}/${day}/${id}`;
this.context.router.push(url);
};
render() {
const { content: { data: content }, excerpt, featuredMedia } = this.props.post;
const isEmbed = content && content.length && content[0].__typename === 'Embed';
return (
<Article>
<header>
<Title>
<PostLink post={this.props.post} />
</Title>
</header>
{featuredMedia && (
<PostLink post={this.props.post}>
<Media media={featuredMedia} />
</PostLink>
)}
{isEmbed ? (
<ContentNode component={Content} content={content} onEmbedClick={this.onEmbedClick} />
) : (
<Content>{excerpt.raw}</Content>
)}
</Article>
);
}
}