mirror of
https://github.com/pelican-plugins/share-post.git
synced 2025-10-15 17:08:54 +02:00
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'))
|
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):
|
def share_post(content):
|
||||||
if isinstance(content, contents.Static):
|
if isinstance(content, contents.Static):
|
||||||
return
|
return
|
||||||
|
|
@ -39,12 +53,14 @@ def share_post(content):
|
||||||
title = article_title(content)
|
title = article_title(content)
|
||||||
url = article_url(content)
|
url = article_url(content)
|
||||||
summary = article_summary(content)
|
summary = article_summary(content)
|
||||||
|
hastags = twitter_hastags(content)
|
||||||
|
via = twitter_via(content)
|
||||||
|
|
||||||
mail_link = 'mailto:?subject=%s&body=%s' % (title, url)
|
mail_link = 'mailto:?subject=%s&body=%s' % (title, url)
|
||||||
diaspora_link = 'https://sharetodiaspora.github.io/?title=%s&url=%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
|
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)
|
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' % (
|
linkedin_link = 'https://www.linkedin.com/shareArticle?mini=true&url=%s&title=%s&summary=%s&source=%s' % (
|
||||||
url, title, summary, url
|
url, title, summary, url
|
||||||
|
|
@ -66,6 +82,8 @@ def run_plugin(generators):
|
||||||
if isinstance(generator, ArticlesGenerator):
|
if isinstance(generator, ArticlesGenerator):
|
||||||
for article in generator.articles:
|
for article in generator.articles:
|
||||||
share_post(article)
|
share_post(article)
|
||||||
|
for translation in article.translations:
|
||||||
|
share_post(translation)
|
||||||
elif isinstance(generator, PagesGenerator):
|
elif isinstance(generator, PagesGenerator):
|
||||||
for page in generator.pages:
|
for page in generator.pages:
|
||||||
share_post(page)
|
share_post(page)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue