mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2024-12-27 07:18:17 +01:00
refactor: fixes linting errors components/ReadNext/index.jsx
adds readNext to my-second-post to show this feature in the demo
This commit is contained in:
parent
db448ba9d1
commit
2a77a52ed2
@ -1,44 +1,48 @@
|
|||||||
import React from 'react'
|
import React from 'react';
|
||||||
import { Link } from 'react-router'
|
import { Link } from 'react-router';
|
||||||
import { prune, include as includes } from 'underscore.string'
|
import { include as includes } from 'underscore.string';
|
||||||
import find from 'lodash/find'
|
import find from 'lodash/find';
|
||||||
|
|
||||||
import './style.css'
|
import './style.css';
|
||||||
|
|
||||||
class ReadNext extends React.Component {
|
class ReadNext extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
const {post} = this.props
|
const { post } = this.props;
|
||||||
const {pages} = this.props.route
|
const { pages } = this.props.route;
|
||||||
const {readNext} = post
|
const { readNext } = post;
|
||||||
|
|
||||||
let nextPost
|
let nextPost;
|
||||||
if (readNext) {
|
if (readNext) {
|
||||||
nextPost = find(pages, (page) => includes(page.path, readNext)
|
nextPost = find(pages, page => includes(page.path, readNext));
|
||||||
)
|
|
||||||
}
|
|
||||||
if (!nextPost) {
|
|
||||||
return React.createElement('noscript', null)
|
|
||||||
} else {
|
|
||||||
nextPost = find(pages, (page) => includes(page.path, readNext.slice(1, -1))
|
|
||||||
)
|
|
||||||
const description = nextPost.data.description
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h6 style={ { fontSize: '16px', margin: '20px 0 0'} }>READ THIS NEXT:</h6>
|
|
||||||
<h3 style={ { margin: '5px 0 0'} }><Link to={ nextPost.path } query={ { readNext: true} } > { nextPost.data.title } </Link></h3>
|
|
||||||
<p className='description'>
|
|
||||||
{ description }
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (!nextPost) {
|
||||||
|
return React.createElement('noscript', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
nextPost = find(pages, page => includes(page.path, readNext.slice(1, -1)));
|
||||||
|
const description = nextPost.data.description;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h6 style={{ fontSize: '16px', margin: '20px 0 0' }}>READ THIS NEXT:</h6>
|
||||||
|
<h3 style={{ margin: '5px 0 0' }}>
|
||||||
|
<Link to={nextPost.path} query={{ readNext: true }}>
|
||||||
|
{nextPost.data.title}
|
||||||
|
</Link>
|
||||||
|
</h3>
|
||||||
|
<p className="description">
|
||||||
|
{description}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadNext.propTypes = {
|
ReadNext.propTypes = {
|
||||||
post: React.PropTypes.object.isRequired,
|
post: React.PropTypes.object.isRequired,
|
||||||
pages: React.PropTypes.array,
|
pages: React.PropTypes.array,
|
||||||
}
|
route: React.PropTypes.object,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ReadNext;
|
||||||
|
|
||||||
export default ReadNext
|
|
||||||
|
@ -3,6 +3,7 @@ title: My Second Post!
|
|||||||
date: "2015-05-06T23:46:37.121Z"
|
date: "2015-05-06T23:46:37.121Z"
|
||||||
layout: post
|
layout: post
|
||||||
path: "/my-second-post/"
|
path: "/my-second-post/"
|
||||||
|
readNext: "/hi-folks/"
|
||||||
category: "FrontEnd"
|
category: "FrontEnd"
|
||||||
description: "Civil society; save lives pathway to a better life public-private partnerships solution, tackle, protect UNHCR social movement Jane Addams sustainable campaign respond equality."
|
description: "Civil society; save lives pathway to a better life public-private partnerships solution, tackle, protect UNHCR social movement Jane Addams sustainable campaign respond equality."
|
||||||
---
|
---
|
||||||
|
Loading…
Reference in New Issue
Block a user