Skip to content

Commit f41dd86

Browse files
authored
Add Fediverse button (#108)
2 parents d64e95e + 13b1ca9 commit f41dd86

7 files changed

+33
-3
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
### Added
10+
11+
- [#108](https://github.com/kytta/shareon/pull/108)
12+
Fediverse button (via [Share₂Fedi](https://github.com/kytta/share2fedi))
13+
714
## [2.4.0] - 2023-12-07
815

916
### Added

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ names of which match the names of the social networks (or `copy-url`, for the
9494
```html
9595
<div class="shareon">
9696
<a class="facebook"></a>
97+
<a class="fediverse"></a>
9798
<a class="linkedin"></a>
9899
<a class="mastodon"></a>
99100
<!-- FB App ID is required for the Messenger button to function -->
@@ -140,6 +141,8 @@ Apart from the URL and title, some networks support extra parameters:
140141

141142
- you **MUST** add `data-fb-app-id` to the FB Messenger button to make sharing
142143
even possible
144+
- add `data-s2f-instance` to the Fediverse button to set your Share₂Fedi
145+
instance
143146
- add `data-media` to an Odnoklassniki, Pinterest, or VK button to customize
144147
the pinned picture
145148
- add `data-text` to a Mastodon, Telegram, Tumblr, Viber, or WhatsApp button to add
@@ -155,6 +158,7 @@ Here are all custom parameters:
155158
```html
156159
<div class="shareon" data-url="https://custom.url/for-this-page">
157160
<a class="facebook" data-title="Custom Facebook title" data-hashtags="awesome"></a>
161+
<a class="fediverse" data-s2f-instance="s2f.mydomain.example"></a>
158162
<a class="messenger" data-fb-app-id="0123456789012345"></a>
159163
<a class="pinterest" data-media="https://custom.picture/for-pinterest">Pin</a>
160164
<a class="telegram" data-text="Check this out!"></a>

index.html

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ <h1>Shareon Demo Page</h1>
3030
<h2><code>&lt;a&gt;</code></h2>
3131
<div class="shareon">
3232
<a class="facebook"></a>
33+
<a class="fediverse"></a>
3334
<a class="linkedin"></a>
3435
<a class="mastodon"></a>
3536
<a class="messenger" data-fb-app-id="3619024578167617"></a>
@@ -54,6 +55,7 @@ <h2><code>&lt;a&gt;</code></h2>
5455
<h2><code>&lt;button&gt;</code></h2>
5556
<div class="shareon">
5657
<button class="facebook"></button>
58+
<button class="fediverse"></button>
5759
<button class="linkedin"></button>
5860
<button class="mastodon"></button>
5961
<button class="messenger" data-fb-app-id="3619024578167617"></button>
@@ -83,6 +85,7 @@ <h2><code>&lt;a&gt;</code> with custom params</h2>
8385
data-text="hey check this out"
8486
>
8587
<a class="facebook"></a>
88+
<a class="fediverse" data-s2f-instance="share2fedi.vercel.app"></a>
8689
<a class="linkedin"></a>
8790
<a class="mastodon" data-via="@[email protected]"></a>
8891
<a class="messenger" data-fb-app-id="3619024578167617"></a>
@@ -106,6 +109,7 @@ <h2><code>&lt;a&gt;</code> with custom params</h2>
106109
<h2>Specimen</h2>
107110
<div class="shareon specimen">
108111
<a class="facebook"></a>
112+
<a class="fediverse"></a>
109113
<a class="linkedin"></a>
110114
<a class="mastodon">Toot</a>
111115
<a class="messenger" data-fb-app-id="3619024578167617"></a>

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@
110110
},
111111
"size-limit": [
112112
{
113-
"limit": "6 KB",
113+
"limit": "6 KiB",
114114
"path": "./dist/shareon.min.css",
115115
"brotli": true
116116
},
117117
{
118-
"limit": "1 KB",
118+
"limit": "1 KiB",
119119
"path": "./dist/shareon.es.js",
120120
"brotli": true
121121
}

src/icons/fediverse.svg

+1
Loading

src/shareon.css

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@
9292
background-image: url("icons/facebook.svg");
9393
}
9494

95+
.shareon > .fediverse {
96+
background-color: #8a54af;
97+
}
98+
.shareon > .fediverse:before {
99+
background-image: url("icons/fediverse.svg");
100+
}
101+
95102
.shareon > .linkedin {
96103
background-color: #0a66c2;
97104
}

src/shareon.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import "./shareon.css";
1313
* media?: string,
1414
* text?: string,
1515
* via?: string,
16-
* fbAppId?: string
16+
* fbAppId?: string,
17+
* s2fInstance?: string,
1718
* }) => string}}
1819
*/
1920
const urlBuilderMap = {
2021
facebook: (d) => `https://www.facebook.com/sharer/sharer.php?u=${d.url}${d.hashtags ? `&hashtag=%23${d.hashtags.split('%2C')[0]}` : ''}`,
22+
fediverse: (d) => `https://${d.s2fInstance}/?text=${d.title}%0D%0A${d.url}${d.text ? `%0D%0A%0D%0A${d.text}` : ''}${d.via ? `%0D%0A%0D%0A${d.via}` : ''}`,
2123
email: (d) => `mailto:?subject=${d.title}&body=${d.url}`,
2224
linkedin: (d) => `https://www.linkedin.com/sharing/share-offsite/?url=${d.url}`,
2325
mastodon: (d) => `https://toot.kytta.dev/?text=${d.title}%0D%0A${d.url}${d.text ? `%0D%0A%0D%0A${d.text}` : ''}${d.via ? `%0D%0A%0D%0A${d.via}` : ''}`,
@@ -126,6 +128,11 @@ const init = () => {
126128
fbAppId: encodeURIComponent(
127129
child.dataset.fbAppId || container.dataset.fbAppId || "",
128130
),
131+
s2fInstance: encodeURIComponent(
132+
child.dataset.s2fInstance ||
133+
container.dataset.s2fInstance ||
134+
"s2f.kytta.dev",
135+
),
129136
};
130137
const url = urlBuilderMap[cls](preset);
131138

0 commit comments

Comments
 (0)