How to code url in jekyll fluid?

I have a problem with the fact that categories are not url encoded when I use German words with Umlauts (e.g. Γ€, ΓΌ). I tried cgi_escape, which offers Liquid, but success with the following code:

<strong>Kategorien</strong><br/> {% for category in site.categories do %} <small><a href="/categories/{{ category[0] | cgi_escape }}">{{ category[0] }} </a><br/> </small> {% endfor %} 

Can anyone help?

+4
source share
2 answers

Using cgi_escape does not work correctly for categories with spaces. Links were generated as /category/the+category instead of /category/the%20category .

The solution I ended up using was from this blog post :

 # _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 URLEncoding def url_encode(url) return URI.escape(url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) end end Liquid::Template.register_filter(URLEncoding) 

A plus is a literal plus anywhere, but in the query part of the URL where it represents a space. Good URL Encoding Link

+5
source

@Peterb, have you upgraded to the latest version of Jekyll? The current version 1.0x supports UTF-8 and handles URLs as much better.

You can install the latest version by running it from the terminal command line:

$ [sudo] gem install jekyll --pre

This issue of the GitHub Issue will cover the issue: https://github.com/mojombo/jekyll/issues/960

0
source

All Articles