Skip to content

Instantly share code, notes, and snippets.

@czenzel
Last active November 30, 2017 18:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save czenzel/515acd4320e5eae4ca77 to your computer and use it in GitHub Desktop.
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)
# 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)
@czenzel
Copy link
Author

czenzel commented Apr 12, 2015

Some issues yet to be solved:

  • Allow post URLs to be written from liquid for blog instead of on-demand jQuery (for search engines in case you want to publish a site / SEO).
  • Some testing of various environments.
  • Allow the user to configure the permalink test structure in the config file instead of directly hard coding a value.

@czenzel
Copy link
Author

czenzel commented Jun 13, 2015

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment