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(title:, url:)
17 :class => "social-share-buttons d-flex gap-1 align-items-end flex-wrap mb-3"
19 safe_join(SOCIAL_SHARE_CONFIG.map do |site, icon|
22 :class => "rounded-circle focus-ring",
23 :title => I18n.t("application.share.#{site}.title"),
25 :data => { :share_type => site == :email ? "email" : "site" }
28 link_to generate_share_url(site, title, url), link_options do
29 image_tag(icon, :alt => I18n.t("application.share.#{site}.alt"), :size => 28)
37 def generate_share_url(site, title, url)
39 title = URI.encode_uri_component(title)
40 url = URI.encode_uri_component(url)
44 "mailto:?subject=#{title}&body=#{url}"
46 "https://x.com/intent/tweet?url=#{url}&text=#{title}"
48 "https://www.linkedin.com/sharing/share-offsite/?url=#{url}"
50 "https://www.facebook.com/sharer/sharer.php?u=#{url}&t=#{title}"
52 "https://mastodonshare.com/?text=#{title}&url=#{url}"
54 "https://t.me/share/url?url=#{url}&text=#{title}"
56 "https://bsky.app/intent/compose?text=#{title}+#{url}"
58 raise ArgumentError, "Unsupported platform: #{platform}"