Commit 2fa87a88 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Fix URLs on mep pages and enhance fb username extraction

parent c1aeb29d
......@@ -16,22 +16,32 @@ def cssify(string):
return re.sub('[^a-z_-]', '', string.lower())
def fix_url(url):
# Ensure we have a usable URL
return re.sub('^(https?://)?', 'https://', url.strip())
def twitter_link(url):
return mark_safe(link.format(network='twitter', url=url,
label=re.sub(r'.*/@?([^/]+)', '@\\1', re.sub(r'/$', '', url.strip()))))
furl = fix_url(url)
return mark_safe(link.format(network='twitter', url=furl,
label=re.sub(r'.*/@?([^/]+)', '@\\1', re.sub(r'/$', '', furl))))
def facebook_link(url):
return mark_safe(link.format(network='facebook', url=url,
label=re.sub(r'.*/([^/]+)', '\\1', re.sub(r'/$', '', url.strip()))))
furl = fix_url(url)
clean_url = re.sub(r'/$', '', re.sub(r'\?.*', '', furl))
m ='/pages/([^/]+)', clean_url, re.I)
return mark_safe(link.format(network='facebook', url=furl, if m else re.sub(r'.*/([^/]+)', '\\1', clean_url)))
def website_link(url):
short_url = re.sub(r'^https?://([^/]+).*', '\\1', url)
return mark_safe(link.format(network='website', url=url,
furl = fix_url(url)
short_url = re.sub(r'^https?://([^/]+).*', '\\1', furl)
return mark_safe(link.format(network='website', url=furl,
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment