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_index.html

74 lines
4.2 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 %} {# 加载缓存标签库,可用于缓存页面片段提升性能 #}
{# 3. 重写header块动态生成页面标题和SEO元标签 #}
{% block header %}
{# 根据是否有筛选条件(标签/分类名称)生成不同标题 #}
{% if tag_name %}
{# 有筛选条件时:标题格式为“页面类型:标签名 | 网站描述”#}
{# 例如“分类:技术 | 我的博客”或“标签:Python | 我的博客”#}
<title>{{ page_type }}:{{ tag_name }} | {{ SITE_DESCRIPTION }}</title>
{# 注释的描述标签可根据需要启用针对筛选结果定制SEO描述 #}
{% comment %}<meta name="description" content="{{ page_type }}:{{ tag_name }}"/>{% endcomment %}
{% else %}
{# 无筛选条件时:使用网站名称和描述作为标题 #}
<title>{{ SITE_NAME }} | {{ SITE_DESCRIPTION }}</title>
{% endif %}
{# 通用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"> {# 核心内容容器,提升无障碍访问性 #}
{# 筛选结果标题:当有筛选条件(如按分类/标签筛选)时显示 #}
{% if page_type and tag_name %}
<header class="archive-header">
{# 显示筛选类型和名称例如“分类技术”或“标签Python”#}
<p class="archive-title">{{ page_type }}<span>{{ tag_name }}</span></p>
</header><!-- .archive-header -->
{% endif %}
{# 遍历文章列表:渲染每篇文章的摘要信息 #}
{% for article in article_list %}
{# 调用自定义标签load_article_detail渲染单篇文章 #}
{# 参数说明:#}
{# article当前文章对象 #}
{# True是否显示摘要True表示展示摘要False可能展示全文#}
{# user当前登录用户用于权限判断如显示编辑按钮#}
{% load_article_detail article True user %}
{% endfor %}
{# 分页控件:当文章数量超过单页显示上限时显示 #}
{% if is_paginated %}
{# 调用自定义标签load_pagination_info生成分页链接 #}
{# 参数说明:#}
{# page_objDjango分页对象包含当前页、总页数等信息#}
{# page_type页面类型如“分类”“标签”用于生成带筛选条件的分页链接#}
{# tag_name筛选名称如分类名、标签名确保分页时保留筛选条件#}
{% load_pagination_info page_obj page_type tag_name %}
{% endif %}
</div><!-- #content -->
</div><!-- #primary -->
{% endblock %}
{# 5. 重写sidebar块加载与当前页面匹配的侧边栏 #}
{% block sidebar %}
{# 调用自定义标签load_sidebar参数linktype可能控制侧边栏内容如热门标签、相关分类#}
{% load_sidebar user linktype %}
{% endblock %}