mirror of
https://gitlab.com/brutaldon/brutaldon
synced 2025-06-05 21:49:32 +02:00
Link in tags to tag timeline.
Currently, only tags in toots from Mastodon servers are relinked, because they use a consistent and easy-to-support heuristic.
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
{% load humanize %}
|
{% load humanize %}
|
||||||
{% load sanitizer %}
|
{% load sanitizer %}
|
||||||
|
{% load taglinks %}
|
||||||
|
|
||||||
<article class="media">
|
<article class="media">
|
||||||
<figure class="media-left">
|
<figure class="media-left">
|
||||||
@ -32,7 +33,7 @@
|
|||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="toot">
|
<div class="toot">
|
||||||
{{ toot.content | strip_html | safe }}
|
{{ toot.content |relink_toot | strip_html | safe }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if toot.media_attachments %}
|
{% if toot.media_attachments %}
|
||||||
|
0
brutaldon/templatetags/__init__.py
Normal file
0
brutaldon/templatetags/__init__.py
Normal file
25
brutaldon/templatetags/taglinks.py
Normal file
25
brutaldon/templatetags/taglinks.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
from django import template
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from urllib import parse
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def relink_tags(value):
|
||||||
|
'''Treat the text as html, and replace tag links with app-internal tag links
|
||||||
|
|
||||||
|
Currently, this only works for tags in toots coming from Mastodon servers,
|
||||||
|
not necessarily GNU Social, Pleroma, or other fediverse servers, because
|
||||||
|
it relies on the markup that Mastodon puts on tags.
|
||||||
|
|
||||||
|
FIXME: handle arbitrary tag lengths.
|
||||||
|
'''
|
||||||
|
soup = BeautifulSoup(value, 'html.parser')
|
||||||
|
for link in soup.find_all('a', class_='hashtag'):
|
||||||
|
link['href'] = reverse('tag', args=[link.span.string])
|
||||||
|
return str(soup)
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def relink_toot(value):
|
||||||
|
return relink_tags(value)
|
@ -1,12 +1,15 @@
|
|||||||
|
beautifulsoup4==4.6.0
|
||||||
bleach==2.1.3
|
bleach==2.1.3
|
||||||
certifi==2017.11.5
|
certifi==2017.11.5
|
||||||
chardet==3.0.4
|
chardet==3.0.4
|
||||||
decorator==4.1.2
|
decorator==4.1.2
|
||||||
Django==2.0.4
|
Django==2.0.4
|
||||||
django-html-sanitizer==0.1.5
|
django-html-sanitizer==0.1.5
|
||||||
|
django-markdownify==0.8.0
|
||||||
django-widget-tweaks==1.4.2
|
django-widget-tweaks==1.4.2
|
||||||
html5lib==1.0.1
|
html5lib==1.0.1
|
||||||
idna==2.6
|
idna==2.6
|
||||||
|
Markdown==2.6.11
|
||||||
Mastodon.py==1.2.1
|
Mastodon.py==1.2.1
|
||||||
python-dateutil==2.6.1
|
python-dateutil==2.6.1
|
||||||
pytz==2017.3
|
pytz==2017.3
|
||||||
|
Reference in New Issue
Block a user