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"
20 tag.button(:type => "button",
21 :class => "btn btn-secondary p-1 border-1 rounded-circle",
22 :title => I18n.t("application.share.share.title"),
24 :data => { :share_type => "native",
26 :share_url => url }) do
27 image_tag("social_icons/share.svg", :alt => I18n.t("application.share.share.alt"), :size => 18, :class => "d-block")
31 buttons << SOCIAL_SHARE_CONFIG.map do |site, icon|
34 :class => "rounded-circle focus-ring",
35 :title => I18n.t("application.share.#{site}.title"),
37 :data => { :share_type => site == :email ? "email" : "site" }
40 link_to generate_share_url(site, title, url), link_options do
41 image_tag(icon, :alt => I18n.t("application.share.#{site}.alt"), :size => 28)
45 safe_join(buttons, "\n")
51 def generate_share_url(site, title, url)
53 title = URI.encode_uri_component(title)
54 url = URI.encode_uri_component(url)
58 "mailto:?subject=#{title}&body=#{url}"
60 "https://x.com/intent/tweet?url=#{url}&text=#{title}"
62 "https://www.linkedin.com/sharing/share-offsite/?url=#{url}"
64 "https://www.facebook.com/sharer/sharer.php?u=#{url}&t=#{title}"
66 "https://mastodonshare.com/?text=#{title}&url=#{url}"
68 "https://t.me/share/url?url=#{url}&text=#{title}"
70 "https://bsky.app/intent/compose?text=#{title}+#{url}"
72 raise ArgumentError, "Unsupported platform: #{platform}"