-
-
Save JoeyGo23/1f913b9771cfa2c0b601 to your computer and use it in GitHub Desktop.
Revisions
-
magicznyleszek revised this gist
Jun 2, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Jekyll & Liquid Cheatsheet A list of the most common functionalities in Jekyll (Liquid). You can use [Jekyll](http://jekyllrb.com/) with [GitHub Pages](https://pages.github.com/), just make sure you are using [the proper version](https://pages.github.com/versions/). ## Running -
magicznyleszek revised this gist
May 18, 2014 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,6 +57,13 @@ Word hello has {{ 'hello' | size }} letters! Todat is {{ 'now' | date: "%Y %h" }} ``` Useful `where` filter example of getting single item from `_data`: ``` {% assign currentItem = site.data.foo | where:"slug","bar" %} {{ newArray[0].name }} ``` Most common filters: - `where` -- select elements from array with given property value: `{{ site.posts | where:"category","foo" }}` -
magicznyleszek revised this gist
May 18, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ Running a local server for testing purposes: ``` jekyll serve jekyll serve --watch --baseurl '' ``` Creating a final outcome (or for testing on a server): @@ -19,7 +19,7 @@ jekyll build jekyll build -w ``` The `-w` or `--watch` flag is for enabling auto-regeneration, the `--baseurl ''` one is useful for server testing. ### Troubleshooting -
magicznyleszek revised this gist
May 18, 2014 . 1 changed file with 33 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,15 +8,19 @@ A list of the most common functionalities in Jekyll (Liquid). Running a local server for testing purposes: ``` jekyll serve jekyll serve -w ``` Creating a final outcome (or for testing on a server): ``` jekyll build jekyll build -w ``` The `-w` or `--watch` flag is for enabling auto-regeneration ### Troubleshooting @@ -55,14 +59,18 @@ Todat is {{ 'now' | date: "%Y %h" }} Most common filters: - `where` -- select elements from array with given property value: `{{ site.posts | where:"category","foo" }}` - `group_by` -- group elements from array by given property: `{{ site.posts | group_by:"category" }}` - `markdownify` -- convert markdown to HTML - `jsonify` -- convert data to JSON: `{{ site.data.dinosaurs | jsonify }}` - `date` -- reformat a date (syntax reference) - `capitalize` -- capitalize words in the input sentence - `downcase` -- convert an input string to lowercase - `upcase` -- convert an input string to uppercase - `first` -- get the first element of the passed in array - `last` -- get the last element of the passed in array - `join` -- join elements of the array with certain character between them - `sort` -- sort elements of the array: `{{ site.posts | sort: 'author' }}` - `size` -- return the size of an array or string - `strip_newlines` -- strip all newlines (`\n`) from string - `replace` -- replace each occurrence: `{{ 'foofoo' | replace:'foo','bar' }}` @@ -103,7 +111,7 @@ Disables tag processing. #### If / Else Simple expression with if/unless, elsif [sic!] and else. ``` {% if user %} @@ -201,4 +209,24 @@ Combining multiple strings into one variable: ``` {% capture full-name %}{{ name }} {{ surname }}{% endcapture %} ``` ### Permalinks Permalinks are constructed with a template: ``` /:categories/:year/:month/:day/:title.html ``` These variables are available: - `year` -- year from the filename - `short_year` -- same as above but without the century - `month` -- month from the filename - `i_month` -- same as above but without leading zeros - `day` -- day from the filename - `i_day` -- same as above but without leading zeros - `title` -- title from the filename - `categories`-- specified categories for the post -
magicznyleszek revised this gist
Mar 27, 2014 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -182,6 +182,13 @@ Limit and offset starting collection: {% endfor %} ``` You can also reverse the loop: ``` {% for item in array reversed %} ... ``` #### Storing variables Storing data in variables: -
magicznyleszek revised this gist
Mar 27, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ # Jekyll & Liquid Cheatsheet A list of the most common functionalities in Jekyll (Liquid). ## Running -
magicznyleszek revised this gist
Mar 27, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Running a local server for testing purposes: ``` jekyll serve --watch ``` @@ -38,15 +38,15 @@ chcp 65001 Simple example of Output: ``` liquid Hello {{name}} Hello {{user.name}} Hello {{ 'leszek' }} ``` Filtering output: ``` liquid Word hello has {{ 'hello' | size }} letters! Todat is {{ 'now' | date: "%Y %h" }} ``` -
magicznyleszek revised this gist
Mar 27, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Running a local server for testing purposes: ``` liquid jekyll serve --watch ``` -
magicznyleszek revised this gist
Mar 27, 2014 . 1 changed file with 87 additions and 50 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,20 +3,32 @@ ## Running Running a local server for testing purposes: ``` jekyll serve --watch ``` Creating a final outcome (or for testing on a server): ``` jekyll build --watch ``` ### Troubleshooting On Windows you can get this error when building/serving: ``` Liquid Exception: incompatible character encodings: UTF-8 and IBM437 in index.html ``` You need to set the code-page first: ``` chcp 65001 ``` ## Liquid @@ -26,14 +38,18 @@ You need to set the code-page first: Simple example of Output: ``` Hello {{name}} Hello {{user.name}} Hello {{ 'leszek' }} ``` Filtering output: ``` Word hello has {{ 'hello' | size }} letters! Todat is {{ 'now' | date: "%Y %h" }} ``` Most common filters: @@ -68,7 +84,9 @@ Tags are used for the logic in your template. For swallowing content. ``` We made 1 million dollars {% comment %} in losses {% endcomment %} this year ``` #### Raw @@ -85,74 +103,93 @@ Disables tag processing. Simple expression with if/unless, elseif and else. ``` {% if user %} Hello {{ user.name }} {% elsif user.name == "The Dude" %} Are you employed, sir? {% else %} Who are you? {% endif %} ``` ``` {% unless user.name == "leszek" and user.race == "human" %} Hello non-human non-leszek {% endunless %} ``` ``` # array: [1,2,3] {% if array contains 2 %} array includes 2 {% endif %} ``` #### Case For more conditions. ``` {% case condition %} {% when 1 %} hit 1 {% when 2 or 3 %} hit 2 or 3 {% else %} don't hit {% endcase %} ``` #### For loop Simple loop over a collection: ``` {% for item in array %} {{ item }} {% endfor %} ``` Simple loop with iteration: ``` {% for i in (1..10) %} {{ i }} {% endfor %} ``` There are helper variables for special occasions: - `forloop.length` -- length of the entire for loop - `forloop.index` -- index of the current iteration - `forloop.index0` -- index of the current iteration (zero based) - `forloop.rindex` -- how many items are still left? - `forloop.rindex0` -- how many items are still left? (zero based) - `forloop.first` -- is this the first iteration? - `forloop.last` -- is this the last iteration? Limit and offset starting collection: ``` # array: [1,2,3,4,5,6] {% for item in array limit:2 offset:2 %} {{ item }} {% endfor %} ``` #### Storing variables Storing data in variables: ``` {% assign name = 'leszek' %} ``` Combining multiple strings into one variable: ``` {% capture full-name %}{{ name }} {{ surname }}{% endcapture %} ``` -
magicznyleszek revised this gist
Mar 27, 2014 . 1 changed file with 34 additions and 33 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,18 +5,18 @@ `jekyll serve --watch` `jekyll build --watch` ### Troubleshooting On Windows you can get this error when building/serving: `Liquid Exception: incompatible character encodings: UTF-8 and IBM437 in index.html` You need to set the code-page first: `chcp 65001` ## Liquid @@ -26,37 +26,37 @@ You need to set the code-page first: Simple example of Output: `Hello {{name}}` `Hello {{user.name}}` `Hello {{ 'leszek' }}` Filtering output: `Word hello has {{ 'hello' | size }} letters!` `Todat is {{ 'now' | date: "%Y %h" }}` Most common filters: - `date` -- reformat a date (syntax reference) - `capitalize` -- capitalize words in the input sentence - `downcase` -- convert an input string to lowercase - `upcase` -- convert an input string to uppercase - `first` -- get the first element of the passed in array - `last` -- get the last element of the passed in array - `join` -- join elements of the array with certain character between them - `sort` -- sort elements of the array - `size` -- return the size of an array or string - `strip_newlines` -- strip all newlines (`\n`) from string - `replace` -- replace each occurrence: `{{ 'foofoo' | replace:'foo','bar' }}` - `replace_first` -- replace the first occurrence: `{{ 'barbar' | replace_first:'bar','foo' }}` - `remove` -- remove each occurrence: `{{ 'foobarfoobar' | remove:'foo' }}` - `remove_first` -- remove the first occurrence: `{{ 'barbar' | remove_first:'bar' }}` - `truncate` -- truncate a string down to x characters - `truncatewords` -- truncate a string down to x words - `prepend` -- prepend a string: `{{ 'bar' | prepend:'foo' }}` - `append` -- append a string: `{{ 'foo' | append:'bar' }}` - `minus`, `plus`, `times`, `divided_by`, `modulo` -- working with numbers: `{{ 4 | plus:2 }}` - `split` -- split a string on a matching pattern: `{{ "a~b" | split:~ }}` ### Tags @@ -68,17 +68,18 @@ Tags are used for the logic in your template. For swallowing content. `We made 1 million dollars {% comment %} in losses {% endcomment %} this year` #### Raw Disables tag processing. ``` {% raw %} In Handlebars, {{ this }} will be HTML-escaped, but {{{ that }}} will not. {% endraw %} ``` #### If / Else -
magicznyleszek revised this gist
Mar 27, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ ## Running `jekyll serve --watch` > jekyll build --watch -
magicznyleszek revised this gist
Mar 27, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ ## Running ``` jekyll serve --watch > jekyll build --watch -
magicznyleszek created this gist
Mar 27, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,157 @@ # Jekyll & Liquid Cheatsheet ## Running > jekyll serve --watch > jekyll build --watch ### Troubleshooting On Windows you can get this error when building/serving: > Liquid Exception: incompatible character encodings: UTF-8 and IBM437 in index.html You need to set the code-page first: > chcp 65001 ## Liquid ### Output Simple example of Output: > Hello {{name}} > Hello {{user.name}} > Hello {{ 'leszek' }} Filtering output: > Word hello has {{ 'hello' | size }} letters! > Todat is {{ 'now' | date: "%Y %h" }} Most common filters: - date -- reformat a date (syntax reference) - capitalize -- capitalize words in the input sentence - downcase -- convert an input string to lowercase - upcase -- convert an input string to uppercase - first -- get the first element of the passed in array - last -- get the last element of the passed in array - join -- join elements of the array with certain character between them - sort -- sort elements of the array - size -- return the size of an array or string - strip_newlines -- strip all newlines (\n) from string - replace -- replace each occurrence: {{ 'foofoo' | replace:'foo','bar' }} - replace_first -- replace the first occurrence: {{ 'barbar' | replace_first:'bar','foo' }} - remove -- remove each occurrence: {{ 'foobarfoobar' | remove:'foo' }} - remove_first -- remove the first occurrence:{{ 'barbar' | remove_first:'bar' }} - truncate -- truncate a string down to x characters - truncatewords -- truncate a string down to x words - prepend -- prepend a string: {{ 'bar' | prepend:'foo' }} - append -- append a string: {{ 'foo' | append:'bar' }} - minus, plus, times, divided_by, modulo -- working with numbers: {{ 4 | plus:2 }} - split -- split a string on a matching pattern: {{ "a~b" | split:~ }} ### Tags Tags are used for the logic in your template. #### Comments For swallowing content. > We made 1 million dollars {% comment %} in losses {% endcomment %} this year #### Raw Disables tag processing. > {% raw %} > In Handlebars, {{ this }} will be HTML-escaped, but {{{ that }}} will not. > {% endraw %} #### If / Else Simple expression with if/unless, elseif and else. > {% if user %} > Hello {{ user.name }} > {% else %} > Who are you? > {% endif %} > {% unless user.name == "leszek" and user.race == "human" %} > Hello non-human non-leszek > {% endunless %} > # array = 1,2,3 > {% if array contains 2 %} > array includes 2 > {% endif %} #### Case For more conditions. > {% case condition %} > {% when 1 %} > hit 1 > {% when 2 or 3 %} > hit 2 or 3 > {% else %} > don't hit > {% endcase %} #### For loop Simple loop over a collection: > {% for item in array %} > {{ item }} > {% endfor %} Simple loop with iteration: > {% for i in (1..10) %} > {{ i }} > {% endfor %} There are helper variables for special occasions: - forloop.length -- length of the entire for loop - forloop.index -- index of the current iteration - forloop.index0 -- index of the current iteration (zero based) - forloop.rindex -- how many items are still left? - forloop.rindex0 -- how many items are still left? (zero based) - forloop.first -- is this the first iteration? - forloop.last -- is this the last iteration? Limit and offset starting collection: > # array = [1,2,3,4,5,6] > {% for item in array limit:2 offset:2 %} > {{ item }} > {% endfor %} #### Storing variables Storing data in variables: > {% assign name = 'leszek' %} Combining multiple strings into one variable: > {% capture full-name %}{{ name }} {{ surname }}{% endcapture %}