Class: Jekyll::UJSocialTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::UJSocialTag
- Includes:
- Jekyll::UJPowertools::VariableResolver
- 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
Methods included from Jekyll::UJPowertools::VariableResolver
#is_quoted?, #parse_arguments, #parse_options, #resolve_input, #resolve_variable
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ UJSocialTag
Returns a new instance of UJSocialTag.
27 28 29 30 |
# File 'lib/tags/social.rb', line 27 def initialize(tag_name, markup, tokens) super @markup = markup.strip end |
Instance Method Details
#render(context) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tags/social.rb', line 32 def render(context) # Resolve the platform name (handles both literals and variables) platform = resolve_input(context, @markup) || @markup # 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 |