Skip to content

Commit

Permalink
feat: <Share /> (denoland#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua authored Jul 28, 2023
1 parent 8476598 commit 1061b81
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
108 changes: 108 additions & 0 deletions components/Share.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.

// Copied from https://iconmonstr.com/facebook-4-svg/
function FacebookIcon() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
class="fill-[#1877F2]"
>
<path d="M12 0c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm3 8h-1.35c-.538 0-.65.221-.65.778v1.222h2l-.209 2h-1.791v7h-3v-7h-2v-2h2v-2.308c0-1.769.931-2.692 3.029-2.692h1.971v3z" />
</svg>
);
}

// Copied from https://iconmonstr.com/linkedin-3-svg/
function LinkedInIcon() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
class="fill-[#0077B5]"
>
<path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.238-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z" />
</svg>
);
}

// Copied from https://iconmonstr.com/reddit-4-svg/
function RedditIcon() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
class="fill-[#FF4500]"
>
<path d="M14.238 15.348c.085.084.085.221 0 .306-.465.462-1.194.687-2.231.687l-.008-.002-.008.002c-1.036 0-1.766-.225-2.231-.688-.085-.084-.085-.221 0-.305.084-.084.222-.084.307 0 .379.377 1.008.561 1.924.561l.008.002.008-.002c.915 0 1.544-.184 1.924-.561.085-.084.223-.084.307 0zm-3.44-2.418c0-.507-.414-.919-.922-.919-.509 0-.923.412-.923.919 0 .506.414.918.923.918.508.001.922-.411.922-.918zm13.202-.93c0 6.627-5.373 12-12 12s-12-5.373-12-12 5.373-12 12-12 12 5.373 12 12zm-5-.129c0-.851-.695-1.543-1.55-1.543-.417 0-.795.167-1.074.435-1.056-.695-2.485-1.137-4.066-1.194l.865-2.724 2.343.549-.003.034c0 .696.569 1.262 1.268 1.262.699 0 1.267-.566 1.267-1.262s-.568-1.262-1.267-1.262c-.537 0-.994.335-1.179.804l-2.525-.592c-.11-.027-.223.037-.257.145l-.965 3.038c-1.656.02-3.155.466-4.258 1.181-.277-.255-.644-.415-1.05-.415-.854.001-1.549.693-1.549 1.544 0 .566.311 1.056.768 1.325-.03.164-.05.331-.05.5 0 2.281 2.805 4.137 6.253 4.137s6.253-1.856 6.253-4.137c0-.16-.017-.317-.044-.472.486-.261.82-.766.82-1.353zm-4.872.141c-.509 0-.922.412-.922.919 0 .506.414.918.922.918s.922-.412.922-.918c0-.507-.413-.919-.922-.919z" />
</svg>
);
}

// Copied from https://iconmonstr.com/twitter-1-svg/
function TwitterIcon() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
class="fill-[#00ACEE]"
>
<path d="M24 4.557c-.883.392-1.832.656-2.828.775 1.017-.609 1.798-1.574 2.165-2.724-.951.564-2.005.974-3.127 1.195-.897-.957-2.178-1.555-3.594-1.555-3.179 0-5.515 2.966-4.797 6.045-4.091-.205-7.719-2.165-10.148-5.144-1.29 2.213-.669 5.108 1.523 6.574-.806-.026-1.566-.247-2.229-.616-.054 2.281 1.581 4.415 3.949 4.89-.693.188-1.452.232-2.224.084.626 1.956 2.444 3.379 4.6 3.419-2.07 1.623-4.678 2.348-7.29 2.04 2.179 1.397 4.768 2.212 7.548 2.212 9.142 0 14.307-7.721 13.995-14.646.962-.695 1.797-1.562 2.457-2.549z" />
</svg>
);
}

/**
* Dynamically generates links for sharing the current content on the major social media platforms.
*
* Inspired by https://schier.co/blog/pure-html-share-buttons
*
* Features:
* - Each link provides the title, where possible
* - Links are opened in a new page
* - Accessible labels are provided, as logos are used as the content for each link
* - Each logo respects the branding color of the respective social media platform.
*/
export default function Share(props: { url: URL; title: string }) {
return (
<div class="flex flex-row gap-4 my-4">
<span class="align-middle">Share</span>
<a
href={`https://www.facebook.com/sharer/sharer.php?u=${props.url.href}`}
target="_blank"
aria-label={`Share ${props.title} on Facebook`}
>
<FacebookIcon />
</a>
<a
href={`https://www.linkedin.com/shareArticle?url=${props.url.href}&title=${props.title}`}
target="_blank"
aria-label={`Share ${props.title} on LinkedIn`}
>
<LinkedInIcon />
</a>
<a
href={`https://reddit.com/submit?url=${props.url.href}&title=${props.title}`}
target="_blank"
aria-label={`Share ${props.title} on Reddit`}
>
<RedditIcon />
</a>
<a
href={`https://twitter.com/share?url=${props.url.href}&text=${props.title}`}
target="_blank"
aria-label={`Share ${props.title} on Twitter`}
>
<TwitterIcon />
</a>
</div>
);
}
3 changes: 2 additions & 1 deletion routes/blog/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CSS, render } from "$gfm";
import { getPost, Post } from "@/utils/posts.ts";
import type { State } from "@/routes/_middleware.ts";
import Head from "@/components/Head.tsx";
import { HEADING_STYLES } from "@/utils/constants.ts";
import Share from "@/components/Share.tsx";

interface BlogPostPageData extends State {
post: Post;
Expand Down Expand Up @@ -38,6 +38,7 @@ export default function PostPage(props: PageProps<BlogPostPageData>) {
{date}
</time>
)}
<Share url={new URL("https://google.com")} title={post.title} />
<div
class="mt-8 markdown-body !bg-transparent !dark:text-white"
data-color-mode="auto"
Expand Down

0 comments on commit 1061b81

Please sign in to comment.