Class: Jekyll::LocalizeLink
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::LocalizeLink
- Defined in:
- lib/jekyll-multiple-languages-plugin.rb
Overview
class LocalizeLink
Creates links or permalinks for translated pages. User must use the “tl” or “translate_link” liquid tags.
Instance Method Summary collapse
-
#initialize(tag_name, key, tokens) ⇒ LocalizeLink
constructor
initialize ======================================.
-
#render(context) ⇒ Object
render ======================================.
Constructor Details
#initialize(tag_name, key, tokens) ⇒ LocalizeLink
initialize
361 362 363 364 |
# File 'lib/jekyll-multiple-languages-plugin.rb', line 361 def initialize(tag_name, key, tokens) super @key = key end |
Instance Method Details
#render(context) ⇒ Object
render
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/jekyll-multiple-languages-plugin.rb', line 371 def render(context) if "#{context[@key]}" != "" # Check for page variable key = "#{context[@key]}" else key = @key end site = context.registers[:site] # Jekyll site object key = key.split namespace = key[0] lang = key[1] || site.config[ 'lang'] default_lang = site.config['default_lang'] baseurl = site.baseurl pages = site.pages url = ""; if default_lang != lang baseurl = baseurl + "/" + lang end for p in pages unless p['namespace'].nil? page_namespace = p['namespace'] if namespace == page_namespace permalink = p['permalink_'+lang] || p['permalink'] url = baseurl + permalink end end end url end |