Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Jekyll Cheat Sheet

Jekyll Cheat Sheet

Preview posts

Add a _drafts folder as a sibling of _posts. You add posts inside it the same way. To preview drafts, start jekyll with jekyll s --wD. The D is for Drafts.

Categorize blog posts

Jekyll only allows one category per post. You can apply the category by front matter or subfolder, but subfolder never gets forgotten so it's recommended. If you need more than one "something" per post, create a separate front matter field:


Get posts by category

You can list by category, limit to the latest 2, or offset into a list:

<h2>Recent Blog Posts</h2>
  {% for post in limit:2 %}
    {% include li-post-summary.html %}
  {% endfor %}

<h2>More Posts</h2>
  {% for post in offset:2 %}
    {% include li-post-oneliner.html %}
  {% endfor %}

Have a main image per blog post

Best done with metadata. Put something like this in your post's front matter:

title: Javascript Dev Revisits the `C` programming language after 14 years
excerpt: I hadn't written a line of C since learning it in an AP community college class. Meow I'm back.
bannerCaption: "Photo Credit:"

And access it like this:

<div class="banner"
     style="{% if page.banner %} background-image:url('{{page.banner}}'); {% endif %}"

Attach an author to a post

Put an author id in your front matter:

author: foo42

Then describe authors in something like _config.yml as in this post.

You use this in html like this:

{% assign author = site.authors[] %}
	<img src="{{ author.gravatar }}?s=40">
	<span class="author">{{ author.display_name }}</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.