Created
April 2, 2018 13:02
-
-
Save davidyeiser/cb7766483125b8d3a70f2ef34ff08e05 to your computer and use it in GitHub Desktop.
Example Post component for React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Link from 'next/link' | |
import dateFormat from 'dateformat' | |
import Markdown from 'react-markdown' | |
class Post extends React.Component { | |
render() { | |
const { | |
title, | |
content, | |
publish_date, | |
slug, | |
id | |
} = this.props | |
const hasId = !!id ? true : false | |
const permalink = hasId ? '/post/' + id + '/' + slug : false | |
return ( | |
<div> | |
{!!permalink ? | |
<Link href={permalink}> | |
<a title="Permalink for this note"> | |
{title && <Title>{title}</Title> : ''} | |
{publish_date && | |
<time dateTime={dateFormat(publish_date, 'isoDateTime')}>{dateFormat(publish_date, 'mmmm d, yyyy')}</time> | |
} | |
</a> | |
</Link> : | |
<div> | |
{title && <Title>{title}</Title>} | |
{publish_date && | |
<time dateTime={dateFormat(publish_date, 'isoDateTime')}>{dateFormat(publish_date, 'mmmm d, yyyy')}</time> | |
} | |
</div> | |
} | |
{content && <Markdown source={content} /> } | |
</div> | |
) | |
} | |
} | |
export default Post |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment