Add twitter_handle tag

This commit is contained in:
Tobias 2018-11-27 20:45:47 +13:00
parent fe43a26ca5
commit 45b65340e1
2 changed files with 7 additions and 2 deletions

View file

@ -33,7 +33,7 @@
<p>
<strong>{{ speaker }}</strong><br />
{% if speaker.twitter_username %}
<a href="https://twitter.com/{{ speaker.twitter_username }}">{{ speaker.twitter_username }}</a><br />
<a href="https://twitter.com/{{ speaker.twitter_username }}">{{ speaker.twitter_username|twitter_handle }}</a><br />
{% endif %}
{% if speaker.homepage %}
<a href="{{ speaker.homepage }}">{{ speaker.homepage }}</a>

View file

@ -36,4 +36,9 @@ def listlookup(lookup, target):
@register.filter
def clean_text(txt):
# Remove double/triple/+ spaces from `txt` and replace with single space
return re.sub(r' {2,}' , ' ', txt)
return re.sub(r' {2,}' , ' ', txt)
@register.filter
def twitter_handle(txt):
# Add @ to twitter handle if not present
return txt if txt.startswith('@') else '@{}'.format(txt)