2021-06-28 03:20:05 -05:00
|
|
|
{{ if site.Params.enableShareOnFediverse | default false }}
|
2021-06-28 04:05:10 -05:00
|
|
|
<a style="margin-bottom: 24px; display: inline-block;" class="shareBtn" onclick="openFediInstanceDialog();">Share on the Fediverse</a>
|
2021-06-28 03:20:05 -05:00
|
|
|
<div id="fediInstanceDialog">
|
|
|
|
<div class="bg" onclick="closeFediInstanceDialog();"></div>
|
|
|
|
<div class="dialog">
|
|
|
|
<h2>Enter your instance's address</h2>
|
|
|
|
<input id="fediInstanceInput" placeholder="Eg. mastodon.social" type="text" />
|
|
|
|
<div class="buttons">
|
|
|
|
<a class="shareBtn" onclick="closeFediInstanceDialog();">Cancel</a>
|
|
|
|
<a class="shareBtn" onclick="shareOnFedi();">Share</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
var articleTitle = '{{ .Title }}';
|
|
|
|
var articleLink = '{{ .Permalink }}';
|
|
|
|
var fediInstanceDialog = document.getElementById('fediInstanceDialog');
|
|
|
|
var fediInstanceInput = document.getElementById('fediInstanceInput');
|
|
|
|
function openFediInstanceDialog() {
|
|
|
|
fediInstanceDialog.classList.add('open');
|
|
|
|
}
|
|
|
|
function closeFediInstanceDialog() {
|
|
|
|
fediInstanceDialog.classList.remove('open');
|
|
|
|
}
|
|
|
|
function fixURL(url) {
|
|
|
|
if (url.substr(0, 8) == 'https://') return url;
|
|
|
|
if (url.substr(0, 7) == 'http://') return url;
|
|
|
|
return 'https://' + url;
|
|
|
|
}
|
|
|
|
function shareOnFedi() {
|
2021-06-28 04:08:31 -05:00
|
|
|
let instance = fediInstanceInput.value.trim();
|
|
|
|
if (!instance) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
instance = fixURL(instance);
|
2021-06-28 03:20:05 -05:00
|
|
|
window.open(
|
|
|
|
`${instance}/share?text=${articleTitle}%20${articleLink}`,
|
|
|
|
'__blank'
|
|
|
|
);
|
2021-06-28 04:08:31 -05:00
|
|
|
closeFediInstanceDialog();
|
2021-06-28 03:20:05 -05:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
{{ end }}
|