From df14216e1b72810a023b96dc743f1bc29f42886c Mon Sep 17 00:00:00 2001
From: IanM <16573496+imorland@users.noreply.github.com>
Date: Sun, 29 Sep 2024 14:44:51 +0100
Subject: [PATCH] chore: allow extending PostPreview content (#4043)
---
.../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) : '';
+ }
}