added a share on fediverse button
This commit is contained in:
parent
165081d97d
commit
cc2474323c
4 changed files with 116 additions and 0 deletions
38
layouts/partials/share_on_fediverse.html
Normal file
38
layouts/partials/share_on_fediverse.html
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
{{ if site.Params.enableShareOnFediverse | default false }}
|
||||
<a class="shareBtn" onclick="openFediInstanceDialog();">Share on the Fediverse</a>
|
||||
<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() {
|
||||
let instance = fixURL(fediInstanceInput.value);
|
||||
window.open(
|
||||
`${instance}/share?text=${articleTitle}%20${articleLink}`,
|
||||
'__blank'
|
||||
);
|
||||
}
|
||||
</script>
|
||||
{{ end }}
|
||||
Loading…
Add table
Add a link
Reference in a new issue