Usar el cajón de compartir del sistema
This commit is contained in:
parent
25ba521238
commit
316041fe91
2 changed files with 32 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
|||
<meta name="color-scheme" content="light"/>
|
||||
|
||||
<link href="assets/css/styles.css" rel="stylesheet">
|
||||
<script defer type="text/javascript" src="assets/js/script.js"></script>
|
||||
|
||||
{% seo %}
|
||||
{% feed_meta %}
|
||||
|
|
31
assets/js/script.js
Normal file
31
assets/js/script.js
Normal file
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue