From ca320b0965c36f3982a2142e2e4788e045235ed6 Mon Sep 17 00:00:00 2001 From: liangliangyy Date: Mon, 29 Sep 2025 11:33:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=B0=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/k8s/deployment.yaml | 4 ++-- djangoblog/urls.py | 14 ++++++++++++++ plugins/reading_time/plugin.py | 8 ++++++++ templates/comments/tags/comment_item.html | 7 +++++-- templates/comments/tags/comment_item_tree.html | 7 +++++-- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/deploy/k8s/deployment.yaml b/deploy/k8s/deployment.yaml index 414fdcc5..b50c4113 100644 --- a/deploy/k8s/deployment.yaml +++ b/deploy/k8s/deployment.yaml @@ -26,13 +26,13 @@ spec: name: djangoblog-env readinessProbe: httpGet: - path: / + path: /health/ port: 8000 initialDelaySeconds: 10 periodSeconds: 30 livenessProbe: httpGet: - path: / + path: /health/ port: 8000 initialDelaySeconds: 10 periodSeconds: 30 diff --git a/djangoblog/urls.py b/djangoblog/urls.py index 4aae58a6..6a9e1de6 100644 --- a/djangoblog/urls.py +++ b/djangoblog/urls.py @@ -20,6 +20,8 @@ from django.urls import path, include from django.urls import re_path from haystack.views import search_view_factory +from django.http import JsonResponse +import time from blog.views import EsSearchView from djangoblog.admin_site import admin_site @@ -40,8 +42,20 @@ handler500 = 'blog.views.server_error_view' handle403 = 'blog.views.permission_denied_view' + +def health_check(request): + """ + 健康检查接口 + 简单返回服务健康状态 + """ + return JsonResponse({ + 'status': 'healthy', + 'timestamp': time.time() + }) + urlpatterns = [ path('i18n/', include('django.conf.urls.i18n')), + path('health/', health_check, name='health_check'), ] urlpatterns += i18n_patterns( re_path(r'^admin/', admin_site.urls), diff --git a/plugins/reading_time/plugin.py b/plugins/reading_time/plugin.py index 35f9db12..4b929d83 100644 --- a/plugins/reading_time/plugin.py +++ b/plugins/reading_time/plugin.py @@ -17,7 +17,15 @@ def register_hooks(self): def add_reading_time(self, content, *args, **kwargs): """ 计算阅读时间并添加到内容开头。 + 只在文章详情页显示,首页(文章列表页)不显示。 """ + # 检查是否为摘要模式(首页/文章列表页) + # 通过kwargs中的is_summary参数判断 + is_summary = kwargs.get('is_summary', False) + if is_summary: + # 如果是摘要模式(首页),直接返回原内容,不添加阅读时间 + return content + # 移除HTML标签和空白字符,以获得纯文本 clean_content = re.sub(r'<[^>]*>', '', content) clean_content = clean_content.strip() diff --git a/templates/comments/tags/comment_item.html b/templates/comments/tags/comment_item.html index 66ec2678..06936496 100644 --- a/templates/comments/tags/comment_item.html +++ b/templates/comments/tags/comment_item.html @@ -2,10 +2,13 @@
  • - + class="avatar avatar-96 photo" + loading="lazy" + decoding="async" + style="max-width:100%;height:auto;">
    - + class="avatar avatar-96 photo" + loading="lazy" + decoding="async" + style="max-width:100%;height:auto;">