Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deploy/k8s/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions djangoblog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down
8 changes: 8 additions & 0 deletions plugins/reading_time/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions templates/comments/tags/comment_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
<li class="comment even thread-even depth-{{ depth }} parent" id="comment-{{ comment_item.pk }}">
<div id="div-comment-{{ comment_item.pk }}" class="comment-body">
<div class="comment-author vcard">
<img alt=""
<img alt="{{ comment_item.author.username }}的头像"
src="{{ comment_item.author.email|gravatar_url:150 }}"
srcset="{{ comment_item.author.email|gravatar_url:150 }}"
class="avatar avatar-96 photo">
class="avatar avatar-96 photo"
loading="lazy"
decoding="async"
style="max-width:100%;height:auto;">
<cite class="fn">
<a rel="nofollow"
{% if comment_item.author.is_superuser %}
Expand Down
7 changes: 5 additions & 2 deletions templates/comments/tags/comment_item_tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
style="margin-left: {% widthratio depth 1 3 %}rem">
<div id="div-comment-{{ comment_item.pk }}" class="comment-body">
<div class="comment-author vcard">
<img alt=""
<img alt="{{ comment_item.author.username }}的头像"
src="{{ comment_item.author.email|gravatar_url:150 }}"
srcset="{{ comment_item.author.email|gravatar_url:150 }}"
class="avatar avatar-96 photo">
class="avatar avatar-96 photo"
loading="lazy"
decoding="async"
style="max-width:100%;height:auto;">
<cite class="fn">
<a rel="nofollow"
{% if comment_item.author.is_superuser %}
Expand Down