diff --git a/README.md b/README.md index e2ccd82..c1651b3 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ -Share Post -========== +# Share Post A Pelican plugin to create share URLs of article +# Author + Copyright (c) Talha Mansoor Author | Talha Mansoor @@ -11,11 +12,12 @@ Author Email | talha131@gmail.com Author Homepage | http://onCrashReboot.com Github Account | https://github.com/talha131 -## Contributors: -* [Jonathan DEKHTIAR](https://github.com/DEKHTIARJonathan) - contact@jonathandekhtiar.eu +### Contributors -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 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 be unobtrusive depending on how Pelican theme uses them. -Requirements -============ +## Requirements `share_post` requires BeautifulSoup @@ -35,8 +36,7 @@ Requirements pip install beautifulsoup4 ``` -How to Use -========== +## How to Use `share_post` adds a dictionary attribute to `article` which can be accessed via `article.share_post`. Keys of the dictionary are as follows, @@ -47,28 +47,29 @@ How to Use 1. `diaspora` 1. `linkedin` 1. `hacker-news` +1. `reddit` -Template Example -================ +## Template Example -```python +```html {% if article.share_post and article.status != 'draft' %}
-

- Share on: - Diaspora* - ❄ - Twitter - ❄ - Facebook - ❄ - LinkedIn - ❄ - HackerNews - ❄ - Email -

+

+ Share on: + Diaspora* + ❄ + Twitter + ❄ + Facebook + ❄ + LinkedIn + ❄ + HackerNews + ❄ + Email + ❄ + Reddit +

{% endif %} ``` - diff --git a/__init__.py b/__init__.py index 428e32a..4185ce8 100644 --- a/__init__.py +++ b/__init__.py @@ -1 +1 @@ -from .share_post import * +from .share_post import * # noqa diff --git a/share_post.py b/share_post.py index 960e4b3..d2a3c64 100644 --- a/share_post.py +++ b/share_post.py @@ -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, }