Sha256: ea2fa28c450512799ff7dac11059197e7f6e8ec2cf62a4b5f26c80fb24c834f6
Contents?: true
Size: 1.04 KB
Versions: 8
Compression:
Stored size: 1.04 KB
Contents
# frozen_string_literal: true module Jekyll module Filters module SocialNetwork # 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 = 'https://todon.nl/@sutty' | social_network %} # <a href="{{ mastodon.url }}"> # <i class="fa-{{ mastodon.name }}"></i> # # {{ mastodon.name | capitalize }} # </a> # # @param [String] # @return [Hash] def social_network(url) return {} unless url.is_a? String require 'uri' uri = URI url uri.host.sub! 'www.', '' name = %r{/@\w+} =~ uri.query ? 'mastodon' : uri.host.split('.', 2).first { 'host' => uri.host, 'name' => name, 'url' => url }.to_liquid rescue URI::InvalidURIError => e Jekyll.logger.warn e.message {}.to_liquid end end end end Liquid::Template.register_filter(Jekyll::Filters::SocialNetwork)
Version data entries
8 entries across 8 versions & 1 rubygems