Compare commits
2 Commits
6ed045e292
...
200373e42f
| Author | SHA256 | Date | |
|---|---|---|---|
| 200373e42f | |||
| 4d0ea1a55b |
@@ -34,12 +34,12 @@ def index(request):
|
|||||||
|
|
||||||
posts = posts.order_by('-publish_date').distinct()
|
posts = posts.order_by('-publish_date').distinct()
|
||||||
|
|
||||||
# 为每篇文章添加摘要(前200个字符)
|
# 为每篇文章添加摘要(前50个字符)
|
||||||
for post in posts:
|
for post in posts:
|
||||||
# 移除HTML标签并截取前200个字符作为摘要
|
# 移除HTML标签并截取前50个字符作为摘要
|
||||||
import re
|
import re
|
||||||
clean_content = re.sub(r'<[^>]+>', '', post.get_markdown_content())
|
clean_content = re.sub(r'<[^>]+>', '', post.get_markdown_content())
|
||||||
post.summary = clean_content[:200] + '...' if len(clean_content) > 200 else clean_content
|
post.summary = clean_content[:50] + '...' if len(clean_content) > 50 else clean_content
|
||||||
|
|
||||||
return render(request, 'blog/index.html', {
|
return render(request, 'blog/index.html', {
|
||||||
'posts': posts,
|
'posts': posts,
|
||||||
|
|||||||
Reference in New Issue
Block a user