[openstreetmap/openstreetmap-website] Add social sharing functionality (PR #4985)
Tom Hughes
notifications at github.com
Mon Aug 19 18:20:56 UTC 2024
@tomhughes requested changes on this pull request.
Added a few comments inline... Other things to consider are whether to offer some other sites - bluesky and threads being the obvious candidates.
> @@ -0,0 +1,27 @@
+// Opening pop-ups with share URL
+function openShareUrl(url, initialWidth = 640, initialHeight = 480) {
+ if (typeof url !== "string" || !url.startsWith("http")) {
+ console.error("Invalid URL"); // Consider removing this line if console warnings should be avoided.
Under what circumstances is this expected to happen?
> @@ -5,6 +5,7 @@
<%= javascript_include_tag "turbo", :type => "module" %>
<%= javascript_include_tag "application" %>
<%= javascript_include_tag "i18n/#{I18n.locale}" %>
+ <%= javascript_include_tag "social_share_button" %>
If this is going to be included everywhere then if can just be added to `app/assets/javascripts/application.js` rather than including it separately here.
The alternative is to do what `app/views/accounts/edit.html.erb` does to include it only in those view that use it.
> +
+ def self.generate_share_url(site, params)
+ site = site.to_sym
+ case site
+ when :email
+ "mailto:?subject=#{URI.encode_www_form_component(params[:title])}&body=#{URI.encode_www_form_component(params[:url])}"
+ when :x
+ via_str = params[:via] ? "&via=#{URI.encode_www_form_component(params[:via])}" : ""
+ hashtags_str = params[:hashtags] ? "&hashtags=#{URI.encode_www_form_component(params[:hashtags].join(','))}" : ""
+ "https://x.com/intent/tweet?url=#{URI.encode_www_form_component(params[:url])}&text=#{URI.encode_www_form_component(params[:title])}#{hashtags_str}#{via_str}"
+ when :linkedin
+ "https://www.linkedin.com/shareArticle?mini=true&url=#{URI.encode_www_form_component(params[:url])}"
+ when :facebook
+ "https://www.facebook.com/sharer/sharer.php?url=#{URI.encode_www_form_component(params[:url])}"
+ when :mastodon
+ "https://mastodon.social/share?text=#{URI.encode_www_form_component(params[:title])}&url=#{URI.encode_www_form_component(params[:url])}"
This is next to useless because it only works if your mastodon account is on `mastodon.social` which won't be true for most people...
> + [valid_sites, invalid_sites]
+ end
+
+ def self.icon_path(site)
+ SOCIAL_SHARE_CONFIG[site.to_sym] || ""
+ end
+
+ def self.valid_site?(site)
+ SOCIAL_SHARE_CONFIG.key?(site.to_sym)
+ end
+
+ def self.generate_share_url(site, params)
+ site = site.to_sym
+ case site
+ when :email
+ "mailto:?subject=#{URI.encode_www_form_component(params[:title])}&body=#{URI.encode_www_form_component(params[:url])}"
This doesn't work anyway, at least in firefox, because it just throws an invalid URL error when you click on a mailto URl with no address.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4985#pullrequestreview-2246176635
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/4985/review/2246176635 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240819/e49566e6/attachment.htm>
More information about the rails-dev
mailing list