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-button d-flex gap-1 align-items-end flex-wrap mb-3"
19 safe_join(SOCIAL_SHARE_CONFIG.map do |site, icon|
22 :class => "ssb-icon rounded-circle",
23 :title => I18n.t("application.share.#{site}.title"),
27 link_to generate_share_url(site, title, url), link_options do
28 image_tag(icon, :alt => I18n.t("application.share.#{site}.alt"), :size => 28)
36 def generate_share_url(site, title, url)
38 title = URI.encode_www_form_component(title)
39 url = URI.encode_www_form_component(url)
43 "mailto:?subject=#{title}&body=#{url}"
45 "https://x.com/intent/tweet?url=#{url}&text=#{title}"
47 "https://www.linkedin.com/sharing/share-offsite/?url=#{url}"
49 "https://www.facebook.com/sharer/sharer.php?u=#{url}&t=#{title}"
51 "https://mastodonshare.com/?text=#{title}&url=#{url}"
53 "https://t.me/share/url?url=#{url}&text=#{title}"
55 "https://bsky.app/intent/compose?text=#{title}+#{url}"
57 raise ArgumentError, "Unsupported platform: #{platform}"