Skip to content

Commit f2ef9f2

Browse files
authored
Use URI templates for social network links (daattali#586)
1 parent 7715136 commit f2ef9f2

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

_data/SocialNetworks.yml

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,91 +2,90 @@
22
# Use the same key you added in _config.yml -> social-network-links.
33
# In addition to that you need to specify the following properties:
44
# name: Specify a user-friendly name that will be used as a link title
5-
# baseURL: Define a base URL which will be combined with the value of
6-
# site.social-network-links.<key>
5+
# urlTemplate: Define a URL template. The variable {value} will be replaced
6+
# with the value of site.social-network-links.<key>
77
# icon: Specify a valid fontawesome icon class
88

99
facebook:
1010
name: "Facebook"
11-
baseURL: "https://www.facebook.com/"
11+
urlTemplate: "https://www.facebook.com/{value}"
1212
icon: "fa-facebook"
1313

1414
github:
1515
name: "GitHub"
16-
baseURL: "https://github.com/"
16+
urlTemplate: "https://github.com/{value}"
1717
icon: "fa-github"
1818

1919
twitter:
2020
name: "Twitter"
21-
baseURL: "https://twitter.com/"
21+
urlTemplate: "https://twitter.com/{value}"
2222
icon: "fa-twitter"
2323

2424
reddit:
2525
name: "Reddit"
26-
baseURL: "https://reddit.com/u/"
26+
urlTemplate: "https://reddit.com/u/{value}"
2727
icon: "fa-reddit"
2828

2929
email:
3030
name: "Email me"
31-
baseURL: "mailto:"
31+
urlTemplate: "mailto:{value}"
3232
icon: "fa-envelope"
3333

3434
linkedin:
3535
name: "LinkedIn"
36-
baseURL: "https://linkedin.com/in/"
36+
urlTemplate: "https://linkedin.com/in/{value}"
3737
icon: "fa-linkedin"
3838

3939
xing:
4040
name: "Xing"
41-
baseURL: "https://www.xing.com/profile/"
41+
urlTemplate: "https://www.xing.com/profile/{value}"
4242
icon: "fa-xing"
4343

4444
stackoverflow:
4545
name: "StackOverflow"
46-
baseURL: "https://stackoverflow.com/users/"
46+
urlTemplate: "https://stackoverflow.com/users/{value}"
4747
icon: "fa-stack-overflow"
4848

4949
snapchat:
5050
name: "Snapchat"
51-
baseURL: "https://www.snapchat.com/add/"
51+
urlTemplate: "https://www.snapchat.com/add/{value}"
5252
icon: "fa-snapchat-ghost"
5353

5454
instagram:
5555
name: "Instagram"
56-
baseURL: "https://www.instagram.com/"
56+
urlTemplate: "https://www.instagram.com/{value}"
5757
icon: "fa-instagram"
5858

5959
youtube:
6060
name: "YouTube"
61-
baseURL: "https://www.youtube.com/"
61+
urlTemplate: "https://www.youtube.com/{value}"
6262
icon: "fa-youtube"
6363

6464
spotify:
6565
name: "Spotify"
66-
baseURL: "https://open.spotify.com/user/"
66+
urlTemplate: "https://open.spotify.com/user/{value}"
6767
icon: "fa-spotify"
6868

6969
telephone:
7070
name: "Phone"
71-
baseURL: "tel:"
71+
urlTemplate: "tel:{value}"
7272
icon: "fa-phone"
7373

7474
rss:
7575
name: "RSS"
76-
baseURL: "{{ '/feed.xml' | relative_url }}"
7776
icon: "fa-rss"
7877

7978
steam:
8079
name: "Steam"
81-
baseURL: "https://steamcommunity.com/id/"
80+
urlTemplate: "https://steamcommunity.com/id/{value}"
8281
icon: "fa-steam"
8382

8483
twitch:
8584
name: "Twitch"
86-
baseURL: "https://www.twitch.tv/"
85+
urlTemplate: "https://www.twitch.tv/{value}"
8786
icon: "fa-twitch"
8887

8988
yelp:
9089
name: "Yelp"
91-
baseURL: "https://{{ site.author.yelp }}.yelp.com"
90+
urlTemplate: "https://{value}.yelp.com"
9291
icon: "fa-yelp"

_includes/footer.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
{%- for link in site.social-network-links -%}
77
{%- assign curkey = link[0] -%}
88
{%- assign element = site.data.SocialNetworks[curkey] -%}
9-
<li>
109
{%- if curkey == 'rss' -%}
11-
<a href="{{ '/feed.xml' | relative_url }}" title="{{ element.name }}">
12-
{%- elsif curkey == 'yelp' -%}
13-
<a href="https://{{ site.social-network-links[curkey] }}.yelp.com" title="{{ element.name }}">
10+
{%- capture url -%}{{ '/feed.xml' | relative_url }}{%- endcapture -%}
1411
{%- else -%}
15-
<a href="{{element.baseURL}}{{ site.social-network-links[curkey] }}" title="{{ element.name }}">
12+
{%- assign value = site.social-network-links[curkey] -%}
13+
{%- assign placeholder = "{value}" -%}
14+
{%- capture url -%}{{ element.urlTemplate | replace: placeholder, value }}{%- endcapture -%}
1615
{%- endif -%}
16+
<li>
17+
<a href="{{ url }}" title="{{ element.name }}">
1718
<span class="fa-stack fa-lg" aria-hidden="true">
1819
<i class="fa fa-circle fa-stack-2x"></i>
1920
<i class="fa {{ element.icon }} fa-stack-1x fa-inverse"></i>

0 commit comments

Comments
 (0)