1
0
mirror of https://gitlab.com/brutaldon/brutaldon synced 2024-12-28 08:41:52 +01: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:
Jason McBrayer 2018-05-07 08:46:59 -04:00
parent 7b4c449179
commit 63cea9be14
4 changed files with 30 additions and 1 deletions

View File

@ -1,5 +1,6 @@
{% load humanize %}
{% load sanitizer %}
{% load taglinks %}
<article class="media">
<figure class="media-left">
@ -32,7 +33,7 @@
</p>
{% endif %}
<div class="toot">
{{ toot.content | strip_html | safe }}
{{ toot.content |relink_toot | strip_html | safe }}
</div>
{% if toot.media_attachments %}

View File

View 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)

View File

@ -1,12 +1,15 @@
beautifulsoup4==4.6.0
bleach==2.1.3
certifi==2017.11.5
chardet==3.0.4
decorator==4.1.2
Django==2.0.4
django-html-sanitizer==0.1.5
django-markdownify==0.8.0
django-widget-tweaks==1.4.2
html5lib==1.0.1
idna==2.6
Markdown==2.6.11
Mastodon.py==1.2.1
python-dateutil==2.6.1
pytz==2017.3