Skip to content

Commit 74f0005

Browse files
committed
description 优化
1 parent b90c902 commit 74f0005

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

blog/templatetags/blog_tags.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ def truncatechars_content(content):
6868
return truncatechars_html(content, settings.ARTICLE_SUB_LENGTH)
6969

7070

71+
@register.filter(is_safe=True)
72+
@stringfilter
73+
def truncate(content):
74+
from django.template.defaultfilters import truncatechars
75+
76+
return truncatechars(content, 150)
77+
78+
7179
@register.inclusion_tag('blog/tags/breadcrumb.html')
7280
def load_breadcrumb(article):
7381
"""
@@ -178,12 +186,13 @@ def load_pagination_info(page_obj, page_type, tag_name):
178186
next_url = reverse('blog:category_detail_page', kwargs={'page': next_number, 'category_name': tag_name})
179187
if page_obj.has_previous():
180188
previous_number = page_obj.previous_page_number()
181-
previous_url = reverse('blog:category_detail_page', kwargs={'page': previous_number, 'category_name': tag_name})
189+
previous_url = reverse('blog:category_detail_page',
190+
kwargs={'page': previous_number, 'category_name': tag_name})
182191

183192
return {
184193
'previous_url': previous_url,
185194
'next_url': next_url,
186-
'page_obj':page_obj
195+
'page_obj': page_obj
187196
}
188197

189198

templates/blog/article_detail.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<title>{{ article.title }} | {{ SITE_DESCRIPTION }}</title>
55
<meta property="og:type" content="article"/>
66
<meta property="og:title" content="{{ article.title }}"/>
7-
<meta property="og:description" content="{{ article.body|truncatewords:100 }}"/>
7+
8+
<meta property="og:description" content="{{ article.body|truncate }}"/>
9+
810
<meta property="og:url"
911
content="{{ article.get_full_url }}"/>
1012
<meta property="article:published_time" content="{% datetimeformat article.pub_time %}"/>

0 commit comments

Comments
 (0)