refactor(sidebar): improve creation of social links

This commit is contained in:
Cotes Chung 2023-02-06 22:33:20 +08:00
parent af8986bf50
commit 5cbaf24bcb
No known key found for this signature in database
GPG Key ID: 0D9E54843167A808
1 changed files with 20 additions and 17 deletions

View File

@ -64,34 +64,37 @@
{% endunless %} {% endunless %}
{% for entry in site.data.contact %} {% for entry in site.data.contact %}
{% capture url %} {% case entry.type %}
{%- if entry.type == 'github' -%} {% when 'github', 'twitter' %}
https://github.com/{{ site.github.username }} {%- capture url -%}
{%- elsif entry.type == 'twitter' -%} https://{{ entry.type }}.com/{{ site[entry.type].username }}
https://twitter.com/{{ site.twitter.username }} {%- endcapture -%}
{%- elsif entry.type == 'email' -%} {% when 'email' %}
{% assign email = site.social.email | split: '@' %} {% assign email = site.social.email | split: '@' %}
javascript:location.href = 'mailto:' + ['{{ email[0] }}','{{ email[1] }}'].join('@') {%- capture url -%}
{%- elsif entry.type == 'rss' -%} javascript:location.href = 'mailto:' + ['{{ email[0] }}','{{ email[1] }}'].join('@')
{{ "/feed.xml" | relative_url }} {%- endcapture -%}
{%- else -%} {% when 'rss' %}
{{ entry.url }} {% assign url = '/feed.xml' | relative_url %}
{%- endif -%} {% else %}
{% endcapture %} {% assign url = entry.url %}
{% endcase %}
{% if url %} {% if url %}
<a href="{{ url }}" aria-label="{{ entry.type }}" <a href="{{ url }}" aria-label="{{ entry.type }}"
{% assign link_types = nil %} {% assign link_types = '' %}
{% unless entry.noblank %} {% unless entry.noblank %}
{% assign link_types = link_types | append: " noopener" %}
target="_blank" target="_blank"
{% assign link_types = 'noopener noreferrer' %}
{% endunless %} {% endunless %}
{% if entry.type == 'mastodon' %} {% if entry.type == 'mastodon' %}
{% assign link_types = link_types | append: " me" %} {% assign link_types = link_types | append: ' me' | strip %}
{% endif %} {% endif %}
{% if link_types %}rel="{{ link_types | lstrip }}"{% endif %}> {% unless link_types == empty %}rel="{{ link_types }}"{% endunless %}>
<i class="{{ entry.icon }}"></i> <i class="{{ entry.icon }}"></i>
</a> </a>
{% endif %} {% endif %}