Class: Jekyll::Polyglot::Liquid::I18nHeadersTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll/polyglot/liquid/tags/i18n-headers.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ I18nHeadersTag

Returns a new instance of I18nHeadersTag.


5
6
7
8
9
10
# File 'lib/jekyll/polyglot/liquid/tags/i18n-headers.rb', line 5

def initialize(tag_name, text, tokens)
  super
  @url = text
  @url.strip!
  @url.chomp! '/'
end

Instance Method Details

#render(context) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jekyll/polyglot/liquid/tags/i18n-headers.rb', line 12

def render(context)
  site = context.registers[:site]
  permalink = context.registers[:page]['permalink']
  site_url = @url.empty? ? site.config['url'] : @url
  i18n = "<meta http-equiv=\"Content-Language\" content=\"#{site.active_lang}\">\n"
  i18n += "<link rel=\"alternate\" hreflang=\"#{site.default_lang}\" "\
  "href=\" #{site_url}#{permalink}\"/>\n"
  site.languages.each do |lang|
    next if lang == site.default_lang
    i18n += "<link rel=\"alternate\" hreflang=\"#{lang}\" "\
    "href=\"#{site_url}/#{lang}#{permalink}\"/>\n"
  end
  i18n
end