1 module SocialShareButtonHelper
4 SOCIAL_SHARE_CONFIG = {
5 :email => "social_icons/email.svg",
6 :bluesky => "social_icons/bluesky.svg",
7 :facebook => "social_icons/facebook.svg",
8 :linkedin => "social_icons/linkedin.svg",
9 :mastodon => "social_icons/mastodon.svg",
10 :telegram => "social_icons/telegram.svg",
11 :x => "social_icons/x.svg"
14 # Generates a set of social share buttons based on the specified options.
15 def social_share_buttons(opts = {})
17 :class => "social-share-button d-flex gap-1 align-items-end flex-wrap mb-3"
19 SOCIAL_SHARE_CONFIG.map do |site, icon|
21 :rel => ["nofollow", opts[:rel]].compact,
22 :class => "ssb-icon rounded-circle",
23 :title => I18n.t("application.share.#{site}.title"),
27 link_to generate_share_url(site, opts), link_options do
28 image_tag(icon, :alt => I18n.t("application.share.#{site}.alt"), :size => 28)
36 def generate_share_url(site, params)
40 to = params[:to] || ""
41 subject = CGI.escape(params[:title])
42 body = CGI.escape(params[:url])
43 "mailto:#{to}?subject=#{subject}&body=#{body}"
45 via_str = params[:via] ? "&via=#{URI.encode_www_form_component(params[:via])}" : ""
46 hashtags_str = params[:hashtags] ? "&hashtags=#{URI.encode_www_form_component(params[:hashtags].join(','))}" : ""
47 "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}"
49 "https://www.linkedin.com/sharing/share-offsite/?url=#{URI.encode_www_form_component(params[:url])}"
51 "https://www.facebook.com/sharer/sharer.php?u=#{URI.encode_www_form_component(params[:url])}&t=#{URI.encode_www_form_component(params[:title])}"
53 "https://mastodonshare.com/?text=#{URI.encode_www_form_component(params[:title])}&url=#{URI.encode_www_form_component(params[:url])}"
55 "https://t.me/share/url?url=#{URI.encode_www_form_component(params[:url])}&text=#{URI.encode_www_form_component(params[:title])}"
57 "https://bsky.app/intent/compose?text=#{URI.encode_www_form_component(params[:title])}+#{URI.encode_www_form_component(params[:url])}"
59 raise ArgumentError, "Unsupported platform: #{platform}"