Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create JSON feed #173

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Create JSON feed #173

wants to merge 13 commits into from

Conversation

hugmanrique
Copy link

The original spec for JSON Feeds has been published this morning (Spec), and as my first Ruby exercise, I tried to create JSON feeds for Jekyll.

By default, the JSON feed will be written to feed.json, but a config option is also available. The JSON code should be valid, and I perform sanitization of strings by using the json Liquid operator.

Please note that this is the first time I've modified some Ruby code, and some things could be totally wrong (I'm not too sure about this return)

@pathawks
Copy link
Member

pathawks commented May 18, 2017

@hugmanrique This is awesome! Great work here.

Per the discussion in #172, I’m not sure that we are ready to support JSON Feed just yet. That said, I wonder if it would be worthwhile for us to have a branch that supports JSON. Kind of a just in case operation. This way, anybody who wanted to work with JSON Feed and Jekyll could have a common place to do so.

@benbalter Thoughts?

@parkr
Copy link
Member

parkr commented May 18, 2017

Huge 👍 on this.

{% endif %}
"items": [
{% assign posts = site.posts | where_exp: "post", "post.draft != true" %}
{% for post in posts limmit: 10 %}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe "limmit" needs to be with one "m" to work correctly.

# Path to feed.xml template file
def feed_source_path
File.expand_path "./feed.xml", File.dirname(__FILE__)
end

# Path to feed.json template file
def feed_json_source_path
File.expand_path "./feed.json", File.dirname(__FILE__)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File.expand_path("feed.xml", __dir__)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feed_source_path function used that same format and I just changed the file path. Please note that I don't know any Ruby and I might be wrong.

{% if site.description %}
"description": {{ site.description | json }},
{% endif %}
"home_page_url": "{{ '/' | absolute_url }}",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why just not {{ absolute_url }}?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolute_url is a filter not a value. It needs something as input.

}
],
{% endif %}
"tags": [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"tags": {{ post.tags | jsonify }},

"title": {{ post.title | smartify | strip_html | normalize_whitespace | json }},
{% if post.excerpt and post.excerpt != empty %}
{% assign post_summary = post.excerpt | strip_html | normalize_whitespace | json %}
"content_html": {{ post_summary }},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think content_html should have a full content of post

"version": "https://jsonfeed.org/version/1",
{% assign site_title = site.title | site.name %}
{% if site_title %}
"title": {{ site_title | smartify | json }},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can't find json filter there https://jekyllrb.com/docs/templates/ may be jsonify

@pathawks
Copy link
Member

This is a cool proof of concept but honestly, if we were to produce a JSON feed, I think doing it in pure Ruby would be a better approach then using Liquid templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants