From 5cbaf24bcb8f62ab5a70697f949460e7251c76e1 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 6 Feb 2023 22:33:20 +0800 Subject: [PATCH] refactor(sidebar): improve creation of social links --- _includes/sidebar.html | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/_includes/sidebar.html b/_includes/sidebar.html index c32efb3..c570597 100644 --- a/_includes/sidebar.html +++ b/_includes/sidebar.html @@ -64,34 +64,37 @@ {% endunless %} {% for entry in site.data.contact %} - {% capture url %} - {%- if entry.type == 'github' -%} - https://github.com/{{ site.github.username }} - {%- elsif entry.type == 'twitter' -%} - https://twitter.com/{{ site.twitter.username }} - {%- elsif entry.type == 'email' -%} + {% case entry.type %} + {% when 'github', 'twitter' %} + {%- capture url -%} + https://{{ entry.type }}.com/{{ site[entry.type].username }} + {%- endcapture -%} + {% when 'email' %} {% assign email = site.social.email | split: '@' %} - javascript:location.href = 'mailto:' + ['{{ email[0] }}','{{ email[1] }}'].join('@') - {%- elsif entry.type == 'rss' -%} - {{ "/feed.xml" | relative_url }} - {%- else -%} - {{ entry.url }} - {%- endif -%} - {% endcapture %} + {%- capture url -%} + javascript:location.href = 'mailto:' + ['{{ email[0] }}','{{ email[1] }}'].join('@') + {%- endcapture -%} + {% when 'rss' %} + {% assign url = '/feed.xml' | relative_url %} + {% else %} + {% assign url = entry.url %} + {% endcase %} {% if url %} + {% unless link_types == empty %}rel="{{ link_types }}"{% endunless %}> + {% endif %}