Last active
November 30, 2017 18:01
-
-
Save czenzel/515acd4320e5eae4ca77 to your computer and use it in GitHub Desktop.
USB and File System Root URL for Jekyll Generated Sites (File System Jekyll without Web Server)
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
# USB / File System Root and URL Root for Jekyll | |
# | |
# Description: Create links and paths within your site using a file system root | |
# Description: This plugin is not limited to USB use for a Jekyll Static Site | |
# | |
# Built by: Christopher Zenzel, AA, IST | |
# Purpose: A Jekyll Web Site containing my Resume for distribution via USB | |
# Built: 2015 | |
# | |
# Please use as you want, but please give credit back to my GIST or | |
# http://github.com/czenzel and http://linkedin.com/in/chriszenzel | |
# | |
# Thank you for your interest in my source code! | |
# | |
# Will this work in GitHub Pages? The answer: No. GitHub Pages does not load Jekyll | |
# plugins at this time. Please generate your site staticlly on another branch and | |
# upload your static site to the gh-pages branch with the static code. | |
# | |
module Jekyll | |
class USBPostURL < Liquid::Tag | |
def initialize(tag_name, variable, tokens) | |
super | |
end | |
def render(context) | |
page_path = context.environments.first["page"]["path"] | |
page_path = page_path.split("/") | |
path_length = page_path.size | |
path_length = path_length - 1 | |
usb_path = '' | |
for i in 1..path_length | |
usb_path = usb_path + '../' | |
end | |
if path_length == 0 | |
usb_path = '.' | |
end | |
usb_path = usb_path.gsub(/\/$/, '') | |
usb_path | |
end | |
end | |
class USBRoot < Liquid::Tag | |
def initialize(tag_name, text, tokens) | |
super | |
end | |
def render(context) | |
if /^[_]posts/ =~ context.environments.first["page"]["path"] | |
page_path = 'blog/test/test/test/test.html' | |
else | |
page_path = context.environments.first["page"]["path"] | |
end | |
page_path = page_path.split("/") | |
path_length = page_path.size | |
path_length = path_length - 1 | |
usb_path = '' | |
for i in 1..path_length | |
usb_path = usb_path + '../' | |
end | |
if path_length == 0 | |
usb_path = '.' | |
end | |
usb_path = usb_path.gsub(/\/$/, '') | |
usb_path | |
end | |
end | |
end | |
Liquid::Template.register_tag('usb_root', Jekyll::USBRoot) | |
Liquid::Template.register_tag('usb_post_url', Jekyll::USBPostURL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey everyone! Some updates to the source code for the USB and File System Root plugin for Jekyll Static Generator:
Some issues yet:
License: