更新 'src/DjangoBlog-master/templates/comments/tags/comment_item_tree.html'

fz_branch
pa2g3nmk9 5 months ago
parent e80c253a98
commit 873d825a80

@ -1,53 +1,69 @@
{% load blog_tags %}
{% load blog_tags %} {# 加载自定义博客标签 #}
{# 评论项模板 - 支持嵌套回复的树形结构 #}
<li class="comment even thread-even depth-{{ depth }} parent" id="comment-{{ comment_item.pk }}"
style="margin-left: {% widthratio depth 1 3 %}rem">
style="margin-left: {% widthratio depth 1 3 %}rem"> {# 根据深度设置左边距,实现缩进 #}
<div id="div-comment-{{ comment_item.pk }}" class="comment-body">
{# 评论作者信息 #}
<div class="comment-author vcard">
{# Gravatar头像 #}
<img alt=""
src="{{ comment_item.author.email|gravatar_url:150 }}"
srcset="{{ comment_item.author.email|gravatar_url:150 }}"
class="avatar avatar-96 photo" height="96" width="96">
{# 作者姓名 #}
<cite class="fn">
<a rel="nofollow"
{% if comment_item.author.is_superuser %}
{% if comment_item.author.is_superuser %} {# 超级用户有个人主页链接 #}
href="{{ comment_item.author.get_absolute_url }}"
{% else %}
href="#"
{% endif %}
{% else %}
href="#" {# 普通用户无链接 #}
{% endif %}
rel="external nofollow"
class="url">{{ comment_item.author.username }}
class="url">
{{ comment_item.author.username }}
</a>
</cite>
</div>
{# 评论元信息 #}
<div class="comment-meta commentmetadata">
{{ comment_item.creation_time }}
{{ comment_item.creation_time }} {# 评论时间 #}
</div>
{# 回复对象信息 #}
<p>
{% if comment_item.parent_comment %}
<div>回复 <a
href="#comment-{{ comment_item.parent_comment.pk }}">@{{ comment_item.parent_comment.author.username }}</a>
{% if comment_item.parent_comment %} {# 如果是回复评论 #}
<div>
回复 <a href="#comment-{{ comment_item.parent_comment.pk }}"> {# 跳转到父评论 #}
@{{ comment_item.parent_comment.author.username }} {# 显示被回复者用户名 #}
</a>
</div>
{% endif %}
</p>
<p>{{ comment_item.body|escape|comment_markdown }}</p>
{# 评论内容 #}
<p>{{ comment_item.body|escape|comment_markdown }}</p> {# 安全渲染评论内容 #}
<div class="reply"><a rel="nofollow" class="comment-reply-link"
href="javascript:void(0)" data-pk="{{ comment_item.pk }}"
aria-label="回复给{{ comment_item.author.username }}">回复</a></div>
{# 回复按钮 #}
<div class="reply">
<a rel="nofollow" class="comment-reply-link"
href="javascript:void(0)"
data-pk="{{ comment_item.pk }}" {# 存储评论ID用于JavaScript #}
aria-label="回复给{{ comment_item.author.username }}">回复</a>
</div>
</div>
</li><!-- #comment-## -->
{% query article_comments parent_comment=comment_item as cc_comments %}
{% for cc in cc_comments %}
{# 递归加载子评论 - 构建评论树 #}
{% query article_comments parent_comment=comment_item as cc_comments %} {# 查询当前评论的子评论 #}
{% for cc in cc_comments %} {# 遍历所有子评论 #}
{% with comment_item=cc template_name="comments/tags/comment_item_tree.html" %}
{% if depth >= 1 %}
{% include template_name %}
{% else %}
{% with depth=depth|add:1 %}
{% include template_name %}
{% if depth >= 1 %} {# 如果已经有一定深度 #}
{% include template_name %} {# 直接包含模板,保持当前深度 #}
{% else %} {# 如果是第一层深度 #}
{% with depth=depth|add:1 %} {# 深度加1 #}
{% include template_name %} {# 包含模板,深度递增 #}
{% endwith %}
{% endif %}
{% endwith %}

Loading…
Cancel
Save