Skip to content

Instantly share code, notes, and snippets.

@ahaywood
Created October 28, 2024 18:54
Show Gist options
  • Save ahaywood/1a0fbf58fb27420203d9351eb9e3c111 to your computer and use it in GitHub Desktop.
Save ahaywood/1a0fbf58fb27420203d9351eb9e3c111 to your computer and use it in GitHub Desktop.
Social Share Link Helpers
export const getTwitterUrl = ({ url, description, hashtags }: {
url: string,
description: string,
hashtags: string
}) => {
const encodedUrl = encodeURIComponent(url)
const encodedDescription = encodeURIComponent(description)
const encodedHashtags = encodeURIComponent(hashtags)
return `https://twitter.com/intent/tweet?url=${encodedUrl}&text=${encodedDescription}&hashtags=${encodedHashtags}`
}
export const getFacebookUrl = ({ url }: { url: string }) => {
const encodedUrl = encodeURIComponent(url)
return `https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}`
}
export const getWhatsAppUrl = ({ content }: { content: string }) => {
const encodedText = encodeURIComponent(content)
return `https://api.whatsapp.com/send?text=${encodedText}`;
}
export const getEmailUrl = ({ subject, body }: { subject: string, body: string }) => {
return `mailto:?subject=${subject}&body=${body}`
}
export const getLinkedInUrl = ({ url, title, summary }: { url: string, title: string, summary: string }) => {
const encodedUrl = encodeURIComponent(url)
const encodedTitle = encodeURIComponent(title)
const encodedSummary = encodeURIComponent(summary)
return `https://www.linkedin.com/shareArticle?mini=true&url=${encodedUrl}&title=${encodedTitle}&summary=${encodedSummary}&source=${encodedTitle}`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment