优化文集列表文集简介文本显示

This commit is contained in:
yangjian 2023-09-23 08:03:15 +08:00
parent 59ef79e445
commit 63d4d3ee10
2 changed files with 11 additions and 3 deletions

View File

@ -3,6 +3,8 @@
from app_doc.models import * from app_doc.models import *
from django import template from django import template
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils.html import strip_tags
import markdown
register = template.Library() register = template.Library()
@ -58,4 +60,10 @@ def get_project_collaborator_cnt(value):
@register.filter(name='tag_doc_cnt') @register.filter(name='tag_doc_cnt')
def get_img_group_cnt(value): def get_img_group_cnt(value):
cnt = DocTag.objects.filter(tag=value).count() cnt = DocTag.objects.filter(tag=value).count()
return cnt return cnt
# 获取文集简介的纯文本
@register.filter(name='project_desc')
def get_project_desc(value):
value = strip_tags(markdown.markdown(value))[:201]
return value

View File

@ -168,8 +168,8 @@
{% if p.intro == "" %} {% if p.intro == "" %}
<span class="">{% trans "此文集没有填写简介" %}</span> <span class="">{% trans "此文集没有填写简介" %}</span>
{% else %} {% else %}
<span class="">{{ p.intro | slice:'20' }}…</span> <span class="">{{ p.intro | project_desc | slice:'20' }}…</span>
<span class="tooltip-content clearfix">{{ p.intro | slice:'100' }}</span> <span class="tooltip-content clearfix">{{ p.intro | project_desc | slice:'100' }}</span>
{% endif %} {% endif %}
</p> </p>
{% for new_doc in p.id|get_new_doc %} {% for new_doc in p.id|get_new_doc %}