Last active
May 5, 2018 00:09
-
-
Save elmasse/0d8af9256690b998ef569066dafa2bda to your computer and use it in GitHub Desktop.
PostList for nextein 1.3.0-beta.4
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
//nextein-example/components/post-list-entry.js | |
import React from 'react' | |
import Link from 'nextein/link' | |
import { Content } from 'nextein/post' | |
const countWords = (s) => { | |
s = s.replace(/(^\s*)|(\s*$)/gi,"");//exclude start and end white-space | |
s = s.replace(/[ ]{2,}/gi," ");//2 or more space to 1 | |
s = s.replace(/\n /,"\n"); // exclude newline with a start spacing | |
return s.split(' ').length; | |
} | |
const readingTime = (words) => { | |
return Math.ceil(words/200) | |
} | |
const PostListEntry = ({ data, content, raw, excerpt=true }) => { | |
const { url, title, date, _entry, page = 'post' } = data | |
const words = countWords(raw) | |
const readTime = readingTime(words) | |
return ( | |
<article> | |
<h1> | |
{/* <a href={url}>{title}</a> */} | |
<Link data={data}><a>{title}</a></Link> | |
</h1> | |
<span>{`${new Date(date).toDateString()} | ~ ${readTime} mins | ${words} words`}</span> | |
<Content data={data} content={content} excerpt={excerpt}/> | |
</article> | |
) | |
} | |
export default PostListEntry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment