1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 08:27:42 +02:00

chore: allow extending PostPreview content (#4043)

This commit is contained in:
IanM
2024-09-29 14:44:51 +01:00
committed by GitHub
parent de36551b45
commit df14216e1b

View File

@@ -17,16 +17,28 @@ export default class PostPreview extends Component {
view() {
const post = this.attrs.post;
const user = post.user();
const content = post.contentType() === 'comment' && post.contentPlain();
const excerpt = content ? highlight(content, this.attrs.highlight, 300) : '';
return (
<Link className="PostPreview" href={app.route.post(post)} onclick={this.attrs.onclick}>
<span className="PostPreview-content">
{avatar(user)}
{username(user)} <span className="PostPreview-excerpt">{excerpt}</span>
{username(user)} <span className="PostPreview-excerpt">{this.excerpt()}</span>
</span>
</Link>
);
}
/**
* @returns {string|undefined|null}
*/
content() {
return this.attrs.post.contentType() === 'comment' && this.attrs.post.contentPlain();
}
/**
* @returns {string}
*/
excerpt() {
return this.content() ? highlight(this.content(), this.attrs.highlight, 300) : '';
}
}