Skip to content

Commit

Permalink
chore: allow extending PostPreview content
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Sep 29, 2024
1 parent de36551 commit aab30d7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions framework/core/js/src/forum/components/PostPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) : '';
}
}

0 comments on commit aab30d7

Please sign in to comment.