Improve URL displays
This commit is contained in:
parent
58a7bf5efd
commit
868cfd3cb9
@ -98,7 +98,7 @@
|
||||
<tbody>
|
||||
{% for referrer in stats.referrers %}
|
||||
<tr>
|
||||
<td>{{referrer.referrer|default:"Direct"|urlizetrunc:"40"}}</td>
|
||||
<td>{{referrer.referrer|default:"Direct"|urldisplay}}</td>
|
||||
<td class="rf">{{referrer.count|intcomma}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -3,6 +3,7 @@ from urllib.parse import urlparse
|
||||
import flag
|
||||
from django import template
|
||||
from django.utils import timezone
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import SafeString
|
||||
|
||||
register = template.Library()
|
||||
@ -39,10 +40,10 @@ def startswith(text, starts):
|
||||
|
||||
@register.filter
|
||||
def urldisplay(url):
|
||||
try:
|
||||
parsed = urlparse(url)
|
||||
if url.startswith("http"):
|
||||
display_url = url.replace("http://", "").replace("https://", "")
|
||||
return SafeString(
|
||||
f"<a href='{url}' title='{url}' rel='nofollow'>{parsed.path if len(parsed.path) < 32 else parsed.path[:32] + '…'}</a>"
|
||||
f"<a href='{url}' title='{url}' rel='nofollow'>{escape(display_url if len(display_url) < 40 else display_url[:40] + '...')}</a>"
|
||||
)
|
||||
except:
|
||||
else:
|
||||
return url
|
||||
|
Loading…
Reference in New Issue
Block a user