blog.trnck.dev
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #75 from github/refactor-social-share

Share: Only list social media that support a share URL

authored by

Brandon Rosage and committed by
GitHub
f663eec5 b609e9bf

+31 -28
+1 -1
_config.yml
··· 27 27 projects: 28 28 # - repo-name 29 29 30 - social_media: 30 + # social_media: 31 31 # behance: your_username 32 32 # facebook: your_username 33 33 # dribbble: your_username
+3
_data/social_media.yml
··· 6 6 facebook: 7 7 name: Facebook 8 8 profile_url_prefix: https://www.facebook.com/ 9 + share_url_prefix: https://www.facebook.com/sharer/sharer.php?u= 9 10 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>' 10 11 11 12 linkedin: 12 13 name: LinkedIn 13 14 profile_url_prefix: https://www.linkedin.com/in/ 15 + share_url_prefix: https://www.linkedin.com/shareArticle?mini=true&url= 14 16 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>' 15 17 16 18 stackoverflow: ··· 21 23 twitter: 22 24 name: Twitter 23 25 profile_url_prefix: https://www.twitter.com/ 26 + share_url_prefix: https://twitter.com/share?url= 24 27 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>' 25 28 26 29 youtube:
-13
_includes/social_media_share_url.html
··· 1 - {% if include.service == 'facebook' %} 2 - {% capture share_url %} 3 - https://www.facebook.com/sharer/sharer.php?u={{ include.permalink | prepend: site.url | prepend: site.baseurl | url_encode }} 4 - {% endcapture %} 5 - {% elsif include.service == 'linkedin' %} 6 - {% capture share_url %} 7 - https://www.linkedin.com/shareArticle?mini=true&url={{ include.permalink | prepend: site.url | prepend: site.baseurl | url_encode }}&title={{ include.title | url_encode }}&source=LinkedIn 8 - {% endcapture %} 9 - {% elsif include.service == 'twitter' %} 10 - {% capture share_url %} 11 - https://twitter.com/share?text={{ include.title | url_encode }}&url={{ include.permalink | prepend: site.url | prepend: site.baseurl | url_encode }} 12 - {% endcapture %} 13 - {% endif %}{{ share_url | strip }}
+27 -14
_layouts/post.html
··· 2 2 3 3 {% capture post_body %} 4 4 {% 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 account in site.social_media %} 8 + {% assign service_shortname = account[0] %} 9 + {% assign service = site.data.social_media[service_shortname] %} 10 + 11 + {% if service.share_url_prefix %} 12 + {% assign shareable_social_media = shareable_social_media | push: service %} 13 + {% endif %} 14 + {% endfor %} 15 + 16 + {% assign total_shareable_services = shareable_social_media | size %} 17 + 18 + {% if total_shareable_services > 0 %} 19 + <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"> 20 + <h3 class="text-gray-dark mr-3 mr-sm-0">Share</h3> 21 + <ul class="d-flex d-sm-block list-style-none"> 22 + {% for service in shareable_social_media %} 23 + <li class="mt-sm-3"> 24 + <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"> 25 + <div style="width:32px">{{ service.icon_svg }}</div><span class="d-none d-sm-inline-block text-gray-light">{{ service.name }}</span> 26 + </a> 27 + </li> 28 + {% endfor %} 29 + </ul> 30 + </div> 31 + {% endif %} 19 32 {% endif %} 20 33 <div class="article"> 21 34 {{ content }}