Module: Jekyll::Filters::SocialNetwork
- Defined in:
- lib/jekyll/filters/social_network.rb
Constant Summary collapse
- MASTODON =
%r{\A/@\w+\z}.freeze
- NON_MASTODON =
%w[youtube.com tiktok.com]
- SUBDOMAINS =
/\A(www|chat)\./.freeze
- DOMAIN_MAP =
{ 't.me' => 'telegram', 'youtu.be' => 'youtube', 'open.spotify.com' => 'spotify' }.freeze
Instance Method Summary collapse
-
#social_network(url) ⇒ Hash
Takes a URL and returns a Hash of attributes, useful when you want to generate social network buttons from an undetermined list of URLs.
Instance Method Details
#social_network(url) ⇒ Hash
Takes a URL and returns a Hash of attributes, useful when you want to generate social network buttons from an undetermined list of URLs.
Example usage:
assign mastodon = ‘todon.nl/@sutty’ | social_network % <a href=“mastodon.url }”>
<i class="fa-{{ mastodon.name }}"></i>
{{ mastodon.name | capitalize }}
</a>
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jekyll/filters/social_network.rb', line 30 def (url) begin require 'uri' uri = URI url host = uri.host = uri.host.sub SUBDOMAINS, '' name = DOMAIN_MAP[host] name ||= mastodon?(uri) ? 'mastodon' : host.split('.', 2).first rescue ArgumentError, URI::InvalidURIError => e Jekyll.logger.warn(e.) if Jekyll.respond_to?(:logger) ensure host ||= url name ||= 'globe' end { 'host' => host, 'name' => name, 'url' => url }.to_liquid end |