Skip to content

Commit 5cbaf24

Browse files
committed
refactor(sidebar): improve creation of social links
1 parent af8986b commit 5cbaf24

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

_includes/sidebar.html

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,37 @@
6464
{% endunless %}
6565

6666
{% for entry in site.data.contact %}
67-
{% capture url %}
68-
{%- if entry.type == 'github' -%}
69-
https://github.com/{{ site.github.username }}
70-
{%- elsif entry.type == 'twitter' -%}
71-
https://twitter.com/{{ site.twitter.username }}
72-
{%- elsif entry.type == 'email' -%}
67+
{% case entry.type %}
68+
{% when 'github', 'twitter' %}
69+
{%- capture url -%}
70+
https://{{ entry.type }}.com/{{ site[entry.type].username }}
71+
{%- endcapture -%}
72+
{% when 'email' %}
7373
{% assign email = site.social.email | split: '@' %}
74-
javascript:location.href = 'mailto:' + ['{{ email[0] }}','{{ email[1] }}'].join('@')
75-
{%- elsif entry.type == 'rss' -%}
76-
{{ "/feed.xml" | relative_url }}
77-
{%- else -%}
78-
{{ entry.url }}
79-
{%- endif -%}
80-
{% endcapture %}
74+
{%- capture url -%}
75+
javascript:location.href = 'mailto:' + ['{{ email[0] }}','{{ email[1] }}'].join('@')
76+
{%- endcapture -%}
77+
{% when 'rss' %}
78+
{% assign url = '/feed.xml' | relative_url %}
79+
{% else %}
80+
{% assign url = entry.url %}
81+
{% endcase %}
8182

8283
{% if url %}
8384
<a href="{{ url }}" aria-label="{{ entry.type }}"
84-
{% assign link_types = nil %}
85+
{% assign link_types = '' %}
86+
8587
{% unless entry.noblank %}
86-
{% assign link_types = link_types | append: " noopener" %}
8788
target="_blank"
89+
{% assign link_types = 'noopener noreferrer' %}
8890
{% endunless %}
8991

9092
{% if entry.type == 'mastodon' %}
91-
{% assign link_types = link_types | append: " me" %}
93+
{% assign link_types = link_types | append: ' me' | strip %}
9294
{% endif %}
9395

94-
{% if link_types %}rel="{{ link_types | lstrip }}"{% endif %}>
96+
{% unless link_types == empty %}rel="{{ link_types }}"{% endunless %}>
97+
9598
<i class="{{ entry.icon }}"></i>
9699
</a>
97100
{% endif %}

0 commit comments

Comments
 (0)