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 hidden or 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) |
Hey everyone! Some updates to the source code for the USB and File System Root plugin for Jekyll Static Generator:
- You can now generate URL or File Paths using the File System
- With some modifications you can now have all your pages generate some SEO complaint links
- You no longer need JavaScript or jQuery to modify links on the fly. You must code navigations, category lists, and other archive lists properly on your blog to reflect SEO properly using this plugin
Some issues yet:
- Allow user or developer to configure sample blog permalink in a configuration file (config.yml) so it is not hard coded within the plugin
License:
- Use as you please but please give credit back to this GIST or my GitHub at http://github.com/czenzel and Linked-In profile at http://linkedin.com/in/chriszenzel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some issues yet to be solved: