mirror of
https://github.com/pelican-plugins/share-post.git
synced 2025-10-15 17:08:54 +02:00
Fix #1121 Add reddit to share post plugin
This commit is contained in:
parent
13e2184d82
commit
d1c511e038
3 changed files with 55 additions and 50 deletions
|
|
@ -1,25 +1,26 @@
|
|||
"""
|
||||
Share Post
|
||||
==========
|
||||
Share Post plugin.
|
||||
|
||||
This plugin adds share URL to article. These links are textual which means no
|
||||
online tracking of your readers.
|
||||
"""
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from pelican import contents, signals
|
||||
from pelican.generators import ArticlesGenerator, PagesGenerator
|
||||
|
||||
try:
|
||||
from urllib.parse import quote
|
||||
except ImportError:
|
||||
from urllib import quote
|
||||
from pelican import signals, contents
|
||||
from pelican.generators import ArticlesGenerator, PagesGenerator
|
||||
|
||||
|
||||
def article_title(content):
|
||||
main_title = BeautifulSoup(content.title, 'html.parser').get_text().strip()
|
||||
sub_title = ''
|
||||
if hasattr(content, 'subtitle'):
|
||||
sub_title = ' ' + BeautifulSoup(content.subtitle, 'html.parser').get_text().strip()
|
||||
sub_title = ' ' + BeautifulSoup(content.subtitle, 'html.parser').get_text().strip() # noqa
|
||||
return quote(('%s%s' % (main_title, sub_title)).encode('utf-8'))
|
||||
|
||||
|
||||
|
|
@ -29,14 +30,11 @@ def article_url(content):
|
|||
|
||||
|
||||
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')) # noqa
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -50,28 +48,34 @@ def share_post(content):
|
|||
if isinstance(content, contents.Static):
|
||||
return
|
||||
|
||||
title = article_title(content)
|
||||
url = article_url(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 = 'https://www.facebook.com/sharer/sharer.php?u=%s' % 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' % (
|
||||
mail_link = 'mailto:?subject=%s&body=%s' % (title, url)
|
||||
diaspora_link = 'https://sharetodiaspora.github.io/?title=%s&url=%s' % (
|
||||
title, url)
|
||||
facebook_link = 'https://www.facebook.com/sharer/sharer.php?u=%s' % 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' % ( # noqa
|
||||
url, title, summary, url
|
||||
)
|
||||
reddit_link = 'https://www.reddit.com/submit?url=%s&title=%s' % (
|
||||
url, title)
|
||||
|
||||
content.share_post = {
|
||||
'diaspora' : diaspora_link,
|
||||
'twitter' : twitter_link,
|
||||
'facebook' : facebook_link,
|
||||
'linkedin' : linkedin_link,
|
||||
'diaspora': diaspora_link,
|
||||
'twitter': twitter_link,
|
||||
'facebook': facebook_link,
|
||||
'linkedin': linkedin_link,
|
||||
'hacker-news': hackernews_link,
|
||||
'email' : mail_link
|
||||
'email': mail_link,
|
||||
'reddit': reddit_link,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue