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