halo-theme-dream2.0-plus
Version:
64 lines (63 loc) • 3.96 kB
HTML
<div xmlns:th="https://www.thymeleaf.org"
th:fragment="widget (sidebar, index)"
th:data-index="${index}"
th:data-position="${sidebar.position}"
th:class="'card widget recent-comments ' + ${sidebar.hide}"
th:with="num = ${#strings.isEmpty(theme.config.sidebar.recent_comments_num)? 5 : T(java.lang.Integer).parseInt(theme.config.sidebar.recent_comments_num)},
comments = ${commentFinder.list(null,1,num)},
isEmpty = ${#lists.isEmpty(comments.items)}">
<div class="card-title" th:with="defaultTitle=#{widget.recent_comments.title},
iconContent = ${#strings.defaultString(sidebar.icon_new?.value, 'ri-message-2-line')},
iconSvg = ${#strings.startsWith(iconContent, '<svg')}">
<i class="card-title-label"
th:unless="${iconSvg}"
th:classappend="${iconContent}"></i>
<th:block th:if="${iconSvg}" th:utext="${iconContent}"></th:block>
<span
th:text="${#strings.defaultString(sidebar.title, defaultTitle)}"></span>
</div>
<div th:if="${isEmpty}" class="card-empty">[[#{widget.recent_comments.empty.tip}]]</div>
<div th:unless="${isEmpty}" class="card-content">
<ul class="widget-comment">
<li class="item" th:each="comment : ${comments}">
<div class="user"
th:with="
emailHash = ${comment.spec.owner.annotations != null ? comment.spec.owner.annotations['email-hash'] : ''},
userA = ${comment.owner.avatar},
img = ${#strings.isEmpty(userA) && !#strings.isEmpty(emailHash) ? #strings.replace(theme.config.sidebar.providerMirror, '{hash}', emailHash) : userA}">
<img width="35" height="35" th:unless="${#strings.isEmpty(img)}" class="avatar" th:src="${img}"
th:alt="${comment.owner.displayName}">
<div th:if="${#strings.isEmpty(img)}" class="no-avatar">
<span class="avatar-info">[[${#strings.substring(comment.owner.displayName, 0, 1)}]]</span>
</div>
<div class="info">
<div class="author">[[${comment.owner.displayName}]]</div>
<span class="date">[[${#temporals.format(comment.spec.creationTime, theme.config.basic_info.global_time_format)}]]</span>
</div>
</div>
<div class="reply"
th:attr="data-content=${comment.spec.content}"
th:with="url = ${comment.spec.subjectRef.kind == 'SinglePage'?(comment.spec.subjectRef.name == theme.config.page_config.link_comment_id?'/links':singlePageFinder.getByName(comment.spec.subjectRef.name).status.permalink):(comment.spec.subjectRef.kind == 'Post'?postFinder.getByName(comment.spec.subjectRef.name).status.permalink:comment.spec.subjectRef.kind == 'Moment'?'/moments':(comment.spec.subjectRef.kind == 'Plugin'? (comment.spec.subjectRef.name == 'PluginLinks' ? '/links':'') : ''))}">
<a th:href="@{${url}}+'#comment-wrapper'" class="link"></a>
</div>
</li>
</ul>
</div>
<script>
document.querySelectorAll('.recent-comments .reply').forEach(reply => {
try {
const contentHtml = reply.getAttribute('data-content')
reply.removeAttribute('data-content')
const link = reply.querySelector('a')
const parser = new DOMParser();
const doc = parser.parseFromString(contentHtml, 'text/html');
const plainText = doc.body.textContent.trim(); // 自动移除所有标签,只保留文本
link.setAttribute('aria-label', plainText)
link.setAttribute('title', plainText)
link.textContent = plainText
} catch (e) {
console.error('Error processing HTML:', e)
}
})
</script>
</div>