Created
January 20, 2018 16:31
-
-
Save espen/641d14891999a22060af1079fd46bf9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use: {% link about.html %} | |
module Jekyll | |
class LinkLang < Liquid::Tag | |
def initialize(tag_name, link, tokens) | |
super | |
@link = link.strip | |
end | |
def render(context) | |
@context = context | |
find(@link) | |
end | |
private | |
def find(link) | |
language = @context.registers[:page]["language"] | |
@context.registers[:site].pages.each do |page| | |
if page.respond_to?(:language) | |
if page.language == language && page.name == link | |
return page.url | |
end | |
end | |
end | |
end | |
end | |
end | |
Liquid::Template.register_tag('link_lang', Jekyll::LinkLang) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment