From aab30d7ed360866295346f4fc21e4ca23025f16d Mon Sep 17 00:00:00 2001 From: IanM Date: Sun, 29 Sep 2024 14:38:02 +0100 Subject: [PATCH] chore: allow extending PostPreview content --- .../js/src/forum/components/PostPreview.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/framework/core/js/src/forum/components/PostPreview.js b/framework/core/js/src/forum/components/PostPreview.js index 5293bd3c17..6f200c7c4c 100644 --- a/framework/core/js/src/forum/components/PostPreview.js +++ b/framework/core/js/src/forum/components/PostPreview.js @@ -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 ( {avatar(user)} - {username(user)} {excerpt} + {username(user)} {this.excerpt()} ); } + + /** + * @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) : ''; + } }