Created
January 7, 2016 20:12
-
-
Save ChaseIndustries/7a8fe3f64d009606838e to your computer and use it in GitHub Desktop.
Jekyll Relative Links plugin - Use {% base %} before your relative link to add the correct path to the beginning of your URL
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
module Jekyll | |
class Base < Liquid::Tag | |
def initialize(tag_name, text, tokens) | |
super | |
end | |
def render(context) | |
page = context['page'] | |
depth = page['path'].split('/').size() | |
case depth | |
when 1 | |
$base = '.' | |
when 2 | |
$base = '..' | |
when 3 | |
$base = '../..' | |
when 4 | |
$base = '../../..' | |
when 5 | |
$base = '../../../..' | |
end | |
$base | |
end | |
end | |
end | |
Liquid::Template.register_tag('base', Jekyll::Base) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment