Skip to content

Commit 2bf87e0

Browse files
feat: add Mastodon sharing link (#1344)
Adds a "share to Mastodon" button as a link sharing option using @justinribeiro's share-to-mastodon package Discussion of proposed change - #1324 --------- Co-authored-by: Cotes Chung <[email protected]>
1 parent f6d96ab commit 2bf87e0

File tree

4 files changed

+71
-43
lines changed

4 files changed

+71
-43
lines changed

_data/share.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,16 @@ platforms:
2323
# - type: Weibo
2424
# icon: "fab fa-weibo"
2525
# link: "http://service.weibo.com/share/share.php?title=TITLE&url=URL"
26+
#
27+
# - type: Mastodon
28+
# icon: "fa-brands fa-mastodon"
29+
# # See: https://github.com/justinribeiro/share-to-mastodon#properties
30+
# instances:
31+
# - label: mastodon.social
32+
# link: "https://mastodon.social/"
33+
# - label: mastodon.online
34+
# link: "https://mastodon.online/"
35+
# - label: fosstodon.org
36+
# link: "https://fosstodon.org/"
37+
# - label: photog.social
38+
# link: "https://photog.social/"

_includes/post-sharing.html

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
11
<!-- Post sharing snippet -->
22

33
<div class="share-wrapper d-flex align-items-center">
4-
<span class="share-label text-muted me-1">{{ site.data.locales[include.lang].post.share }}</span>
4+
<span class="share-label text-muted">{{ site.data.locales[include.lang].post.share }}</span>
55
<span class="share-icons">
66
{% capture title %}{{ page.title }} - {{ site.title }}{% endcapture %}
77
{% assign title = title | uri_escape %}
88
{% assign url = page.url | absolute_url | url_encode %}
99

10-
{% for share in site.data.share.platforms %}
10+
{% for share in site.data.share.platforms -%}
11+
{% if share.type == 'Mastodon' %}
12+
<script defer type="module" src="https://cdn.jsdelivr.net/npm/@justinribeiro/share-to-mastodon/+esm"></script>
13+
<button
14+
class="btn text-start"
15+
data-bs-toggle="tooltip"
16+
data-bs-placement="top"
17+
title="{{ share.type }}"
18+
aria-label="{{ share.type }}"
19+
>
20+
<share-to-mastodon
21+
class="share-mastodon"
22+
message="{{ title }}"
23+
url="{{ url }}"
24+
{%- if share.instances -%}
25+
customInstanceList="{{ share.instances | jsonify | xml_escape }}"
26+
{%- endif %}
27+
>
28+
<i class="{{ share.icon }}"></i>
29+
</share-to-mastodon>
30+
</button>
31+
32+
{% continue %}
33+
{% endif %}
34+
1135
{% assign link = share.link | replace: 'TITLE', title | replace: 'URL', url %}
36+
1237
<a
1338
href="{{ link }}"
1439
data-bs-toggle="tooltip"
@@ -31,7 +56,7 @@
3156
title="{{ site.data.locales[include.lang].post.button.share_link.title }}"
3257
data-title-succeed="{{ site.data.locales[include.lang].post.button.share_link.succeed }}"
3358
>
34-
<i class="fa-fw fas fa-link pe-none"></i>
59+
<i class="fa-fw fas fa-link pe-none fs-6"></i>
3560
</button>
3661
</span>
3762
</div>

_sass/colors/typography-light.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363

6464
/* Posts */
6565
--toc-highlight: #0550ae;
66-
--btn-share-hover-color: var(--link-color);
66+
--btn-share-color: gray;
67+
--btn-share-hover-color: #0d6efd;
6768
--card-bg: white;
6869
--card-hovor-bg: #e2e2e2;
6970
--card-shadow: rgb(104, 104, 104, 0.05) 0 2px 6px 0,

_sass/layout/post.scss

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
Post-specific style
33
*/
44

5-
@mixin btn-sharing-color($light-color, $important: false) {
6-
@if $important {
7-
color: var(--btn-share-color, $light-color) !important;
8-
} @else {
9-
color: var(--btn-share-color, $light-color);
10-
}
11-
}
12-
135
%btn-post-nav {
146
width: 50%;
157
position: relative;
@@ -72,11 +64,23 @@ h1 + .post-meta {
7264
-ms-user-select: none;
7365
user-select: none;
7466

67+
%icon-size {
68+
font-size: 1.125rem;
69+
}
70+
7571
.share-icons {
76-
font-size: 1.2rem;
72+
display: flex;
73+
74+
i {
75+
color: var(--btn-share-color);
76+
77+
@extend %icon-size;
78+
}
7779

7880
> * {
79-
margin-left: 0.25rem;
81+
@extend %icon-size;
82+
83+
margin-left: 0.5rem;
8084

8185
&:hover {
8286
i {
@@ -87,43 +91,28 @@ h1 + .post-meta {
8791

8892
button {
8993
position: relative;
90-
bottom: 2px;
94+
bottom: 1px;
9195
padding: 0;
9296

9397
@extend %cursor-pointer;
9498
}
95-
96-
a :hover {
97-
text-decoration: none;
98-
}
99-
100-
.fa-square-x-twitter {
101-
@include btn-sharing-color(black);
102-
}
103-
104-
.fa-facebook-square {
105-
@include btn-sharing-color(rgb(66, 95, 156));
106-
}
107-
108-
.fa-telegram {
109-
@include btn-sharing-color(rgb(39, 159, 217));
110-
}
111-
112-
.fa-linkedin {
113-
@include btn-sharing-color(rgb(0, 119, 181));
114-
}
115-
116-
.fa-weibo {
117-
@include btn-sharing-color(rgb(229, 20, 43));
118-
}
11999
} /* .share-icons */
120-
121-
.fas.fa-link {
122-
@include btn-sharing-color(rgb(171, 171, 171));
123-
}
124100
} /* .share-wrapper */
125101
}
126102

103+
.share-mastodon {
104+
/* See: https://github.com/justinribeiro/share-to-mastodon#properties */
105+
--wc-stm-font-family: $font-family-base;
106+
--wc-stm-dialog-background-color: var(--card-bg);
107+
--wc-stm-form-button-border: 1px solid var(--btn-border-color);
108+
--wc-stm-form-submit-background-color: var(--sidebar-btn-bg);
109+
--wc-stm-form-cancel-background-color: var(--sidebar-btn-bg);
110+
--wc-stm-form-button-background-color-hover: #007bff;
111+
--wc-stm-form-button-color-hover: white;
112+
113+
font-size: 1rem;
114+
}
115+
127116
.post-tags {
128117
line-height: 2rem;
129118

0 commit comments

Comments
 (0)