module Jekyll::Filters::SocialNetwork

Constants

DOMAIN_MAP
SUBDOMAINS

Public Instance Methods

social_network(url) click to toggle source

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>

@param [String] @return [Hash]

   # File lib/jekyll/filters/social_network.rb
26 def social_network(url)
27   begin
28     require 'uri'
29 
30     uri  = URI url
31     host = uri.host.sub SUBDOMAINS, ''
32 
33     name   = DOMAIN_MAP[host]
34     name ||= %r{/@\w+} =~ uri.query ? 'mastodon' : host.split('.', 2).first
35   rescue ArgumentError, URI::InvalidURIError => e
36     Jekyll.logger.warn(e.message) if Jekyll.respond_to?(:logger)
37   ensure
38     host ||= url
39     name ||= 'globe'
40   end
41 
42   { 'host' => host, 'name' => name, 'url' => url }.to_liquid
43 end