Skip to content

Instantly share code, notes, and snippets.

@elmasse
Last active May 5, 2018 00:09
Show Gist options
  • Save elmasse/0d8af9256690b998ef569066dafa2bda to your computer and use it in GitHub Desktop.
Save elmasse/0d8af9256690b998ef569066dafa2bda to your computer and use it in GitHub Desktop.
PostList for nextein 1.3.0-beta.4
//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