forked from enviPath/enviPy
[Enhancement] Restyle Discourse Cards for title only (#220)
Excerpts are only delivered for pinned posts. So all cards apart from pinned look empty. Changed to only display (more of) the title now. closes #214 Reviewed-on: enviPath/enviPy#220 Co-authored-by: Tobias O <tobias.olenyi@envipath.com> Co-committed-by: Tobias O <tobias.olenyi@envipath.com>
This commit is contained in:
@ -63,17 +63,20 @@ class DiscourseAPI {
|
||||
* @returns {string} Cleaned excerpt
|
||||
*/
|
||||
extractExcerpt(excerpt) {
|
||||
if (!excerpt) return 'Click to read more';
|
||||
if (!excerpt) return 'No preview available yet';
|
||||
|
||||
// Remove HTML tags and clean up; collapse whitespace; do not add manual ellipsis
|
||||
return excerpt
|
||||
const cleaned = excerpt
|
||||
.replace(/<[^>]*>/g, '') // Remove HTML tags
|
||||
.replace(/ /g, ' ') // Replace with spaces
|
||||
.replace(/&/g, '&') // Replace & with &
|
||||
.replace(/</g, '<') // Replace < with <
|
||||
.replace(/>/g, '>') // Replace > with >
|
||||
.replace(/\s+/g, ' ') // Collapse all whitespace/newlines
|
||||
.trim()
|
||||
.trim();
|
||||
|
||||
// Check if excerpt is empty after cleaning
|
||||
return cleaned || 'No preview available yet';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -305,16 +305,13 @@
|
||||
const date = new Date(topic.created_at).toLocaleDateString();
|
||||
|
||||
return `
|
||||
<div class="card bg-white shadow-xs hover:shadow-lg transition-shadow duration-300 h-64 w-75 flex-shrink-0">
|
||||
<div class="card-body flex flex-col h-full">
|
||||
<h3 class="card-title leading-tight font-normal tracking-tight h-12 mb-2 line-clamp-2 text-ellipsis wrap-break-word overflow-hidden">
|
||||
<div class="card bg-white shadow-sm hover:shadow-lg transition-shadow duration-300 h-52 w-75 flex-shrink-0">
|
||||
<div class="card-body flex flex-col h-full justify-between">
|
||||
<h3 class="card-title leading-tight font-normal tracking-tight mb-2 line-clamp-5 overflow-hidden">
|
||||
<a href="${topic.url}" target="_blank" class="hover:text-primary">
|
||||
${topic.title}
|
||||
</a>
|
||||
</h3>
|
||||
<div class="text-sm line-clamp-4 break-words" >
|
||||
${topic.excerpt}
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row items-center justify-between">
|
||||
<div class="flex items-center gap-2">
|
||||
|
||||
Reference in New Issue
Block a user