Skip to content

Instantly share code, notes, and snippets.

@Akumzy
Last active January 16, 2021 21:38
Show Gist options
  • Save Akumzy/459953868b2cd6c9b0ca2d0a194bc4d7 to your computer and use it in GitHub Desktop.
Save Akumzy/459953868b2cd6c9b0ca2d0a194bc4d7 to your computer and use it in GitHub Desktop.
The socialShare function will return the right platform link
interface SocialsOptions {
text?: string
url: string
hashtags?: string
title?: string
}
export function socialShare(
data: SocialsOptions | string,
platform:
| 'twitter'
| 'facebook'
| 'linkedin'
| 'hackernews'
| 'reddit'
| 'whatsapp'
) {
switch (platform) {
case 'twitter':
data = data as SocialsOptions
return `https://twitter.com/intent/tweet?url=${data.url}&text=${data.text}&hashtags=${data.hashtags}`
case 'linkedin':
data = data as string
return `https://www.linkedin.com/cws/share?url=${data}`
case 'facebook':
data = data as string
return `https://www.facebook.com/sharer/sharer.php?u=${data}`
case 'reddit':
data = data as SocialsOptions
return `https://www.reddit.com/submit?url=${data.url}&title=${data.title}`
case 'hackernews':
data = data as SocialsOptions
return `https://news.ycombinator.com/submitlink?u=${data.url}&t=${data.title}`
case 'whatsapp':
data = data as SocialsOptions
return `https://api.whatsapp.com/send?text=${data.title} ${data.url}`
default:
break
}
return ''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment