├── LICENSE.md ├── README.md ├── filter-liquid-in-front-matter.md ├── filter-table-of-contents.md ├── include-nav-with-data.md ├── include-reading-time.md └── tag-with-own-includes-dir-lookup.md /LICENSE.md: -------------------------------------------------------------------------------- 1 | CC0 1.0 Universal 2 | 3 | Statement of Purpose 4 | 5 | The laws of most jurisdictions throughout the world automatically confer 6 | exclusive Copyright and Related Rights (defined below) upon the creator and 7 | subsequent owner(s) (each and all, an "owner") of an original work of 8 | authorship and/or a database (each, a "Work"). 9 | 10 | Certain owners wish to permanently relinquish those rights to a Work for the 11 | purpose of contributing to a commons of creative, cultural and scientific 12 | works ("Commons") that the public can reliably and without fear of later 13 | claims of infringement build upon, modify, incorporate in other works, reuse 14 | and redistribute as freely as possible in any form whatsoever and for any 15 | purposes, including without limitation commercial purposes. These owners may 16 | contribute to the Commons to promote the ideal of a free culture and the 17 | further production of creative, cultural and scientific works, or to gain 18 | reputation or greater distribution for their Work in part through the use and 19 | efforts of others. 20 | 21 | For these and/or other purposes and motivations, and without any expectation 22 | of additional consideration or compensation, the person associating CC0 with a 23 | Work (the "Affirmer"), to the extent that he or she is an owner of Copyright 24 | and Related Rights in the Work, voluntarily elects to apply CC0 to the Work 25 | and publicly distribute the Work under its terms, with knowledge of his or her 26 | Copyright and Related Rights in the Work and the meaning and intended legal 27 | effect of CC0 on those rights. 28 | 29 | 1. Copyright and Related Rights. A Work made available under CC0 may be 30 | protected by copyright and related or neighboring rights ("Copyright and 31 | Related Rights"). Copyright and Related Rights include, but are not limited 32 | to, the following: 33 | 34 | i. the right to reproduce, adapt, distribute, perform, display, communicate, 35 | and translate a Work; 36 | 37 | ii. moral rights retained by the original author(s) and/or performer(s); 38 | 39 | iii. publicity and privacy rights pertaining to a person's image or likeness 40 | depicted in a Work; 41 | 42 | iv. rights protecting against unfair competition in regards to a Work, 43 | subject to the limitations in paragraph 4(a), below; 44 | 45 | v. rights protecting the extraction, dissemination, use and reuse of data in 46 | a Work; 47 | 48 | vi. database rights (such as those arising under Directive 96/9/EC of the 49 | European Parliament and of the Council of 11 March 1996 on the legal 50 | protection of databases, and under any national implementation thereof, 51 | including any amended or successor version of such directive); and 52 | 53 | vii. other similar, equivalent or corresponding rights throughout the world 54 | based on applicable law or treaty, and any national implementations thereof. 55 | 56 | 2. Waiver. To the greatest extent permitted by, but not in contravention of, 57 | applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and 58 | unconditionally waives, abandons, and surrenders all of Affirmer's Copyright 59 | and Related Rights and associated claims and causes of action, whether now 60 | known or unknown (including existing as well as future claims and causes of 61 | action), in the Work (i) in all territories worldwide, (ii) for the maximum 62 | duration provided by applicable law or treaty (including future time 63 | extensions), (iii) in any current or future medium and for any number of 64 | copies, and (iv) for any purpose whatsoever, including without limitation 65 | commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes 66 | the Waiver for the benefit of each member of the public at large and to the 67 | detriment of Affirmer's heirs and successors, fully intending that such Waiver 68 | shall not be subject to revocation, rescission, cancellation, termination, or 69 | any other legal or equitable action to disrupt the quiet enjoyment of the Work 70 | by the public as contemplated by Affirmer's express Statement of Purpose. 71 | 72 | 3. Public License Fallback. Should any part of the Waiver for any reason be 73 | judged legally invalid or ineffective under applicable law, then the Waiver 74 | shall be preserved to the maximum extent permitted taking into account 75 | Affirmer's express Statement of Purpose. In addition, to the extent the Waiver 76 | is so judged Affirmer hereby grants to each affected person a royalty-free, 77 | non transferable, non sublicensable, non exclusive, irrevocable and 78 | unconditional license to exercise Affirmer's Copyright and Related Rights in 79 | the Work (i) in all territories worldwide, (ii) for the maximum duration 80 | provided by applicable law or treaty (including future time extensions), (iii) 81 | in any current or future medium and for any number of copies, and (iv) for any 82 | purpose whatsoever, including without limitation commercial, advertising or 83 | promotional purposes (the "License"). The License shall be deemed effective as 84 | of the date CC0 was applied by Affirmer to the Work. Should any part of the 85 | License for any reason be judged legally invalid or ineffective under 86 | applicable law, such partial invalidity or ineffectiveness shall not 87 | invalidate the remainder of the License, and in such case Affirmer hereby 88 | affirms that he or she will not (i) exercise any of his or her remaining 89 | Copyright and Related Rights in the Work or (ii) assert any associated claims 90 | and causes of action with respect to the Work, in either case contrary to 91 | Affirmer's express Statement of Purpose. 92 | 93 | 4. Limitations and Disclaimers. 94 | 95 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 96 | surrendered, licensed or otherwise affected by this document. 97 | 98 | b. Affirmer offers the Work as-is and makes no representations or warranties 99 | of any kind concerning the Work, express, implied, statutory or otherwise, 100 | including without limitation warranties of title, merchantability, fitness 101 | for a particular purpose, non infringement, or the absence of latent or 102 | other defects, accuracy, or the present or absence of errors, whether or not 103 | discoverable, all to the greatest extent permissible under applicable law. 104 | 105 | c. Affirmer disclaims responsibility for clearing rights of other persons 106 | that may apply to the Work or any use thereof, including without limitation 107 | any person's Copyright and Related Rights in the Work. Further, Affirmer 108 | disclaims responsibility for obtaining any necessary consents, permissions 109 | or other rights required for any use of the Work. 110 | 111 | d. Affirmer understands and acknowledges that Creative Commons is not a 112 | party to this document and has no duty or obligation with respect to this 113 | CC0 or use of the Work. 114 | 115 | For more information, please see 116 | 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jekyll Snippets (Tips 'n' Tricks) 2 | 3 | Welcome. The Jekyll Snippets chapter 4 | collects tips 'n' tricks about all things Jekyll and friends. 5 | 6 | Do you have any Jekyll tips or tricks that you'd like to write about? 7 | We love guest posts. 8 | [Send in a pull request](https://github.com/planetjekyll/snippets/pulls) 9 | or 10 | [open an issue ticket](https://github.com/planetjekyll/snippets/issues) 11 | to get the conversation started and your write-up posted on Planet Jekyll. 12 | 13 | 14 | 15 | ## Filters 16 | 17 | - [**liquify Filter - Use Liquid Placeholders in Front Matter Values**](filter-liquid-in-front-matter.md) 18 | - [**toc Filter - (Auto-)generate a table of contents**](filter-table-of-contents.md) 19 | 20 | ## Tags 21 | 22 | - [**Use Your Own Includes Directory Lookup in Your Liquid Tags**](tag-with-own-includes-dir-lookup.md) 23 | 24 | 25 | ## Includes 26 | 27 | - [**Build Your Navigation Menu Using \_data/nav.yml**](include-nav-with-data.md) 28 | - [**Reading Time (e.g. 3 mins) with reading_time.html Template**](include-reading-time.md) 29 | 30 | 31 | 32 | ## Meta 33 | 34 | **License** 35 | 36 | ![](https://publicdomainworks.github.io/buttons/zero88x31.png) 37 | 38 | The snippets and scripts are dedicated to the public domain. Use it as you please with no restrictions whatsoever. 39 | -------------------------------------------------------------------------------- /filter-liquid-in-front-matter.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: snippet 3 | title: "liquify Filter - Use Liquid Placeholders in Front Matter Values" 4 | --- 5 | 6 | 7 | ## {{ page.title }} 8 | 9 | Add a new filter that lets you use liquid in your front matter block. Example: 10 | 11 | ``` 12 | --- 13 | title: How to install {% raw %}{{ site.data.placeholder.product-name }}{% endraw %} 14 | --- 15 | ``` 16 | 17 | And the filter: 18 | 19 | ``` ruby 20 | module LiquidFilter 21 | def liquify(input) 22 | Liquid::Template.parse(input).render(@context) 23 | end 24 | end 25 | Liquid::Template.register_filter(LiquidFilter) 26 | ``` 27 | 28 | Use it in your templates / layouts like: 29 | 30 | ``` 31 | {% raw %} 32 | {{ page.title | liquify }} 33 | {% endraw %} 34 | ``` 35 | 36 | 37 | 38 | ## Sources 39 | 40 | - [Jekyll filter: Use Liquid in front-matter](https://fettblog.eu/snippets/jekyll/liquid-in-frontmatter/) by Stefan Baumgartner 41 | -------------------------------------------------------------------------------- /filter-table-of-contents.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: snippet 3 | title: "toc Filter - (Auto-)generate a table of contents" 4 | --- 5 | 6 | ## {{ page.title }} 7 | 8 | 9 | Add a filter that (auto-)generates a table of contents 10 | using all heading 2 (h2) tags on your page: 11 | 12 | 13 | ``` ruby 14 | module TocFilter 15 | def toc(input) 16 | output = "' 27 | output 28 | end 29 | end 30 | Liquid::Template.register_filter(TocFilter) 31 | ``` 32 | 33 | Use it in your templates / layouts like: 34 | 35 | 36 | ``` 37 | {% raw %} 38 | {{ content | toc }} 39 | {% endraw %} 40 | ``` 41 | 42 | 43 | ## Sources 44 | 45 | - [Jekyll table of contents per page](https://fettblog.eu/snippets/jekyll/table-of-contents/) by Stefan Baumgartner 46 | -------------------------------------------------------------------------------- /include-nav-with-data.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: snippet 3 | title: "Build Your Navigation Menu Using _data/nav.yml" 4 | --- 5 | 6 | ## {{ page.title }} 7 | 8 | In your `_data` folder add a new navigation file. Example: 9 | 10 | `_data/nav.yml`: 11 | 12 | ``` yaml 13 | - title: "Home" 14 | href: "/" 15 | 16 | - title: "News" 17 | href: "/news/" 18 | 19 | - title: "Snippets" 20 | subcategories: 21 | - subtitle: "Example1" 22 | subhref: "#" 23 | - subtitle: "Example2" 24 | subhref: "#" 25 | ``` 26 | 27 | `_includes/nav.html`: 28 | 29 | ``` 30 | {% raw %} 31 | 55 | {% endraw %} 56 | ``` 57 | 58 | Note: U+25BC (`▼`) is the unicode for a black down-pointing triange (e.g. `▼`) 59 | 60 | 61 | 62 | ## Sources 63 | 64 | - [Using _data to Build Jekyll Navigation](http://chrisanthropic.github.io/slim-pickins-jekyll-theme/blog/2014/using-_data-to-build-jekyll-navigation/) 65 | -------------------------------------------------------------------------------- /include-reading-time.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: snippet 3 | title: "Reading Time (e.g. 3 mins) with _includes/reading_time.html Template" 4 | --- 5 | 6 | ## {{ page.title }} 7 | 8 | To add the reading time (e.g. 3 mins) to your posts include the `reading_time.html` 9 | template in your post layout. Example: 10 | 11 | ``` 12 | {% raw %} 13 | {% include reading_time.html %} 14 | {% endraw %} 15 | ``` 16 | 17 | 18 | `_includes/reading_time.html`: 19 | 20 | ``` 21 | {% raw %} 22 | 23 | {% assign words = content | number_of_words %} 24 | {% if words < 360 %} 25 | 1 min 26 | {% else %} 27 | {{ words | divided_by:180 }} mins 28 | {% endif %} 29 | 30 | {% endraw %} 31 | ``` 32 | 33 | Note: The template assumes a reading speed of 180 words per minute (WPM). 34 | 35 | 36 | 37 | ## Sources 38 | 39 | - [Jekyll: Reading time without plugins](http://carlosbecker.com/posts/jekyll-reading-time-without-plugins/) by Carlos Becker, Jan 2015 40 | - [Wikipedia: Words per minute](http://en.wikipedia.org/wiki/Words_per_minute) 41 | -------------------------------------------------------------------------------- /tag-with-own-includes-dir-lookup.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: snippet 3 | title: "Use Your Own Includes Directory Lookup in Your Liquid Tags" 4 | --- 5 | 6 | 7 | ## {{ page.title }} 8 | 9 | Add your own `_includes` directory lookup to your liquid tags 10 | by adding `resolved_includes_dir`: 11 | 12 | ```ruby 13 | module Jekyll 14 | module Tags 15 | class SnippetTag < IncludeTag 16 | def resolved_includes_dir(context) 17 | context.registers[:site].in_source_dir('_snippets') 18 | end 19 | end 20 | end 21 | end 22 | 23 | Liquid::Template.register_tag('snippet', Jekyll::Tags::SnippetTag) 24 | ``` 25 | 26 | 27 | ## Sources 28 | 29 | - [Custom Jekyll Includes Directory](https://fettblog.eu/snippets/jekyll/custom-jekyll-includes-directory/) by Stefan Baumgartner 30 | --------------------------------------------------------------------------------