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

feat: allow extending PostPreview content (#4197)

This commit is contained in:
Davide Iadeluca
2025-02-21 09:45:36 +01:00
committed by GitHub
parent f54a5200cf
commit e2221b5f74

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={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) : '';
}
}