Skip to content

Instantly share code, notes, and snippets.

@jamesan
Created April 14, 2011 11:08
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamesan/919275 to your computer and use it in GitHub Desktop.
Save jamesan/919275 to your computer and use it in GitHub Desktop.
Percent encoding for URI conforming to RFC 3986. Ref: http://tools.ietf.org/html/rfc3986#page-12
require 'liquid'
require 'uri'
# Percent encoding for URI conforming to RFC 3986.
# Ref: http://tools.ietf.org/html/rfc3986#page-12
module URLEncoding
def url_encode(url)
return URI.escape(url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end
end
Liquid::Template.register_filter(URLEncoding)
@chinchang
Copy link

How is this plugin supposed to be used while writing my template?

@Hezion
Copy link

Hezion commented Apr 28, 2013

see https://github.com/mojombo/jekyll/wiki/Liquid-Extensions

so you would probably want sth like this:

{{ post.title | URLEncoding }}

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