diff --git a/_layouts/default.html b/_layouts/default.html index 7755094..a533fac 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -9,6 +9,7 @@ + {% seo %} {% feed_meta %} diff --git a/assets/js/script.js b/assets/js/script.js new file mode 100644 index 0000000..61cd8fa --- /dev/null +++ b/assets/js/script.js @@ -0,0 +1,31 @@ +--- +--- + +document.addEventListener('{%- if site.turbolinks.enabled -%}turbolinks:load{%- else -%}DOMContentLoaded{%- endif -%}', () => { + document.querySelectorAll('.share').forEach(share => { + share.addEventListener('click', event => { + if (!Navigator.share) return; + + event.preventDefault(); + event.stopPropagation(); + + const title = document.querySelector('title').text; + + try { + const text = document.querySelector('meta[property="og:description"]').content; + } catch { + const text = ''; + } + + try { + const url = document.querySelector('link[rel=canonical]').href; + } catch { + const url = document.location.href; + } + + const data = { title: title, text: text, url: url }; + + if (Navigator.canShare(data)) Navigator.share(data).then(); + }); + }); +});