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

View file

@ -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 %}
<a href="{{ url }}" aria-label="{{ entry.type }}"
{% assign link_types = nil %}
{% assign link_types = '' %}
{% unless entry.noblank %}
{% assign link_types = link_types | append: " noopener" %}
target="_blank"
{% assign link_types = 'noopener noreferrer' %}
{% endunless %}
{% if entry.type == 'mastodon' %}
{% assign link_types = link_types | append: " me" %}
{% assign link_types = link_types | append: ' me' | strip %}
{% endif %}
{% if link_types %}rel="{{ link_types | lstrip }}"{% endif %}>
{% unless link_types == empty %}rel="{{ link_types }}"{% endunless %}>
<i class="{{ entry.icon }}"></i>
</a>
{% endif %}