Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Anthony
memopol
Commits
2fa87a88
Commit
2fa87a88
authored
Jun 12, 2016
by
Nicolas Joyard
Browse files
Fix URLs on mep pages and enhance fb username extraction
parent
c1aeb29d
Changes
1
Hide whitespace changes
Inline
Side-by-side
memopol/templatetags/memopol_tags.py
View file @
2fa87a88
...
...
@@ -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
())
@
register
.
filter
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
))))
@
register
.
filter
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
=
re
.
search
(
r
'/pages/([^/]+)'
,
clean_url
,
re
.
I
)
return
mark_safe
(
link
.
format
(
network
=
'facebook'
,
url
=
furl
,
label
=
m
.
group
(
1
)
if
m
else
re
.
sub
(
r
'.*/([^/]+)'
,
'
\\
1'
,
clean_url
)))
@
register
.
filter
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
,
label
=
short_url
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment