diff options
| author | Dym Sohin <re@dym.sh> | 2023-10-23 01:03:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-22 19:03:30 -0400 |
| commit | a871337a749652d4b791b5ad0c272fff77149cd6 (patch) | |
| tree | 9f5bdde3faf2fe13f8fbb94b169cdbfb50bfd213 /lume/src/_includes | |
| parent | c04d9d6dbfdaac26e964a6879c660bb6ae918c6e (diff) | |
| download | xesite-a871337a749652d4b791b5ad0c272fff77149cd6.tar.xz xesite-a871337a749652d4b791b5ad0c272fff77149cd6.zip | |
fix blogpost sharing button from non-chromium browsers (#733)
Closes #726
Diffstat (limited to 'lume/src/_includes')
| -rw-r--r-- | lume/src/_includes/blog.njk | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lume/src/_includes/blog.njk b/lume/src/_includes/blog.njk index 5edad30..0262a17 100644 --- a/lume/src/_includes/blog.njk +++ b/lume/src/_includes/blog.njk @@ -43,16 +43,26 @@ layout: base.njk title: document.title, url: window.location.href }; - if (!navigator.canShare(shareData)) { - console.log("can't share"); - return; + if (navigator.share && navigator.canShare(shareData)) { + // console.log("(via navigator.share)"); + navigator + .share(shareData) + .then(() => { + console.log("Thanks for sharing!"); + }) + .catch(console.error); + } + else if (navigator.clipboard) { + // console.log("(via navigator.clipboard)"); + navigator.clipboard.writeText(shareData.url) + .then(() => { + console.log("Thanks for sharing!"); + }) + .catch(console.error); + } + else { + console.log("can't share directly, but feel free to copy the url from addressbar manually"); } - navigator - .share({title: document.title, url: window.location.href}) - .then(() => { - console.log('Thanks for sharing!'); - }) - .catch(console.error); } shareButton.addEventListener("click", doShareButton); </script> |
