You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DjangoBlog/templates/blog/article_archives.html

84 lines
4.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{# gq: #}
{# 1. 模板继承:复用网站基础布局(包含头部导航、底部信息等公共组件)#}
{% extends 'share_layout/base.html' %}
{# 2. 加载自定义与内置模板标签库 #}
{% load blog_tags %} {# 加载自定义博客标签库,提供博客专属功能(如加载侧边栏)#}
{% load cache %} {# 加载缓存标签库,可用于缓存页面片段提升性能 #}
{% load i18n %} {# 加载国际化标签库,实现多语言文本切换 #}
{# 3. 重写header块定义页面头部元信息标题、SEO标签等#}
{% block header %}
{# 页面标题:多语言支持“文章归档” + 网站描述 #}
<title>{% trans 'article archive' %} | {{ SITE_DESCRIPTION }}</title>
{# SEO优化标签提升归档页在搜索引擎中的表现 #}
<meta name="description" content="{{ SITE_SEO_DESCRIPTION }}"/> {# 网站SEO描述 #}
<meta name="keywords" content="{{ SITE_KEYWORDS }}"/> {# 网站关键词 #}
{# Open Graph协议标签优化社交平台分享时的展示效果 #}
<meta property="og:type" content="blog"/> {# 内容类型为博客 #}
<meta property="og:title" content="{{ SITE_NAME }}"/> {# 社交分享标题 #}
<meta property="og:description" content="{{ SITE_DESCRIPTION }}"/> {# 社交分享描述 #}
<meta property="og:url" content="{{ SITE_BASE_URL }}"/> {# 网站基础URL #}
<meta property="og:site_name" content="{{ SITE_NAME }}"/> {# 网站名称 #}
{% endblock %}
{# 4. 重写content块定义页面核心内容文章归档列表#}
{% block content %}
<div id="primary" class="site-content"> {# 主内容区容器,应用网站全局样式 #}
<div id="content" role="main"> {# 核心内容容器role属性提升可访问性 #}
{# 归档页标题区域 #}
<header class="archive-header">
{# 显示“文章归档”标题(多语言支持)#}
<p class="archive-title">{% trans 'article archive' %}</p>
</header><!-- .archive-header -->
{# 归档列表内容区域 #}
<div class="entry-content">
{# 核心逻辑:按年份和月份分组展示文章 #}
{# regroup标签将article_list文章列表按发布时间的年份分组 #}
{% regroup article_list by pub_time.year as year_post_group %}
<ul>
{# 遍历年份分组 #}
{% for year in year_post_group %}
<li>
{# 显示年份 + 多语言“年”如“2023年”#}
{{ year.grouper }} {% trans 'year' %}
{# 二次分组:在当前年份下,按发布时间的月份再次分组 #}
{% regroup year.list by pub_time.month as month_post_group %}
<ul>
{# 遍历月份分组 #}
{% for month in month_post_group %}
<li>
{# 显示月份 + 多语言“月”如“3月”#}
{{ month.grouper }} {% trans 'month' %}
<ul>
{# 遍历当前年月下的所有文章 #}
{% for article in month.list %}
<li>
{# 文章标题链接:指向文章详情页 #}
<a href="{{ article.get_absolute_url }}">{{ article.title }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</div>
</div><!-- #content -->
</div><!-- #primary -->
{% endblock %}
{# 5. 重写sidebar块加载网站侧边栏 #}
{% block sidebar %}
{# 调用自定义标签load_sidebar加载侧边栏内容 #}
{# 参数说明user为当前用户对象'i'可能用于指定侧边栏样式或权限 #}
{% load_sidebar user 'i' %}
{% endblock %}