From 35f7df71a252fd921b913173cf213a996640810d Mon Sep 17 00:00:00 2001 From: Jonathan Adcock Date: Wed, 26 Feb 2025 10:46:39 +0000 Subject: [PATCH] updated helpers and mapper to use X sharing links instead of twitter --- .../partials/share-dataset/icon-handler.tmpl | 13 +++++++------ helpers/helpers.go | 8 ++++---- helpers/helpers_test.go | 1 + mapper/static_base.go | 16 ++++++++-------- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/assets/templates/partials/share-dataset/icon-handler.tmpl b/assets/templates/partials/share-dataset/icon-handler.tmpl index 1ab16b1b..8502c6d4 100644 --- a/assets/templates/partials/share-dataset/icon-handler.tmpl +++ b/assets/templates/partials/share-dataset/icon-handler.tmpl @@ -1,11 +1,12 @@ {{ $icon := . }} -{{ if eq $icon "facebook" }} +{{ if eq $icon "email" }} + {{ template "icons/email" }} +{{ else if eq $icon "facebook" }} {{ template "icons/facebook" }} -{{ else if eq $icon "twitter" }} - {{ template "icons/twitter" }} {{ else if eq $icon "linkedin" }} {{ template "icons/linkedin" }} -{{ else if eq $icon "email" }} - {{ template "icons/email" }} +{{ else if eq $icon "twitter" }} + {{ template "icons/twitter" }} +{{ else if eq $icon "x" }} + {{ template "icons/x" }} {{ end }} - diff --git a/helpers/helpers.go b/helpers/helpers.go index 4fe9cb2e..61e5de5f 100644 --- a/helpers/helpers.go +++ b/helpers/helpers.go @@ -50,14 +50,14 @@ func GetCurrentURL(lang, siteDomain, urlPath string) string { // GenerateSharingLink returns a sharing link for different types of social media func GenerateSharingLink(socialType, currentURL, title string) string { switch socialType { + case "email": + return fmt.Sprintf("mailto:?subject=%s&body=%s\n%s", title, title, currentURL) case "facebook": return fmt.Sprintf("https://www.facebook.com/sharer/sharer.php?u=%s", currentURL) - case "twitter": - return fmt.Sprintf("https://twitter.com/intent/tweet?original_referer&text=%s&url=%s", title, currentURL) case "linkedin": return fmt.Sprintf("https://www.linkedin.com/sharing/share-offsite/?url=%s", currentURL) - case "email": - return fmt.Sprintf("mailto:?subject=%s&body=%s\n%s", title, title, currentURL) + case "twitter", "x": + return fmt.Sprintf("https://%s.com/intent/tweet?original_referer&text=%s&url=%s", socialType, title, currentURL) default: return "" } diff --git a/helpers/helpers_test.go b/helpers/helpers_test.go index 12d3ffab..7ffcdc7e 100644 --- a/helpers/helpers_test.go +++ b/helpers/helpers_test.go @@ -81,6 +81,7 @@ func TestGenerateSharingLink(t *testing.T) { So(GenerateSharingLink("twitter", url, title), ShouldResemble, fmt.Sprintf("https://twitter.com/intent/tweet?original_referer&text=%s&url=%s", title, url)) So(GenerateSharingLink("linkedin", url, title), ShouldResemble, fmt.Sprintf("https://www.linkedin.com/sharing/share-offsite/?url=%s", url)) So(GenerateSharingLink("email", url, title), ShouldResemble, fmt.Sprintf("mailto:?subject=%s&body=%s\n%s", title, title, url)) + So(GenerateSharingLink("x", url, title), ShouldResemble, fmt.Sprintf("https://x.com/intent/tweet?original_referer&text=%s&url=%s", title, url)) }) } diff --git a/mapper/static_base.go b/mapper/static_base.go index 15b9a0c2..25380866 100644 --- a/mapper/static_base.go +++ b/mapper/static_base.go @@ -191,25 +191,25 @@ func buildStaticSharingDetails(d dataset.DatasetDetails, lang, currentURL string shareDetails := static.ShareDetails{} shareDetails.Language = lang shareDetails.ShareLocations = []static.Share{ + { + Title: "Email", + Link: helpers.GenerateSharingLink("email", currentURL, d.Title), + Icon: "email", + }, { Title: "Facebook", Link: helpers.GenerateSharingLink("facebook", currentURL, d.Title), Icon: "facebook", }, - { - Title: "Twitter", - Link: helpers.GenerateSharingLink("twitter", currentURL, d.Title), - Icon: "twitter", - }, { Title: "LinkedIn", Link: helpers.GenerateSharingLink("linkedin", currentURL, d.Title), Icon: "linkedin", }, { - Title: "Email", - Link: helpers.GenerateSharingLink("email", currentURL, d.Title), - Icon: "email", + Title: "X", + Link: helpers.GenerateSharingLink("x", currentURL, d.Title), + Icon: "x", }, } return shareDetails