Converted ReadNext Component to ES6
This commit is contained in:
parent
3f78235061
commit
742b029244
2 changed files with 56 additions and 50 deletions
|
|
@ -1,50 +0,0 @@
|
||||||
React = require 'react'
|
|
||||||
Router = require 'react-router'
|
|
||||||
{Link} = Router
|
|
||||||
prune = require 'underscore.string/prune'
|
|
||||||
includes = require 'underscore.string/include'
|
|
||||||
find = require 'lodash/collection/find'
|
|
||||||
|
|
||||||
module.exports = React.createClass
|
|
||||||
|
|
||||||
render: ->
|
|
||||||
{rhythm, fontSizeToMS} = @props.typography
|
|
||||||
readNext = @props.post.readNext
|
|
||||||
if readNext?
|
|
||||||
nextPost = find @props.pages, (page) -> includes page.path, readNext.slice(1, -1)
|
|
||||||
unless nextPost
|
|
||||||
<noscript />
|
|
||||||
else
|
|
||||||
nextPost = find @props.pages, (page) -> includes page.path, readNext.slice(1, -1)
|
|
||||||
|
|
||||||
# Create prunned version of the body.
|
|
||||||
html = nextPost.data.body
|
|
||||||
body = prune(html.replace(/<[^>]*>/g, ''), 200)
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<h6
|
|
||||||
style={{
|
|
||||||
margin: 0
|
|
||||||
fontSize: fontSizeToMS(-1).fontSize
|
|
||||||
lineHeight: fontSizeToMS(-1).lineHeight
|
|
||||||
letterSpacing: -0.5
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
READ THIS NEXT:
|
|
||||||
</h6>
|
|
||||||
<h3
|
|
||||||
style={{
|
|
||||||
marginBottom: rhythm(1/4)
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Link
|
|
||||||
to={nextPost.path}
|
|
||||||
query={{readNext: true}}
|
|
||||||
>
|
|
||||||
{nextPost.data.title}
|
|
||||||
</Link>
|
|
||||||
</h3>
|
|
||||||
<p>{body}</p>
|
|
||||||
<hr />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
56
components/ReadNext.jsx
Normal file
56
components/ReadNext.jsx
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { Link } from 'react-router';
|
||||||
|
import { prune, include as includes } from 'underscore.string';
|
||||||
|
import find from 'lodash/collection/find';
|
||||||
|
|
||||||
|
module.exports = React.createClass({
|
||||||
|
render: function() {
|
||||||
|
var body, fontSizeToMS, html, nextPost, readNext, ref, rhythm;
|
||||||
|
ref = this.props.typography, rhythm = ref.rhythm, fontSizeToMS = ref.fontSizeToMS;
|
||||||
|
readNext = this.props.post.readNext;
|
||||||
|
if (readNext != null) {
|
||||||
|
nextPost = find(this.props.pages, function(page) {
|
||||||
|
return includes(page.path, readNext.slice(1, -1));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!nextPost) {
|
||||||
|
return React.createElement("noscript", null);
|
||||||
|
} else {
|
||||||
|
nextPost = find(this.props.pages, function(page) {
|
||||||
|
return includes(page.path, readNext.slice(1, -1));
|
||||||
|
});
|
||||||
|
// Create pruned version of the body.
|
||||||
|
html = nextPost.data.body;
|
||||||
|
body = prune(html.replace(/<[^>]*>/g, ''), 200);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h6
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: fontSizeToMS(-1).fontSize,
|
||||||
|
lineHeight: fontSizeToMS(-1).lineHeight,
|
||||||
|
letterSpacing: -0.5
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
READ THIS NEXT:
|
||||||
|
</h6>
|
||||||
|
<h3
|
||||||
|
style={{
|
||||||
|
marginBottom: rhythm(1/4)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Link
|
||||||
|
to={nextPost.path}
|
||||||
|
query={{readNext: true}}
|
||||||
|
>
|
||||||
|
{nextPost.data.title}
|
||||||
|
</Link>
|
||||||
|
</h3>
|
||||||
|
<p>{body}</p>
|
||||||
|
<hr />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue