-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: share through social platforms
- Loading branch information
1 parent
fb72578
commit b2e90f3
Showing
5 changed files
with
90 additions
and
33 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useRouter } from 'next/router' | ||
import { AppRoutes } from '@/config/routes' | ||
import XIcon from '@/public/images/x-icon.svg' | ||
import LinkedinIcon from '@/public/images/linkedin-icon.svg' | ||
import { type Entry } from 'contentful' | ||
import { type TypeAuthorSkeleton } from '@/contentful/types' | ||
import { IconButton, SvgIcon } from '@mui/material' | ||
import css from '../styles.module.css' | ||
|
||
const Socials = ({ title, authors }: { title: string; authors: Entry<TypeAuthorSkeleton, undefined, string>[] }) => { | ||
const router = useRouter() | ||
|
||
const currentUrl = `${AppRoutes.blog}${router.asPath}` | ||
|
||
const sharingText = `${title} by @${authors | ||
.map((author) => author.fields.name) | ||
.join(', @') | ||
.toString()}` | ||
|
||
const xUrl = `https://twitter.com/intent/tweet?url=${encodeURIComponent(currentUrl)}&text=${encodeURIComponent( | ||
sharingText, | ||
)}` | ||
const linkedinUrl = `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(currentUrl)}` | ||
|
||
return ( | ||
<div className={css.socials}> | ||
{/* X */} | ||
<IconButton aria-label="Share on X" href={xUrl} target="_blank" rel="noreferrer" size="small"> | ||
<SvgIcon component={XIcon} fontSize="inherit" color="inherit" inheritViewBox /> | ||
</IconButton> | ||
|
||
{/* Linkedin */} | ||
<IconButton aria-label="Share on Linkedin" href={linkedinUrl} target="_blank" rel="noreferrer" size="small"> | ||
<SvgIcon component={LinkedinIcon} fontSize="inherit" color="inherit" inheritViewBox /> | ||
</IconButton> | ||
</div> | ||
) | ||
} | ||
|
||
export default Socials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters