frozen-filters
Liquid Tags for jekyllrb
Description
Liquid filters for shopify liquid template engine.
This ruby gem is a port of frozen-filters-js.
Installation
gem install frozen-filters
Usage
Usage outside jekyllrb
:
require 'liquid'
require 'frozen-filters'
vars = {
'url' => 'http://www.example.com/first/second/index.html?param1=value1¶m2=value2'
}
@template = Liquid::Template.parse('{{ url | remove_ext }}')
@template.render(vars) # http://www.example.com/first/second/index?param1=value1¶m2=value2
Usage within jekyllrb
:
- Add to blog
Gemfile
:
gem "frozen-filters", "~> 0.3.0"
- Add to
plugins
section of blog_config.yml
:
- frozen-filters
- Use the filters on any liquid page.e.g.
{{ "/assets/main.css" | remove_ext }}
Filters
Url Filters
remove_ext
- Removes the extension part of an url.
e.g.http://www.example.com/first/second/index?param1=value1¶m2=value2
.remove_qs
- Removes the query string part of an url. e.g.http://www.example.com/first/second/index.html
.extract_basename
- Returns the basename of an url. e.g.index.html
.extract_dirname
- Returns the dirname of an url. e.g./first/second
.extract_path
- Returns the path of an url. e.g./first/second/index.html
.extract_protocol
- Returns the protocol. e.g.http
.extract_qs
- Returns the query string. e.g.param1=value1¶m2=value2
.
Array Filters
array_head
- Returns the firstN
elements of an array.
e.g.{{ ["first","second","third"] | array_head: 2 }}
=~["first","second"]
.
If the number of parameters is negative it returns an empty array.
The the input isn't an array it returns the untouched input.array_tail
- Returns the lastN
elements of an array.
e.g.{{ ["first","second","third"] | array_tail: 2 }}
=~["first","second"]
.
If the number of parameters is negative it returns an empty array.
The the input isn't an array it returns the untouched input.array_to_taglist
- Transforms an array into an enclosed html tag list separated by newline.
e.g.{{ ["first","second" | array_to_taglist: "li" }}
returns:
<li>first</li>
<li>second</li>
If the input isn't an array, it returns the untouched input.
Internationalization
The url filters support domains and paths with:
- non-latin characters.
e.g.http://吃.高雄/第一/第二/首頁.html?param1=value1¶m2=value2
. - punycodes:
e.g.https://xn--jp-cd2fp15c.xn--fsq.jp/abc/index.html?param1=value1¶m2=value2
.
Copyrights
© 2018 Alexandre Bento Freire
License
You might also like
How to use f-strings in Python
What are lists, arrays, and linked lists
Linux Zip alternatives
How to scrape a webpage using ChatGPT 5 and Python
Introduction to Stacks and Queues: A Beginner’s Guide with Java, JavaScript, and Python Examples
Get started programming with Python and ChatGPT
Can AI Create A Webpage To Plot Stock Prices
What is a CPU, FPU, GPU, TPU, and NPU? Understanding the Hardware Driving Modern Computing
Can ChatGPT Analyze The FIFA World Cup Results from a JSON File
What are the best computer languages to learn in 2025
Travel Ideas
Travel to Lisbon
Best day trips near Lisbon, Portugal
Travel to Chichen Itza, Mexico
Quilotoa Loop: A Solo Hiker’s Journey with an Unexpected Companion
Travel to Machu Picchu, Peru
Best beaches in Thailand
Best beaches near Lisbon, Portugal
Best places to visit in Thailand