mirror of
https://github.com/pelican-plugins/share-post.git
synced 2025-10-15 17:08:54 +02:00
Fix share_post plugin
Firstly, the implemented services only accept unmarked text, so `get_text()` instead of `prettify()` is called. Secondly, `&` is properly escaped ampersand in href URLs.
This commit is contained in:
parent
5c70b46572
commit
9052e10aa7
1 changed files with 7 additions and 9 deletions
|
|
@ -15,11 +15,11 @@ from pelican import signals, contents
|
||||||
|
|
||||||
|
|
||||||
def article_title(content):
|
def article_title(content):
|
||||||
main_title = BeautifulSoup(content.title, 'html.parser').prettify().strip()
|
main_title = BeautifulSoup(content.title, 'html.parser').get_text().strip()
|
||||||
sub_title = ''
|
sub_title = ''
|
||||||
if hasattr(content, 'subtitle'):
|
if hasattr(content, 'subtitle'):
|
||||||
sub_title = BeautifulSoup(content.subtitle, 'html.parser').prettify().strip()
|
sub_title = ' ' + BeautifulSoup(content.subtitle, 'html.parser').get_text().strip()
|
||||||
return quote(('%s %s' % (main_title, sub_title)).encode('utf-8'))
|
return quote(('%s%s' % (main_title, sub_title)).encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
def article_url(content):
|
def article_url(content):
|
||||||
|
|
@ -28,7 +28,7 @@ def article_url(content):
|
||||||
|
|
||||||
|
|
||||||
def article_summary(content):
|
def article_summary(content):
|
||||||
return quote(content.summary.encode('utf-8'))
|
return quote(BeautifulSoup(content.summary, 'html.parser').get_text().strip().encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
def share_post(content):
|
def share_post(content):
|
||||||
|
|
@ -38,13 +38,11 @@ def share_post(content):
|
||||||
url = article_url(content)
|
url = article_url(content)
|
||||||
summary = article_summary(content)
|
summary = article_summary(content)
|
||||||
|
|
||||||
tweet = '%s %s' % (title, url)
|
tweet = quote(('%s %s' % (title, url)).encode('utf-8'))
|
||||||
facebook_link = 'http://www.facebook.com/sharer/sharer.php?s=100' \
|
facebook_link = 'http://www.facebook.com/sharer/sharer.php?s=100&p%%5Burl%%5D=%s' % url
|
||||||
'&p[url]=%s&p[images][0]=&p[title]=%s&p[summary]=%s' \
|
|
||||||
% (url, title, summary)
|
|
||||||
gplus_link = 'https://plus.google.com/share?url=%s' % url
|
gplus_link = 'https://plus.google.com/share?url=%s' % url
|
||||||
twitter_link = 'http://twitter.com/home?status=%s' % tweet
|
twitter_link = 'http://twitter.com/home?status=%s' % tweet
|
||||||
mail_link = 'mailto:?subject=%s&body=%s' % (title, url)
|
mail_link = 'mailto:?subject=%s&body=%s' % (title, url)
|
||||||
|
|
||||||
share_links = {'twitter': twitter_link,
|
share_links = {'twitter': twitter_link,
|
||||||
'facebook': facebook_link,
|
'facebook': facebook_link,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue