Skip to content

Instantly share code, notes, and snippets.

@jonsuh
Created February 1, 2015 17:28
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jonsuh/2a88c7799461623d9d82 to your computer and use it in GitHub Desktop.
Save jonsuh/2a88c7799461623d9d82 to your computer and use it in GitHub Desktop.
Jekyll URL Encode
# _plugins/url_encode.rb
require 'liquid'
require 'uri'
# Percent encoding for URI conforming to RFC 3986.
# Ref: http://tools.ietf.org/html/rfc3986#page-12
module URLEncode
def url_encode(url)
return URI.escape(url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end
end
Liquid::Template.register_filter(URLEncode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment