Skip to content

Instantly share code, notes, and snippets.

@SimplGy
Last active March 17, 2016 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimplGy/385cc726d19242c43930 to your computer and use it in GitHub Desktop.
Save SimplGy/385cc726d19242c43930 to your computer and use it in GitHub Desktop.
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:

---
tag:
  -ruby
  -bug
---

Get posts by category

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

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

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

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.
banner: http://simple.gy/img/apollo-13-eva-test.jpg
bannerCaption: "Photo Credit: http://unsplash.com"
---

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[page.author] %}
<aside>
	<img src="http://www.gravatar.com/avatar/{{ author.gravatar }}?s=40">
	<span class="author">{{ author.display_name }}</span>
</aside>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment