Skip to content

Commit ca320b0

Browse files
committed
一些小优化
1 parent 44bed3e commit ca320b0

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

deploy/k8s/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ spec:
2626
name: djangoblog-env
2727
readinessProbe:
2828
httpGet:
29-
path: /
29+
path: /health/
3030
port: 8000
3131
initialDelaySeconds: 10
3232
periodSeconds: 30
3333
livenessProbe:
3434
httpGet:
35-
path: /
35+
path: /health/
3636
port: 8000
3737
initialDelaySeconds: 10
3838
periodSeconds: 30

djangoblog/urls.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from django.urls import path, include
2121
from django.urls import re_path
2222
from haystack.views import search_view_factory
23+
from django.http import JsonResponse
24+
import time
2325

2426
from blog.views import EsSearchView
2527
from djangoblog.admin_site import admin_site
@@ -40,8 +42,20 @@
4042
handler500 = 'blog.views.server_error_view'
4143
handle403 = 'blog.views.permission_denied_view'
4244

45+
46+
def health_check(request):
47+
"""
48+
健康检查接口
49+
简单返回服务健康状态
50+
"""
51+
return JsonResponse({
52+
'status': 'healthy',
53+
'timestamp': time.time()
54+
})
55+
4356
urlpatterns = [
4457
path('i18n/', include('django.conf.urls.i18n')),
58+
path('health/', health_check, name='health_check'),
4559
]
4660
urlpatterns += i18n_patterns(
4761
re_path(r'^admin/', admin_site.urls),

plugins/reading_time/plugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ def register_hooks(self):
1717
def add_reading_time(self, content, *args, **kwargs):
1818
"""
1919
计算阅读时间并添加到内容开头。
20+
只在文章详情页显示,首页(文章列表页)不显示。
2021
"""
22+
# 检查是否为摘要模式(首页/文章列表页)
23+
# 通过kwargs中的is_summary参数判断
24+
is_summary = kwargs.get('is_summary', False)
25+
if is_summary:
26+
# 如果是摘要模式(首页),直接返回原内容,不添加阅读时间
27+
return content
28+
2129
# 移除HTML标签和空白字符,以获得纯文本
2230
clean_content = re.sub(r'<[^>]*>', '', content)
2331
clean_content = clean_content.strip()

templates/comments/tags/comment_item.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
<li class="comment even thread-even depth-{{ depth }} parent" id="comment-{{ comment_item.pk }}">
33
<div id="div-comment-{{ comment_item.pk }}" class="comment-body">
44
<div class="comment-author vcard">
5-
<img alt=""
5+
<img alt="{{ comment_item.author.username }}的头像"
66
src="{{ comment_item.author.email|gravatar_url:150 }}"
77
srcset="{{ comment_item.author.email|gravatar_url:150 }}"
8-
class="avatar avatar-96 photo">
8+
class="avatar avatar-96 photo"
9+
loading="lazy"
10+
decoding="async"
11+
style="max-width:100%;height:auto;">
912
<cite class="fn">
1013
<a rel="nofollow"
1114
{% if comment_item.author.is_superuser %}

templates/comments/tags/comment_item_tree.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
style="margin-left: {% widthratio depth 1 3 %}rem">
44
<div id="div-comment-{{ comment_item.pk }}" class="comment-body">
55
<div class="comment-author vcard">
6-
<img alt=""
6+
<img alt="{{ comment_item.author.username }}的头像"
77
src="{{ comment_item.author.email|gravatar_url:150 }}"
88
srcset="{{ comment_item.author.email|gravatar_url:150 }}"
9-
class="avatar avatar-96 photo">
9+
class="avatar avatar-96 photo"
10+
loading="lazy"
11+
decoding="async"
12+
style="max-width:100%;height:auto;">
1013
<cite class="fn">
1114
<a rel="nofollow"
1215
{% if comment_item.author.is_superuser %}

0 commit comments

Comments
 (0)