feat(links): 添加最近评论侧边模块,友链界面支持不指定评论区id

This commit is contained in:
nineya 2023-12-04 15:12:26 +08:00
parent 4644c76c97
commit 6f7f36e010
3 changed files with 37 additions and 3 deletions

View File

@ -551,6 +551,8 @@ spec:
label: 广告模块
- value: 'recent_posts'
label: 最近文章模块
- value: 'recent_comments'
label: 最近评论模块
- value: 'categories'
label: 文章分类模块
- value: 'tags'
@ -770,6 +772,11 @@ spec:
label: 侧边栏最近文章-展示文章数量
placeholder: 请输入数量数值
value: 5
- $formkit: number
name: recent_comments_num
label: 侧边栏最近评论-展示评论数量
placeholder: 请输入数量数值
value: 5
- $formkit: radio
name: categories_more
label: 侧边栏分类-显示”更多”按钮
@ -868,7 +875,7 @@ spec:
name: link_comment_id
label: 友链页面-评论区ID
placeholder: '请输入 ID'
help: '友链页面没有 ID需要指定一个自定义页面的 ID 用于评论,被指定的文章评论区将作为友链的评论区, 放空则不显示评论区。'
help: '友链页面没有 ID需要指定一个自定义页面的 ID 用于评论,被指定的文章评论区将作为友链的评论区,放空则友链的评论标签将被显示为“未知-未知”。'
- $formkit: radio
name: enable_tags_tag_color
label: 标签页面-开启标签颜色

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<th:block xmlns:th="https://www.thymeleaf.org"
th:insert="~{common/layout :: layout (title = '友链 - ' + ${site.title}, canonical = @{/links}, content = ~{::content}, isPost = false)}"
th:with="baseEnableComment = ${!#strings.isEmpty(theme.config.page_config.link_comment_id)}">
th:with="baseEnableComment = true">
<th:block th:fragment="content"
th:with="defaultAvatar = ${#strings.defaultString(theme.config.page_config.links_default_avatar, #theme.assets('/img/avatar.svg'))}">
<div class="card">
@ -48,7 +48,7 @@
</div>
<div class="card card-content" id="comment-wrapper" th:if="${enableComment}">
<h3 class="comment-title">评论</h3>
<div class="widget-comment" th:data-id="${theme.config.page_config.link_comment_id}" data-target="SinglePage"></div>
<div class="widget-comment" th:data-id="${theme.config.page_config.link_comment_id?:'links'}" data-target="SinglePage"></div>
</div>
</th:block>
</th:block>

View File

@ -0,0 +1,27 @@
<div xmlns:th="https://www.thymeleaf.org"
th:fragment="widget (hide)"
th:class="'card widget recent-comments ' + ${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)}">
<div class="card-title">
<i class="ri-history-line card-title-label"></i><span>最新评论</span>
</div>
<div th:if="${isEmpty}" class="card-empty">暂无评论</div>
<div th:unless="${isEmpty}" class="card-content">
<ul class="widget-comment">
<li class="item" th:each="comment : ${comments}">
<div class="user">
<img width="35" height="35" class="avatar" th:src="${comment.owner.avatar}"
th:alt="${comment.owner.displayName}">
<div class="info">
<div class="author">[[${comment.owner.displayName}]]</div>
<span class="date">[[${#temporals.format(comment.spec.creationTime, 'yyyy-MM-dd')}]]</span>
</div>
</div>
<div class="reply"
th:with="url = ${comment.spec.subjectRef.kind == 'SinglePage'?(comment.spec.subjectRef.name == 'links'?'/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':'')}">
<a th:href="@{${url}}+'#comment-wrapper'" class="link">[[${comment.spec.content}]]</a>
</div>
</li>
</ul>
</div>
</div>