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 %} {% 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: '@' %}
{%- capture url -%}
javascript:location.href = 'mailto:' + ['{{ email[0] }}','{{ email[1] }}'].join('@') javascript:location.href = 'mailto:' + ['{{ email[0] }}','{{ email[1] }}'].join('@')
{%- elsif entry.type == 'rss' -%} {%- endcapture -%}
{{ "/feed.xml" | relative_url }} {% when 'rss' %}
{%- else -%} {% assign url = '/feed.xml' | relative_url %}
{{ entry.url }} {% else %}
{%- endif -%} {% assign url = entry.url %}
{% endcapture %} {% 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 %}