mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 17:17:28 +02:00
Extract blog post truncation logic and add tests (#640)
This commit is contained in:
parent
5b3f54741e
commit
8d676e6a5a
13 changed files with 192 additions and 30 deletions
|
@ -8,32 +8,32 @@
|
|||
const MarkdownBlock = require('./MarkdownBlock.js');
|
||||
const React = require('react');
|
||||
|
||||
const utils = require('./utils');
|
||||
|
||||
// inner blog component for the article itself, without sidebar/header/footer
|
||||
class BlogPost extends React.Component {
|
||||
renderContent() {
|
||||
let content = this.props.content;
|
||||
let hasSplit = false;
|
||||
if (content.split('<!--truncate-->').length > 1) {
|
||||
hasSplit = (
|
||||
<div className="read-more">
|
||||
<a
|
||||
className="button"
|
||||
href={this.props.config.baseUrl + 'blog/' + this.props.post.path}>
|
||||
Read More
|
||||
</a>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (this.props.truncate) {
|
||||
content = content.split('<!--truncate-->')[0];
|
||||
return (
|
||||
<article className="post-content">
|
||||
<MarkdownBlock>{content}</MarkdownBlock>
|
||||
{hasSplit}
|
||||
<MarkdownBlock>
|
||||
{utils.extractBlogPostBeforeTruncate(this.props.content)}
|
||||
</MarkdownBlock>
|
||||
{utils.blogPostHasTruncateMarker(this.props.content) && (
|
||||
<div className="read-more">
|
||||
<a
|
||||
className="button"
|
||||
href={
|
||||
this.props.config.baseUrl + 'blog/' + this.props.post.path
|
||||
}>
|
||||
Read More
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
</article>
|
||||
);
|
||||
}
|
||||
return <MarkdownBlock>{content}</MarkdownBlock>;
|
||||
return <MarkdownBlock>{this.props.content}</MarkdownBlock>;
|
||||
}
|
||||
|
||||
renderAuthorPhoto() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue