From 7afd4f9c98c8738c4dbc0ff24a9d8f4d8984bd7e Mon Sep 17 00:00:00 2001 From: Paulo Date: Mon, 15 Nov 2021 13:00:29 +0000 Subject: [PATCH] Fix hashtag sending through 'undefined' if empty (#20) * Fix hashtag sending through 'undefined' if empty * Bump package version to 0.0.5 --- package-lock.json | 4 ++-- package.json | 2 +- src/utils/getFacebookUrl.ts | 13 ++++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index cc2cc28..94969ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@phntms/react-share", - "version": "0.0.4", + "version": "0.0.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@phntms/react-share", - "version": "0.0.4", + "version": "0.0.5", "license": "MIT", "dependencies": { "is-absolute-url": "^3.0.3" diff --git a/package.json b/package.json index 66e60f5..6c049eb 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@phntms/react-share", "description": "An all-in-one React library to implement custom Sharing Meta and Social Media Sharing Buttons.", - "version": "0.0.4", + "version": "0.0.5", "main": "lib/index.js", "types": "lib/index.d.ts", "homepage": "https://github.com/phantomstudios/react-share#readme", diff --git a/src/utils/getFacebookUrl.ts b/src/utils/getFacebookUrl.ts index ebe92c7..e23a7f7 100644 --- a/src/utils/getFacebookUrl.ts +++ b/src/utils/getFacebookUrl.ts @@ -9,11 +9,18 @@ export interface FacebookProps extends BaseShareProps { hashtag?: string; } -export const getFacebookUrl = ({ url, quote, hashtag }: FacebookProps) => - `https://www.facebook.com/sharer/sharer.php${objectToUrlParams({ +export const getFacebookUrl = ({ + url, + quote, + hashtag: suppliedHashtag, +}: FacebookProps) => { + let hashtag = suppliedHashtag; + if (hashtag && hashtag.charAt(0) !== "#") hashtag = `#${hashtag}`; + return `https://www.facebook.com/sharer/sharer.php${objectToUrlParams({ u: url, quote, - hashtag: hashtag?.charAt(0) === "#" ? hashtag : `#${hashtag}`, + hashtag, })}`; +}; export default getFacebookUrl;