Skip to content

Commit

Permalink
updated helpers and mapper to use X sharing links instead of twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyAdcockAND committed Feb 26, 2025
1 parent 63818b1 commit 35f7df7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
13 changes: 7 additions & 6 deletions assets/templates/partials/share-dataset/icon-handler.tmpl
Original file line number Diff line number Diff line change
@@ -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 }}

8 changes: 4 additions & 4 deletions helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand Down
1 change: 1 addition & 0 deletions helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}

Expand Down
16 changes: 8 additions & 8 deletions mapper/static_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35f7df7

Please sign in to comment.