Skip to content

Commit ea5b047

Browse files
committed
Optimize Liquid share link generation
To remove the stray &, a lot had to be done that feels very hacky and also silly
1 parent 3f4b5c7 commit ea5b047

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

_includes/share.html

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,45 @@
11
<div id="share">
22
Share on
33

4-
<span title="Share this on Mastodon" class="btn" style="background-color: #6260fa; cursor: pointer;" onclick="mastodon_modal()">Mastodon</span>
4+
<span title="Share this on Mastodon" class="btn" style="background-color: #6260fa; cursor: pointer;"
5+
onclick="mastodon_modal()">Mastodon</span>
56

67
{% for butt in site.sharebuttons %}
8+
{%- assign elems = "" | split: "" -%}
9+
10+
{%- if butt.title -%}
11+
{%- assign title = butt.title | append: '=' -%}
12+
{%- assign title = title | append: page.title | uri_escape -%}
13+
{%- assign elems = title | split: '\n' | concat: elems -%}
14+
{%- endif -%}
15+
16+
{%- if butt.body -%}
17+
{%- assign body = butt.body | append: '=' -%}
18+
{%- assign body = body | append: '%0A' -%}
19+
{%- assign body = body | append: 'https://ellietheyeen.github.io' | append: page.url | uri_escape -%}
20+
{%- assign body = body | '%0A' -%}
21+
{%- assign elems = body | split: '\n' | concat: elems -%}
22+
{%- endif -%}
23+
24+
{%- if butt.media -%}
25+
{%- assign media = butt.media | append: '=' -%}
26+
{%- assign mediaurl = page.image | absolute_url -%}
27+
{%- assign media = media | append: mediaurl -%}
28+
{%- assign elems = media | split: '\n' | concat: elems -%}
29+
{%- endif -%}
30+
31+
{%- if butt.url -%}
32+
{%- assign url = butt.url | append: '=' -%}
33+
{%- assign url = url | append: 'https://ellietheyeen.github.io' | append: page.url | uri_escape -%}
34+
{%- assign elems = url | split: '\n' | concat: elems -%}
35+
{%- endif -%}
36+
37+
{%- if butt.extra -%}
38+
{%- assign elems = butt.extra | split: '\n' | concat: elems -%}
39+
{%- endif -%}
40+
741
<a class="sharelink" title="Share this on {{ butt.name }}" target="_blank"
8-
href="{{ butt.base }}?{%- if butt.extra -%}{{ butt.extra }}{%- endif -%}{%- if butt.url -%}&{{ butt.url }}={{ 'https://ellietheyeen.github.io' | append: page.url | uri_escape }}{%- endif -%}{%- if butt.title -%}&{{ butt.title }}={{ page.title | uri_escape }}{%- endif -%}{%- if butt.body -%}&{{ butt.body }}={{ page.title | uri_escape }}%0A{{ 'https://ellietheyeen.github.io' | append: page.url | uri_escape }}%0A{%- endif -%}{%- if butt.media -%}&{{ butt.media }}={{ page.image | absolute_url }}{%- endif -%}">
42+
href="{{ butt.base }}?{{ elems | join: '&' }}">
943
<span class="btn" style="background-color: {{ butt.color }};">{{ butt.name }}</span>
1044
</a>
1145
{% endfor %}

0 commit comments

Comments
 (0)