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
57
README.md
57
README.md
|
|
@ -1,8 +1,9 @@
|
||||||
Share Post
|
# Share Post
|
||||||
==========
|
|
||||||
|
|
||||||
A Pelican plugin to create share URLs of article
|
A Pelican plugin to create share URLs of article
|
||||||
|
|
||||||
|
# Author
|
||||||
|
|
||||||
Copyright (c) Talha Mansoor
|
Copyright (c) Talha Mansoor
|
||||||
|
|
||||||
Author | Talha Mansoor
|
Author | Talha Mansoor
|
||||||
|
|
@ -11,11 +12,12 @@ Author Email | talha131@gmail.com
|
||||||
Author Homepage | http://onCrashReboot.com
|
Author Homepage | http://onCrashReboot.com
|
||||||
Github Account | https://github.com/talha131
|
Github Account | https://github.com/talha131
|
||||||
|
|
||||||
## Contributors:
|
### Contributors
|
||||||
* [Jonathan DEKHTIAR](https://github.com/DEKHTIARJonathan) - contact@jonathandekhtiar.eu
|
|
||||||
|
|
||||||
Why do you need it?
|
* [Jonathan DEKHTIAR](https://github.com/DEKHTIARJonathan) - contact@jonathandekhtiar.eu
|
||||||
===================
|
* [Paolo Melchiorre](https://github.com/pauloxnet) - [www.paulox.net](https://www.paulox.net/)
|
||||||
|
|
||||||
|
## Why do you need it?
|
||||||
|
|
||||||
Almost all website have share widgets to let readers share posts on social
|
Almost all website have share widgets to let readers share posts on social
|
||||||
networks. Most of these widgets are used by vendors for online tracking. These
|
networks. Most of these widgets are used by vendors for online tracking. These
|
||||||
|
|
@ -26,8 +28,7 @@ affect readers attention.
|
||||||
can use. These links do not have the ability to track the users. They can also
|
can use. These links do not have the ability to track the users. They can also
|
||||||
be unobtrusive depending on how Pelican theme uses them.
|
be unobtrusive depending on how Pelican theme uses them.
|
||||||
|
|
||||||
Requirements
|
## Requirements
|
||||||
============
|
|
||||||
|
|
||||||
`share_post` requires BeautifulSoup
|
`share_post` requires BeautifulSoup
|
||||||
|
|
||||||
|
|
@ -35,8 +36,7 @@ Requirements
|
||||||
pip install beautifulsoup4
|
pip install beautifulsoup4
|
||||||
```
|
```
|
||||||
|
|
||||||
How to Use
|
## How to Use
|
||||||
==========
|
|
||||||
|
|
||||||
`share_post` adds a dictionary attribute to `article` which can be accessed via
|
`share_post` adds a dictionary attribute to `article` which can be accessed via
|
||||||
`article.share_post`. Keys of the dictionary are as follows,
|
`article.share_post`. Keys of the dictionary are as follows,
|
||||||
|
|
@ -47,28 +47,29 @@ How to Use
|
||||||
1. `diaspora`
|
1. `diaspora`
|
||||||
1. `linkedin`
|
1. `linkedin`
|
||||||
1. `hacker-news`
|
1. `hacker-news`
|
||||||
|
1. `reddit`
|
||||||
|
|
||||||
Template Example
|
## Template Example
|
||||||
================
|
|
||||||
|
|
||||||
```python
|
```html
|
||||||
{% if article.share_post and article.status != 'draft' %}
|
{% if article.share_post and article.status != 'draft' %}
|
||||||
<section>
|
<section>
|
||||||
<p id="post-share-links">
|
<p id="post-share-links">
|
||||||
Share on:
|
Share on:
|
||||||
<a href="{{article.share_post['diaspora']}}" target="_blank" title="Share on Diaspora">Diaspora*</a>
|
<a href="{{article.share_post['diaspora']}}" target="_blank" title="Share on Diaspora">Diaspora*</a>
|
||||||
❄
|
❄
|
||||||
<a href="{{article.share_post['twitter']}}" target="_blank" title="Share on Twitter">Twitter</a>
|
<a href="{{article.share_post['twitter']}}" target="_blank" title="Share on Twitter">Twitter</a>
|
||||||
❄
|
❄
|
||||||
<a href="{{article.share_post['facebook']}}" target="_blank" title="Share on Facebook">Facebook</a>
|
<a href="{{article.share_post['facebook']}}" target="_blank" title="Share on Facebook">Facebook</a>
|
||||||
❄
|
❄
|
||||||
<a href="{{article.share_post['linkedin']}}" target="_blank" title="Share on LinkedIn">LinkedIn</a>
|
<a href="{{article.share_post['linkedin']}}" target="_blank" title="Share on LinkedIn">LinkedIn</a>
|
||||||
❄
|
❄
|
||||||
<a href="{{article.share_post['hacker-news']}}" target="_blank" title="Share on HackerNews">HackerNews</a>
|
<a href="{{article.share_post['hacker-news']}}" target="_blank" title="Share on HackerNews">HackerNews</a>
|
||||||
❄
|
❄
|
||||||
<a href="{{article.share_post['email']}}" target="_blank" title="Share via Email">Email</a>
|
<a href="{{article.share_post['email']}}" target="_blank" title="Share via Email">Email</a>
|
||||||
</p>
|
❄
|
||||||
|
<a href="{{article.share_post['reddit']}}" target="_blank" title="Share via Reddit">Reddit</a>
|
||||||
|
</p>
|
||||||
</section>
|
</section>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
from .share_post import *
|
from .share_post import * # noqa
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,26 @@
|
||||||
"""
|
"""
|
||||||
Share Post
|
Share Post plugin.
|
||||||
==========
|
|
||||||
|
|
||||||
This plugin adds share URL to article. These links are textual which means no
|
This plugin adds share URL to article. These links are textual which means no
|
||||||
online tracking of your readers.
|
online tracking of your readers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
from pelican import contents, signals
|
||||||
|
from pelican.generators import ArticlesGenerator, PagesGenerator
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urllib import quote
|
from urllib import quote
|
||||||
from pelican import signals, contents
|
|
||||||
from pelican.generators import ArticlesGenerator, PagesGenerator
|
|
||||||
|
|
||||||
|
|
||||||
def article_title(content):
|
def article_title(content):
|
||||||
main_title = BeautifulSoup(content.title, 'html.parser').get_text().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').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'))
|
return quote(('%s%s' % (main_title, sub_title)).encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -29,14 +30,11 @@ def article_url(content):
|
||||||
|
|
||||||
|
|
||||||
def article_summary(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):
|
def twitter_hastags(content):
|
||||||
tags = getattr(content, 'tags', [])
|
tags = getattr(content, 'tags', [])
|
||||||
category = getattr(content, 'category', '')
|
|
||||||
if category:
|
|
||||||
tags.append(category)
|
|
||||||
hashtags = ','.join((tag.slug for tag in tags))
|
hashtags = ','.join((tag.slug for tag in tags))
|
||||||
return '' if not hashtags else '&hashtags=%s' % hashtags
|
return '' if not hashtags else '&hashtags=%s' % hashtags
|
||||||
|
|
||||||
|
|
@ -50,28 +48,34 @@ def share_post(content):
|
||||||
if isinstance(content, contents.Static):
|
if isinstance(content, contents.Static):
|
||||||
return
|
return
|
||||||
|
|
||||||
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)
|
hastags = twitter_hastags(content)
|
||||||
via = twitter_via(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' % (
|
||||||
facebook_link = 'https://www.facebook.com/sharer/sharer.php?u=%s' % url
|
title, url)
|
||||||
twitter_link = 'https://twitter.com/intent/tweet?text=%s&url=%s%s%s' % (title, url, via, hastags)
|
facebook_link = 'https://www.facebook.com/sharer/sharer.php?u=%s' % url
|
||||||
hackernews_link = 'https://news.ycombinator.com/submitlink?t=%s&u=%s' % (title, url)
|
twitter_link = 'https://twitter.com/intent/tweet?text=%s&url=%s%s%s' % (
|
||||||
linkedin_link = 'https://www.linkedin.com/shareArticle?mini=true&url=%s&title=%s&summary=%s&source=%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
|
url, title, summary, url
|
||||||
)
|
)
|
||||||
|
reddit_link = 'https://www.reddit.com/submit?url=%s&title=%s' % (
|
||||||
|
url, title)
|
||||||
|
|
||||||
content.share_post = {
|
content.share_post = {
|
||||||
'diaspora' : diaspora_link,
|
'diaspora': diaspora_link,
|
||||||
'twitter' : twitter_link,
|
'twitter': twitter_link,
|
||||||
'facebook' : facebook_link,
|
'facebook': facebook_link,
|
||||||
'linkedin' : linkedin_link,
|
'linkedin': linkedin_link,
|
||||||
'hacker-news': hackernews_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