Class: Jekyll::UJSocialTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::UJSocialTag
- Defined in:
- lib/tags/social.rb
Constant Summary collapse
- SOCIAL_URLS =
Social platform URL patterns
{ 'facebook' => 'https://facebook.com/%s', 'twitter' => 'https://twitter.com/%s', 'linkedin' => 'https://linkedin.com/in/%s', 'youtube' => 'https://youtube.com/@%s', 'instagram' => 'https://instagram.com/%s', 'tumblr' => 'https://%s.tumblr.com', 'slack' => 'https://%s.slack.com', 'discord' => 'https://discord.gg/%s', 'github' => 'https://github.com/%s', 'dev' => 'https://dev.to/%s', 'tiktok' => 'https://tiktok.com/@%s', 'twitch' => 'https://twitch.tv/%s', 'soundcloud' => 'https://soundcloud.com/%s', 'spotify' => 'https://open.spotify.com/user/%s', 'mixcloud' => 'https://mixcloud.com/%s' }
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ UJSocialTag
constructor
A new instance of UJSocialTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ UJSocialTag
25 26 27 28 |
# File 'lib/tags/social.rb', line 25 def initialize(tag_name, markup, tokens) super @markup = markup.strip end |
Instance Method Details
#render(context) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tags/social.rb', line 30 def render(context) # Parse the platform name (can be quoted or unquoted) platform_input = parse_argument(@markup) # Resolve the platform name (could be a variable or literal string) platform = resolve_variable(context, platform_input) # If it didn't resolve to anything, use the input as a literal string platform = platform_input if platform.nil? || platform.empty? # Get the social handle from page.resolved.socials.{platform} page = context['page'] return '' unless page = page['resolved'] && page['resolved']['socials'] && page['resolved']['socials'][platform] return '' unless && !.empty? # Get the URL pattern for this platform url_pattern = SOCIAL_URLS[platform] return '' unless url_pattern # Build the URL url_pattern % end |