diff --git a/plugins/article_copyright/plugin.py b/plugins/article_copyright/plugin.py index 2f6dbae..8898cb9 100644 --- a/plugins/article_copyright/plugin.py +++ b/plugins/article_copyright/plugin.py @@ -1,3 +1,4 @@ +#gq: # 1. 导入所需的基础类和模块 # 从插件管理模块导入基类 BasePlugin diff --git a/plugins/external_links/plugin.py b/plugins/external_links/plugin.py index 1b0a056..4d729d3 100644 --- a/plugins/external_links/plugin.py +++ b/plugins/external_links/plugin.py @@ -1,3 +1,4 @@ +#gq: # 导入正则表达式模块,用于匹配和处理HTML中的标签 import re # 导入URL解析模块,用于解析链接的域名等信息 diff --git a/plugins/reading_time/plugin.py b/plugins/reading_time/plugin.py index 6cf9a7f..457bc94 100644 --- a/plugins/reading_time/plugin.py +++ b/plugins/reading_time/plugin.py @@ -1,3 +1,4 @@ +#gq: # 导入数学运算模块,用于向上取整计算 import math # 导入正则表达式模块,用于处理HTML内容和文本分词 diff --git a/plugins/seo_optimizer/plugin.py b/plugins/seo_optimizer/plugin.py index 9a4b6cd..d953ec1 100644 --- a/plugins/seo_optimizer/plugin.py +++ b/plugins/seo_optimizer/plugin.py @@ -1,3 +1,4 @@ +#gq: # 导入JSON模块,用于将结构化数据转换为JSON格式 import json # 导入Django工具函数,用于移除HTML标签(提取纯文本) diff --git a/plugins/view_count/plugin.py b/plugins/view_count/plugin.py index 3e8528e..3d0f7d1 100644 --- a/plugins/view_count/plugin.py +++ b/plugins/view_count/plugin.py @@ -1,3 +1,4 @@ +#gq: # 导入Django博客系统的插件基类,所有自定义插件需继承此类以实现标准化接口 from djangoblog.plugin_manage.base_plugin import BasePlugin # 导入插件钩子管理模块,用于将插件功能绑定到系统预设的钩子点 diff --git a/templates/account/forget_password.html b/templates/account/forget_password.html index 4729ec3..fbf1c4c 100644 --- a/templates/account/forget_password.html +++ b/templates/account/forget_password.html @@ -1,3 +1,4 @@ +{# gq: #} {# 1. 模板继承:继承基础账户页面模板,复用头部、底部、样式等公共组件 #} {# base_account.html 通常包含账户相关页面(登录、注册、密码重置)的通用布局 #} {% extends 'share_layout/base_account.html' %} diff --git a/templates/account/login.html b/templates/account/login.html index 5850bda..0e26dd9 100644 --- a/templates/account/login.html +++ b/templates/account/login.html @@ -1,3 +1,4 @@ +{# gq: #} {# 1. 模板继承:复用账户相关页面的公共布局(如头部导航、底部信息、基础样式) #} {# base_account.html 通常是登录、注册、密码重置等页面的父模板,保证风格统一 #} {% extends 'share_layout/base_account.html' %} diff --git a/templates/account/registration_form.html b/templates/account/registration_form.html index 412eeda..1f97b9a 100644 --- a/templates/account/registration_form.html +++ b/templates/account/registration_form.html @@ -1,3 +1,4 @@ +{# gq: #} {# 1. 模板继承:复用账户相关页面的公共布局 #} {# base_account.html 通常包含登录、注册、密码重置等页面的通用组件(如头部样式、底部信息)#} {# 继承后只需专注于当前注册页的专属内容,减少重复代码并保证风格统一 #} diff --git a/templates/account/result.html b/templates/account/result.html index 23c9094..baf24a5 100644 --- a/templates/account/result.html +++ b/templates/account/result.html @@ -1,23 +1,42 @@ +{# gq: #} +{# 1. 模板继承:复用网站基础布局模板 #} +{# base.html 通常包含网站公共组件(如顶部导航栏、底部版权信息、全局样式引用等)#} +{# 继承后只需编写当前页面的专属内容,减少重复代码并保证全站风格统一 #} {% extends 'share_layout/base.html' %} + +{# 2. 加载国际化标签库:实现多语言文本切换 #} +{# 后续用{% trans %}包裹的文本(如“login”“back to the homepage”)可根据用户语言设置自动翻译 #} {% load i18n %} + +{# 3. 重写父模板的header块:定义当前页面的标题 #} +{# 父模板中header块通常对应HTML的区域,此处仅重写标签 #} {% block header %} + {# 动态标题:{{ title }}由视图函数传递,不同场景显示不同标题(如“登录提示”“操作成功”)#} <title> {{ title }} {% endblock %} + +{# 4. 重写父模板的content块:定义页面核心内容(提示信息与操作链接)#} {% block content %} + {# 主内容容器:site-content和content类通常是网站预设样式,控制内容区域的布局和样式 #}
-
+
{# role="main"提升页面可访问性,告诉辅助工具这是主要内容区 #} + {# 提示信息头部:archive-header类为预设样式,用于包裹标题类内容 #}
- + {# 动态提示内容:{{ content }}由视图传递,显示具体提示文本(如“请先登录再访问该页面”“操作已完成”)#}

{{ content }}

-
-
+
{# 换行符:增加提示信息与操作链接之间的间距,提升视觉舒适度 #} + + {# 操作链接头部:设置文本居中,引导用户点击关键链接 #} +
+ {# 登录链接:跳转到账户登录页,供未登录用户使用(多语言文本支持)#} {% trans 'login' %} - | + | {# 分隔符:视觉上区分不同链接,避免混淆 #} + {# 首页链接:跳转到网站首页,供需要返回主页面的用户使用(多语言文本支持)#} {% trans 'back to the homepage' %} diff --git a/templates/blog/article_archives.html b/templates/blog/article_archives.html index 959319e..355451a 100644 --- a/templates/blog/article_archives.html +++ b/templates/blog/article_archives.html @@ -1,42 +1,65 @@ +{# gq: #} +{# 1. 模板继承:复用网站基础布局(包含头部导航、底部信息等公共组件)#} {% extends 'share_layout/base.html' %} -{% load blog_tags %} -{% load cache %} -{% load i18n %} -{% block header %} - {% trans 'article archive' %} | {{ SITE_DESCRIPTION }} +{# 2. 加载自定义与内置模板标签库 #} +{% load blog_tags %} {# 加载自定义博客标签库,提供博客专属功能(如加载侧边栏)#} +{% load cache %} {# 加载缓存标签库,可用于缓存页面片段提升性能 #} +{% load i18n %} {# 加载国际化标签库,实现多语言文本切换 #} - - - - - - - +{# 3. 重写header块:定义页面头部元信息(标题、SEO标签等)#} +{% block header %} + {# 页面标题:多语言支持“文章归档” + 网站描述 #} + {% trans 'article archive' %} | {{ SITE_DESCRIPTION }} + {# SEO优化标签:提升归档页在搜索引擎中的表现 #} + {# 网站SEO描述 #} + {# 网站关键词 #} + {# Open Graph协议标签:优化社交平台分享时的展示效果 #} + {# 内容类型为博客 #} + {# 社交分享标题 #} + {# 社交分享描述 #} + {# 网站基础URL #} + {# 网站名称 #} {% endblock %} + +{# 4. 重写content块:定义页面核心内容(文章归档列表)#} {% block content %} -
-
+
{# 主内容区容器,应用网站全局样式 #} +
{# 核心内容容器,role属性提升可访问性 #} + {# 归档页标题区域 #}
- + {# 显示“文章归档”标题(多语言支持)#}

{% trans 'article archive' %}

+ {# 归档列表内容区域 #}
- + {# 核心逻辑:按年份和月份分组展示文章 #} + {# regroup标签:将article_list(文章列表)按发布时间的年份分组 #} {% regroup article_list by pub_time.year as year_post_group %}
    + {# 遍历年份分组 #} {% for year in year_post_group %} -
  • {{ year.grouper }} {% trans 'year' %} +
  • + {# 显示年份 + 多语言“年”(如“2023年”)#} + {{ year.grouper }} {% trans 'year' %} + + {# 二次分组:在当前年份下,按发布时间的月份再次分组 #} {% regroup year.list by pub_time.month as month_post_group %}
      + {# 遍历月份分组 #} {% for month in month_post_group %} -
    • {{ month.grouper }} {% trans 'month' %} +
    • + {# 显示月份 + 多语言“月”(如“3月”)#} + {{ month.grouper }} {% trans 'month' %} @@ -49,12 +72,12 @@
- {% endblock %} - +{# 5. 重写sidebar块:加载网站侧边栏 #} {% block sidebar %} + {# 调用自定义标签load_sidebar,加载侧边栏内容 #} + {# 参数说明:user为当前用户对象,'i'可能用于指定侧边栏样式或权限 #} {% load_sidebar user 'i' %} {% endblock %} - diff --git a/templates/blog/article_detail.html b/templates/blog/article_detail.html index a74a0db..7719d3c 100644 --- a/templates/blog/article_detail.html +++ b/templates/blog/article_detail.html @@ -1,52 +1,87 @@ +{# gq: #} +{# 1. 模板继承:复用网站基础布局(包含头部导航、底部信息、全局样式等公共组件)#} {% extends 'share_layout/base.html' %} + +{# 2. 加载自定义博客标签库:提供文章详情渲染、侧边栏加载等专属功能 #} {% load blog_tags %} +{# 3. 重写header块:此处留空,说明文章详情页的头部元信息(如标题、SEO标签)#} +{# 可能通过其他方式(如SEO插件)动态生成,或在base.html中统一处理 #} {% block header %} {% endblock %} + +{# 4. 重写content块:定义文章详情页的核心内容(文章主体、导航、评论区)#} {% block content %} -
-
+
{# 主内容区容器,应用网站全局样式 #} +
{# 核心内容容器,role属性提升无障碍访问性 #} + + {# 渲染文章详情:调用自定义标签load_article_detail #} + {# 参数说明:#} + {# article:当前文章对象(包含标题、内容、发布时间等信息)#} + {# False:控制是否显示编辑按钮(此处为False,仅展示不允许编辑)#} + {# user:当前登录用户对象(用于权限判断,如作者才能编辑)#} {% load_article_detail article False user %} + {# 文章导航(上一篇/下一篇):仅当文章类型为'a'(普通文章)时显示 #} {% if article.type == 'a' %} -
- {% if article.comment_status == "o" and OPEN_SITE_COMMENT %} + {# 评论区:仅当文章允许评论(comment_status == "o")且网站全局开启评论(OPEN_SITE_COMMENT为True)时显示 #} + {% if article.comment_status == "o" and OPEN_SITE_COMMENT %} + {# 引入评论列表模板:展示已有评论 #} {% include 'comments/tags/comment_list.html' %} + + {# 评论表单:根据用户登录状态显示不同内容 #} {% if user.is_authenticated %} + {# 已登录用户:显示评论提交表单 #} {% include 'comments/tags/post_comment.html' %} {% else %} + {# 未登录用户:提示登录后评论,并提供登录入口 #}
-

您还没有登录,请您登录后发表评论。 +

+ 您还没有登录,请您 + {# 登录链接:附带next参数,登录后跳回当前文章页 #} + 登录 + 后发表评论。

- {% load oauth_tags %} - {% load_oauth_applications request %} - + {# 第三方登录入口:加载OAuth登录标签,提供社交账号登录选项 #} + {% load oauth_tags %} {# 加载自定义OAuth标签库 #} + {% load_oauth_applications request %} {# 渲染第三方登录按钮(如GitHub、Google)#}
{% endif %} {% endif %}
- {% endblock %} +{# 5. 重写sidebar块:加载文章详情页专属侧边栏 #} {% block sidebar %} + {# 调用自定义标签load_sidebar,参数"p"可能指定侧边栏样式(如包含热门文章、分类等组件)#} {% load_sidebar user "p" %} {% endblock %} \ No newline at end of file diff --git a/templates/blog/article_index.html b/templates/blog/article_index.html index 0ee6150..d636831 100644 --- a/templates/blog/article_index.html +++ b/templates/blog/article_index.html @@ -1,42 +1,74 @@ +{# gq: #} +{# 1. 模板继承:复用网站基础布局(头部导航、底部信息等公共组件)#} {% extends 'share_layout/base.html' %} -{% load blog_tags %} -{% load cache %} + +{# 2. 加载自定义标签库与缓存工具 #} +{% load blog_tags %} {# 加载博客专属标签库(文章渲染、分页等功能)#} +{% load cache %} {# 加载缓存标签库,可用于缓存页面片段提升性能 #} + +{# 3. 重写header块:动态生成页面标题和SEO元标签 #} {% block header %} + {# 根据是否有筛选条件(标签/分类名称)生成不同标题 #} {% if tag_name %} + {# 有筛选条件时:标题格式为“页面类型:标签名 | 网站描述”#} + {# 例如“分类:技术 | 我的博客”或“标签:Python | 我的博客”#} {{ page_type }}:{{ tag_name }} | {{ SITE_DESCRIPTION }} + {# 注释的描述标签:可根据需要启用,针对筛选结果定制SEO描述 #} {% comment %}{% endcomment %} {% else %} + {# 无筛选条件时:使用网站名称和描述作为标题 #} {{ SITE_NAME }} | {{ SITE_DESCRIPTION }} {% endif %} - - - - - - - + + {# 通用SEO元标签:提升页面在搜索引擎中的表现 #} + {# 网站SEO描述 #} + {# 网站关键词 #} + {# Open Graph协议标签:优化社交平台分享效果 #} + {# 内容类型为博客 #} + {# 社交分享标题 #} + {# 社交分享描述 #} + {# 网站基础URL #} + {# 网站名称 #} {% endblock %} + +{# 4. 重写content块:展示文章列表(支持筛选和分页)#} {% block content %} -
-
+
{# 主内容区容器,应用全局样式 #} +
{# 核心内容容器,提升无障碍访问性 #} + + {# 筛选结果标题:当有筛选条件(如按分类/标签筛选)时显示 #} {% if page_type and tag_name %}
- + {# 显示筛选类型和名称,例如“分类:技术”或“标签:Python”#}

{{ page_type }}:{{ tag_name }}

{% 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_obj:Django分页对象(包含当前页、总页数等信息)#} + {# page_type:页面类型(如“分类”“标签”,用于生成带筛选条件的分页链接)#} + {# tag_name:筛选名称(如分类名、标签名,确保分页时保留筛选条件)#} {% load_pagination_info page_obj page_type tag_name %} - {% endif %}
- {% endblock %} + +{# 5. 重写sidebar块:加载与当前页面匹配的侧边栏 #} {% block sidebar %} + {# 调用自定义标签load_sidebar,参数linktype可能控制侧边栏内容(如热门标签、相关分类)#} {% load_sidebar user linktype %} {% endblock %} \ No newline at end of file diff --git a/templates/blog/error_page.html b/templates/blog/error_page.html index d41cfb6..f4a1d94 100644 --- a/templates/blog/error_page.html +++ b/templates/blog/error_page.html @@ -1,44 +1,63 @@ -{% extends 'share_layout/base.html' %} -{% load blog_tags %} -{% load cache %} +{# gq: #} +{# 1. 模板继承:复用网站基础布局(包含头部导航、底部样式等公共组件)#} +{# 确保错误页面与其他网站风格保持一致,提升用户体验 #} +{% extends 'share_layout/share_layout/base.html' %} + +{# 2. 加载自定义标签库与缓存工具 #} +{% load blog_tags %} {# 加载博客专属标签库,用于侧边栏等组件渲染 #} +{% load cache %} {# 加载缓存标签库,可优化页面加载性能(当前模板未直接使用,预留扩展)#} + +{# 3. 重写header块:根据错误类型动态生成页面标题和SEO元标签 #} {% block header %} + {# 判断是否为错误页面(通过tag_name存在性标识,实际逻辑可能依赖视图传递的状态码)#} {% if tag_name %} + {# 根据状态码动态生成页面标题,适配不同错误场景 #} {% if statuscode == '404' %} - 404 NotFound + 404 NotFound {# 404错误:页面未找到 #} {% elif statuscode == '403' %} - Permission Denied + Permission Denied {# 403错误:权限不足 #} {% elif statuscode == '500' %} - 500 Error + 500 Error {# 500错误:服务器内部错误 #} {% else %} - + {# 其他未定义错误:默认空标题 #} {% endif %} + {# 注释的描述标签:可根据需要启用,针对具体错误场景定制SEO描述 #} {% comment %}{% endcomment %} {% else %} + {# 非错误页面(如正常访问但无筛选条件时):使用网站默认标题 #} {{ SITE_NAME }} | {{ SITE_DESCRIPTION }} {% endif %} - - - - - - - + + {# 通用SEO与社交分享标签:保持与网站其他页面一致的元信息 #} + {# 网站SEO描述 #} + {# 网站关键词 #} + {# Open Graph协议标签:优化社交平台分享时的展示(即使错误页面被分享也能保持品牌一致性)#} + {# 内容类型为博客 #} + {# 社交分享标题 #} + {# 社交分享描述 #} + {# 网站基础URL #} + {# 网站名称 #} {% endblock %} + +{# 4. 重写content块:展示错误提示信息 #} {% block content %} -
-
+
{# 主内容区容器,应用网站全局样式 #} +
{# 核心内容容器,提升无障碍访问性 #} + {# 错误信息头部:使用归档页样式展示错误提示,保持页面结构一致性 #}
+ {# 动态错误消息:{{ message }}由视图传递,显示具体错误描述(如“页面不存在”“您没有访问权限”)#}

{{ message }}

- {% endblock %} - +{# 5. 重写sidebar块:加载网站侧边栏 #} {% block sidebar %} + {# 调用自定义标签load_sidebar加载侧边栏,参数'i'可能指定错误页面专用侧边栏样式 #} + {# 即使在错误页面也显示侧边栏,帮助用户导航到其他正常页面 #} {% load_sidebar user 'i' %} {% endblock %} diff --git a/templates/blog/links_list.html b/templates/blog/links_list.html index ccecbea..8b5eb13 100644 --- a/templates/blog/links_list.html +++ b/templates/blog/links_list.html @@ -1,43 +1,58 @@ +{# gq: #} +{# 1. 模板继承:复用网站基础布局(包含头部导航、底部信息、全局样式等公共组件)#} +{# 确保友情链接页与其他页面风格统一,提升网站整体一致性 #} {% extends 'share_layout/base.html' %} -{% load blog_tags %} -{% load cache %} -{% block header %} - 友情链接 | {{ SITE_DESCRIPTION }} +{# 2. 加载自定义标签库与缓存工具 #} +{% load blog_tags %} {# 加载博客专属标签库,用于侧边栏等组件渲染 #} +{% load cache %} {# 加载缓存标签库,可优化页面加载性能(预留扩展)#} - - - - - - - +{# 3. 重写header块:定义友情链接页的标题和SEO元标签 #} +{% block header %} + {# 页面标题:固定显示“友情链接” + 网站描述,明确页面主题 #} + 友情链接 | {{ SITE_DESCRIPTION }} + {# SEO优化标签:提升页面在搜索引擎中的可见性 #} + {# 网站SEO描述 #} + {# 网站关键词 #} + {# Open Graph协议标签:优化社交平台分享效果,保持品牌一致性 #} + {# 内容类型为博客 #} + {# 社交分享标题 #} + {# 社交分享描述 #} + {# 网站基础URL #} + {# 网站名称 #} {% endblock %} + +{# 4. 重写content块:展示友情链接列表 #} {% block content %} -
-
+
{# 主内容区容器,应用网站全局样式 #} +
{# 核心内容容器,提升无障碍访问性 #} + {# 页面标题区域:明确当前页面为“友情链接” #}
- -

友情链接

+

友情链接

{# 固定标题,直接展示页面主题 #}
-
-
    + {# 友情链接内容区域:以列表形式展示所有链接 #} +
    {# 应用文章内容样式,保持与其他页面的排版一致 #} +
      {# 无序列表:简洁展示链接列表 #} + {# 遍历友情链接对象列表:object_list由视图传递,包含所有友情链接数据 #} {% for obj in object_list %} -
    • +
    • {# 列表项:每个项对应一个友情链接 #} + {# 链接标签:href为友情链接地址,链接文本为网站名称 #} {{ obj.name }}
    • - {% endfor %}
    + {% endfor %} +
- {% endblock %} - +{# 5. 重写sidebar块:加载网站侧边栏 #} {% block sidebar %} + {# 调用自定义标签load_sidebar加载侧边栏,参数'i'可能指定侧边栏样式(如包含网站公告、热门文章等)#} + {# 即使在友情链接页也显示侧边栏,丰富页面内容并引导用户访问其他板块 #} {% load_sidebar user 'i' %} {% endblock %}