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
26
27
28
# File 'lib/jekyll/polyglot/liquid/tags/i18n_headers.rb', line 12

def render(context)
  site = context.registers[:site]
  permalink = context.registers[:page]['permalink']
  permalink_lang = context.registers[:page]['permalink_lang']
  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

    url = permalink_lang && permalink_lang[lang] ? permalink_lang[lang] : permalink
    i18n += "<link rel=\"alternate\" hreflang=\"#{lang}\" "\
    "href=\"#{site_url}/#{lang}/#{url}\"/>\n"
  end
  i18n
end