mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
Add share button
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
// https://github.com/mattjennings/sveltekit-blog-template/blob/main/src/routes/post/%5Bslug%5D/%2Bpage.svelte
|
// https://github.com/mattjennings/sveltekit-blog-template/blob/main/src/routes/post/%5Bslug%5D/%2Bpage.svelte
|
||||||
|
|
||||||
|
import { browser } from "$app/environment";
|
||||||
import SvelteSeo from "svelte-seo";
|
import SvelteSeo from "svelte-seo";
|
||||||
export let data;
|
export let data;
|
||||||
import { SITE_URL } from "$lib/metadata";
|
import { SITE_URL } from "$lib/metadata";
|
||||||
@@ -9,7 +10,23 @@
|
|||||||
// if (data.ghReleaseData) {
|
// if (data.ghReleaseData) {
|
||||||
// GhReleasesDownload = import("$lib/GhReleasesDownload.svelte").then((m) => m.default)
|
// GhReleasesDownload = import("$lib/GhReleasesDownload.svelte").then((m) => m.default)
|
||||||
// }
|
// }
|
||||||
$: canonical = SITE_URL + "/blog/" + data.post.canonical
|
$: canonical = SITE_URL + "/blog/" + data.post.canonical;
|
||||||
|
|
||||||
|
$: webShareAPISupported = browser && typeof navigator.share !== 'undefined';
|
||||||
|
// let webShareAPISupported = true;
|
||||||
|
|
||||||
|
$: handleWebShare;
|
||||||
|
const handleWebShare = async () => {
|
||||||
|
try {
|
||||||
|
navigator.share({
|
||||||
|
title: data.post.title,
|
||||||
|
text: data.post.description,
|
||||||
|
url: canonical,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
webShareAPISupported = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SvelteSeo
|
<SvelteSeo
|
||||||
@@ -32,9 +49,16 @@
|
|||||||
<article class="h-entry">
|
<article class="h-entry">
|
||||||
<h1 id="title" class="p-name">{data.post.title}</h1>
|
<h1 id="title" class="p-name">{data.post.title}</h1>
|
||||||
<aside>
|
<aside>
|
||||||
<a class="u-url" href={canonical}>Published on <time class="dt-published" datetime={data.post.date}
|
<a class="u-url" href={canonical}
|
||||||
>{new Date(data.post.date).toLocaleDateString()}</time
|
>Published on <time class="dt-published" datetime={data.post.date}
|
||||||
></a> · <span>{data.post.readingTime.text}</span>
|
>{new Date(data.post.date).toLocaleDateString()}</time
|
||||||
|
></a
|
||||||
|
>
|
||||||
|
· <span>{data.post.readingTime.text}</span>
|
||||||
|
{#if webShareAPISupported} · <button class="link" on:click={handleWebShare}
|
||||||
|
>Share</button
|
||||||
|
>
|
||||||
|
{/if}
|
||||||
</aside>
|
</aside>
|
||||||
<Toc headings={data.post.headings} />
|
<Toc headings={data.post.headings} />
|
||||||
<!-- {#await GhReleasesDownload}
|
<!-- {#await GhReleasesDownload}
|
||||||
@@ -56,4 +80,14 @@
|
|||||||
color: currentColor;
|
color: currentColor;
|
||||||
text-decoration: unset;
|
text-decoration: unset;
|
||||||
}
|
}
|
||||||
|
button.link {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: unset;
|
||||||
|
padding: 0;
|
||||||
|
/* margin: 0; */
|
||||||
|
display: inline;
|
||||||
|
text-decoration: underline;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user