forked from github/share-post
Improve translations and facebook/twitter links
This commit is contained in:
parent
5b64414f79
commit
de3397633c
1 changed files with 20 additions and 2 deletions
|
|
@ -32,6 +32,20 @@ def article_summary(content):
|
|||
return quote(BeautifulSoup(content.summary, 'html.parser').get_text().strip().encode('utf-8'))
|
||||
|
||||
|
||||
def twitter_hastags(content):
|
||||
tags = getattr(content, 'tags', [])
|
||||
category = getattr(content, 'category', '')
|
||||
if category:
|
||||
tags.append(category)
|
||||
hashtags = ','.join((tag.slug for tag in tags))
|
||||
return '' if not hashtags else '&hashtags=%s' % hashtags
|
||||
|
||||
|
||||
def twitter_via(content):
|
||||
twitter_username = content.settings.get('TWITTER_USERNAME', '')
|
||||
return '' if not twitter_username else '&via=%s' % twitter_username
|
||||
|
||||
|
||||
def share_post(content):
|
||||
if isinstance(content, contents.Static):
|
||||
return
|
||||
|
|
@ -39,12 +53,14 @@ def share_post(content):
|
|||
title = article_title(content)
|
||||
url = article_url(content)
|
||||
summary = article_summary(content)
|
||||
hastags = twitter_hastags(content)
|
||||
via = twitter_via(content)
|
||||
|
||||
mail_link = 'mailto:?subject=%s&body=%s' % (title, url)
|
||||
diaspora_link = 'https://sharetodiaspora.github.io/?title=%s&url=%s' % (title, url)
|
||||
facebook_link = 'http://www.facebook.com/sharer/sharer.php?u=%s' % url
|
||||
facebook_link = 'https://www.facebook.com/sharer/sharer.php?u=%s' % url
|
||||
gplus_link = 'https://plus.google.com/share?url=%s' % url
|
||||
twitter_link = 'https://twitter.com/intent/tweet?text=%s&url=%s' % (title, url)
|
||||
twitter_link = 'https://twitter.com/intent/tweet?text=%s&url=%s%s%s' % (title, url, via, hastags)
|
||||
hackernews_link = 'https://news.ycombinator.com/submitlink?t=%s&u=%s' % (title, url)
|
||||
linkedin_link = 'https://www.linkedin.com/shareArticle?mini=true&url=%s&title=%s&summary=%s&source=%s' % (
|
||||
url, title, summary, url
|
||||
|
|
@ -66,6 +82,8 @@ def run_plugin(generators):
|
|||
if isinstance(generator, ArticlesGenerator):
|
||||
for article in generator.articles:
|
||||
share_post(article)
|
||||
for translation in article.translations:
|
||||
share_post(translation)
|
||||
elif isinstance(generator, PagesGenerator):
|
||||
for page in generator.pages:
|
||||
share_post(page)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue