Skip to content

Instantly share code, notes, and snippets.

@egardner
Created March 5, 2015 16:00
Show Gist options
  • Save egardner/5a7eaa314c0104235a39 to your computer and use it in GitHub Desktop.
Save egardner/5a7eaa314c0104235a39 to your computer and use it in GitHub Desktop.
Jekyll JSON template
---
layout: null
---
[
{% for post in site.posts %}
{
"title" : "{{ post.title }}",
"url" : "{{ post.url }}",
"date" : "{{ post.date | date: "%B %d, %Y" }}",
"content" : "{{ post.content | strip_html | strip_newlines | escape_once }}"
} {% if forloop.last %}{% else %},{% endif %}
{% endfor %}
]
@egardner
Copy link
Author

egardner commented Mar 5, 2015

This generates valid JSON from Jekyll posts when Jekyll runs. strip_newlines is essential in the content field, but strip_html is not. To return safe HTML instead of a raw string, do this:

"content" : "{{ post.content | strip_newlines | escape }}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment