Skip to content

Commit eb572aa

Browse files
committed
Refactor social share solution
Removes share_url include and includes share URL previs in datalist
1 parent b609e9b commit eb572aa

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ projects:
2727
projects:
2828
# - repo-name
2929

30-
social_media:
30+
# social_media:
3131
# behance: your_username
3232
# facebook: your_username
3333
# dribbble: your_username

_data/social_media.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ behance:
66
facebook:
77
name: Facebook
88
profile_url_prefix: https://www.facebook.com/
9+
share_url_prefix: https://www.facebook.com/sharer/sharer.php?u=
910
icon_svg: '<svg height="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 15.3 15.4"><path d="M14.5 0H.8a.88.88 0 0 0-.8.9v13.6a.88.88 0 0 0 .8.9h7.3v-6h-2V7.1h2V5.4a2.87 2.87 0 0 1 2.5-3.1h.5a10.87 10.87 0 0 1 1.8.1v2.1h-1.3c-1 0-1.1.5-1.1 1.1v1.5h2.3l-.3 2.3h-2v5.9h3.9a.88.88 0 0 0 .9-.8V.8a.86.86 0 0 0-.8-.8z" fill="#959da5"/></svg>'
1011

1112
linkedin:
1213
name: LinkedIn
1314
profile_url_prefix: https://www.linkedin.com/in/
15+
share_url_prefix: https://www.linkedin.com/shareArticle?mini=true&url=
1416
icon_svg: '<svg height="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19 18"><path d="M3.94 2A2 2 0 1 1 2 0a2 2 0 0 1 1.94 2zM4 5.48H0V18h4zm6.32 0H6.34V18h3.94v-6.57c0-3.66 4.77-4 4.77 0V18H19v-7.93c0-6.17-7.06-5.94-8.72-2.91z" fill="#959da5"/></svg>'
1517

1618
stackoverflow:
@@ -21,6 +23,7 @@ stackoverflow:
2123
twitter:
2224
name: Twitter
2325
profile_url_prefix: https://www.twitter.com/
26+
share_url_prefix: https://twitter.com/share?url=
2427
icon_svg: '<svg height="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 273.5 222.3"><path d="M273.5 26.3a109.77 109.77 0 0 1-32.2 8.8 56.07 56.07 0 0 0 24.7-31 113.39 113.39 0 0 1-35.7 13.6 56.1 56.1 0 0 0-97 38.4 54 54 0 0 0 1.5 12.8A159.68 159.68 0 0 1 19.1 10.3a56.12 56.12 0 0 0 17.4 74.9 56.06 56.06 0 0 1-25.4-7v.7a56.11 56.11 0 0 0 45 55 55.65 55.65 0 0 1-14.8 2 62.39 62.39 0 0 1-10.6-1 56.24 56.24 0 0 0 52.4 39 112.87 112.87 0 0 1-69.7 24 119 119 0 0 1-13.4-.8 158.83 158.83 0 0 0 86 25.2c103.2 0 159.6-85.5 159.6-159.6 0-2.4-.1-4.9-.2-7.3a114.25 114.25 0 0 0 28.1-29.1" fill="#959da5"/></svg>'
2528

2629
youtube:

_includes/social_media_share_url.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

_layouts/post.html

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,32 @@
22

33
{% capture post_body %}
44
{% if site.social_media %}
5-
<div class="col-sm-4 col-lg-3 d-flex flex-wrap flex-items-center d-sm-block float-sm-right border rounded-2 bg-white p-3 mb-5 ml-md-5">
6-
<h3 class="text-gray-dark mr-3 mr-sm-0">Share</h3>
7-
<ul class="d-flex d-sm-block list-style-none">
8-
{% for account in site.social_media %}
9-
<li class="mt-sm-3">
10-
{% assign service_shortname = account[0] %}
11-
{% assign service = site.data.social_media[service_shortname] %}
12-
<a href="{% include social_media_share_url.html service=service_shortname title=page.title permalink=page.url %}" title="Share on {{ service.name }}" class="d-flex flex-items-center">
13-
<div style="width:32px">{{ service.icon_svg }}</div><span class="d-none d-sm-inline-block text-gray-light">{{ service.name }}</span>
14-
</a>
15-
</li>
16-
{% endfor %}
17-
</ul>
18-
</div>
5+
{% assign shareable_social_media = '' | split: ',' %}
6+
7+
{% for service in site.social_media %}
8+
{% if service.share_url %}
9+
{% assign shareable_social_media = shareable_social_media | push: service %}
10+
{% end %}
11+
{% endfor %}
12+
13+
{% assign total_shareable_services = shareable_social_media | size %}
14+
15+
{% if total_shareable_services > 0 %}
16+
<div class="col-sm-4 col-lg-3 d-flex flex-wrap flex-items-center d-sm-block float-sm-right border rounded-2 bg-white p-3 mb-5 ml-md-5">
17+
<h3 class="text-gray-dark mr-3 mr-sm-0">Share</h3>
18+
<ul class="d-flex d-sm-block list-style-none">
19+
{% for account in shareable_social_media %}
20+
<li class="mt-sm-3">
21+
{% assign service_shortname = account[0] %}
22+
{% assign service = site.data.social_media[service_shortname] %}
23+
<a href="{% service.share_url_prefix %}{% page.url | prepend: site.url | prepend: site.baseurl | url_encode %}" title="Share on {{ service.name }}" class="d-flex flex-items-center">
24+
<div style="width:32px">{{ service.icon_svg }}</div><span class="d-none d-sm-inline-block text-gray-light">{{ service.name }}</span>
25+
</a>
26+
</li>
27+
{% endfor %}
28+
</ul>
29+
</div>
30+
{% endif %}
1931
{% endif %}
2032
<div class="article">
2133
{{ content }}

0 commit comments

Comments
 (0)