Skip to content

Commit f3e262f

Browse files
committed
feat(sharing): Enable customizing the sharing links
Previously the sharing links were fixed at twitter, facebook, email. This patch makes it possible to opt in and out of the networks supported by the share_post plug-in.
1 parent e431642 commit f3e262f

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

documentation/content/Supported Plugins/share-post-plugin.md

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ configuration variable in your Pelican configuration.
3535
PLUGINS = ['share_post']
3636
```
3737

38+
Optionally, customize the list of networks where the article can be shared using `SHARE_LINKS`.
39+
40+
```python
41+
SHARE_LINKS = [ ('twitter', 'Twitter'), ('facebook', 'Facebook'), ('email', 'Email') ]
42+
```
43+
44+
The first item in each pair refers to a network recognized by `share_post`. Currently the list of supported networks includes `twitter`, `facebook`, `email`, `hacker-news`, `linkedin` and `reddit`. The second item in each pair is the text displayed for the link on the page.
45+
46+
The sharing links are displayed in the order of `SHARE_LINKS`, therefore this variable can also be used to customize the link order.
47+
3848
!!! note
3949

4050
The [share_post plugin](https://github.com/getpelican/pelican-plugins/blob/master/share_post/README.md) requires the Python `beautifulsoup4` package to be installed.

documentation/pelicanconf.py

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@
122122
"Documentation of Elegant, a theme for Pelican, originally created by Talha Mansoor"
123123
)
124124

125+
# Share links at bottom of articles
126+
# Supported: twitter, facebook, hacker-news, reddit, linkedin, email
127+
SHARE_LINKS = [ ('twitter', 'Twitter'), ('facebook', 'Facebook'), ('email', 'Email') ]
128+
125129
# Landing Page
126130
PROJECTS_TITLE = "Related Projects"
127131
PROJECTS = [

templates/_includes/_defaults.html

+6
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,9 @@
224224
{% else %}
225225
{% set APPLAUSE_BUTTON = APPLAUSE_BUTTON %}
226226
{% endif %}
227+
228+
{% if not SHARE_LINKS %}
229+
{% set SHARE_LINKS = [ ('twitter', 'Twitter'), ('facebook', 'Facebook'), ('email', 'Email') ] %}
230+
{% else %}
231+
{% set SHARE_LINKS = SHARE_LINKS %}
232+
{% endif %}

templates/_includes/share_links.html

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
{% macro share_links(article) %}
2-
{% if article.share_post and article.status != 'draft' %}
2+
{% from '_includes/_defaults.html' import SHARE_LINKS with context %}
3+
{% if article.share_post and article.status != 'draft' and SHARE_LINKS %}
34
<p id="post-share-links">
45
{% if article.share_post_intro %}
56
{{ article.share_post_intro }}
67
{% else %}
78
{% from '_includes/_defaults.html' import SHARE_POST_INTRO with context %}
89
{{ SHARE_POST_INTRO }}
910
{% endif %}
10-
<a href="{{ article.share_post['twitter'] }}" target="_blank" rel="nofollow noopener noreferrer" title="Share on Twitter">Twitter</a>
11-
12-
<a href="{{ article.share_post['facebook'] }}" target="_blank" rel="nofollow noopener noreferrer" title="Share on Facebook">Facebook</a>
13-
14-
<a href="{{ article.share_post['email'] }}" target="_blank" rel="nofollow noopener noreferrer" title="Share via Email">Email</a>
15-
</p>
11+
{% for network, label in SHARE_LINKS %}
12+
{% if not loop.first %} ❄ {% endif %}
13+
<a href="{{ article.share_post[network] }}" target="_blank" rel="nofollow noopener noreferrer" title="Share {% if network == 'email' %}via{% else %}on{% endif %} {{ label }}">{{ label }}</a>
14+
{% endfor %}
1615
{% endif %}
1716
{% endmacro %}

0 commit comments

Comments
 (0)