diff --git a/cps/templates/detail.html b/cps/templates/detail.html index 3121a3e9..3a7c5f6f 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -60,7 +60,7 @@ {% endif %} -

{{entry.title}}

+

{{entry.title|shortentitle(40)}}

{% for author in entry.authors %} {{author.name.replace('|',',')}} diff --git a/cps/templates/discover.html b/cps/templates/discover.html index eab709f6..3466597c 100644 --- a/cps/templates/discover.html +++ b/cps/templates/discover.html @@ -17,7 +17,7 @@

{{entry.title|shortentitle}}

{% for author in entry.authors %} - {{author.name.replace('|',',')}} + {{author.name.replace('|',',')|shortentitle(30)}} {% if not loop.last %} & {% endif %} diff --git a/cps/templates/index.html b/cps/templates/index.html index 436ff10d..2851e707 100755 --- a/cps/templates/index.html +++ b/cps/templates/index.html @@ -18,7 +18,7 @@

{{entry.title|shortentitle}}

-

{{entry.authors[0].name}}

+

{{entry.authors[0].name|shortentitle(30)}}

{% if entry.ratings.__len__() > 0 %}
{% for number in range((entry.ratings[0].rating/2)|int(2)) %} @@ -53,10 +53,10 @@
-

{{entry.title|truncate(60)}}

+

{{entry.title|shortentitle}}

{% for author in entry.authors %} - {{author.name.replace('|',',')}} + {{author.name.replace('|',',')|shortentitle(30)}} {% if not loop.last %} & {% endif %} diff --git a/cps/web.py b/cps/web.py index 55d903c2..714e31ec 100755 --- a/cps/web.py +++ b/cps/web.py @@ -346,12 +346,28 @@ def remote_login_required(f): # custom jinja filters @app.template_filter('shortentitle') -def shortentitle_filter(s): - if len(s) > 60: - s = s.split(':', 1)[0] - if len(s) > 60: - s = textwrap.wrap(s, 60, break_long_words=False)[0] + ' [...]' - return s +def shortentitle_filter(s,nchar=20): + text = s.split() + res = "" # result + sum = 0 # overall length + for line in text: + if sum >= 60: + res += '...' + break + # if word longer than 20 chars truncate line and append '...', otherwise add whole word to result + # string, and summarize total length to stop at 60 chars + if len(line) > nchar: + res += line[:(nchar-3)] + '[..] ' + sum += nchar+3 + else: + res += line + ' ' + sum += len(line) + 1 + return res.strip() + #if len(s) > 20: + # s = s.split(':', 1)[0] + # if len(s) > 20: + # s = textwrap.wrap(s, 20, break_long_words=True)[0] + ' ...' + #return s @app.template_filter('mimetype')