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
from

Conversation

Projects
None yet
6 participants
@hugmanrique
Copy link

hugmanrique commented May 17, 2017

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)

hugmanrique added some commits May 17, 2017

@pathawks

This comment has been minimized.

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

This comment has been minimized.

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 %}

This comment has been minimized.

@justinrummel

justinrummel May 24, 2017

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

hugmanrique added some commits May 24, 2017

@vallieres

This comment has been minimized.

Copy link

vallieres commented on eaf474c May 26, 2017

Thanks for the mention :) I was about to suggest that you add more attributes but then I realized that what you're going for is the bare minimum so things like authors, link posts and images are not there by default.

This comment has been minimized.

Copy link
Owner

hugmanrique replied May 26, 2017

When I did the first commit I didn't have too much time so I just limited the amount of testing I could do (see if all the vars are sanitized) and I just decided to leave some things for another day.

Would you suggest adding anything else?

This comment has been minimized.

Copy link

vallieres replied May 26, 2017

I think we should cover the JSON Feed specs with a few more fields wrapped around if statements so that it does not generate empty attributes for nothing.

I'll send you a PR later :)

# 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__)

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Jun 15, 2017

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

This comment has been minimized.

@hugmanrique

hugmanrique Jun 16, 2017

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 }}",

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Jun 15, 2017

why just not {{ absolute_url }}?

This comment has been minimized.

@pathawks

pathawks Jun 15, 2017

Member

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

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

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Jun 17, 2017

"tags": {{ post.tags | jsonify }},
Simplify tags loop
@bogdanvlviv suggested this
"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 }},

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Jun 17, 2017

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 }},

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Jun 17, 2017

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

@pathawks

This comment has been minimized.

Copy link
Member

pathawks commented Jun 17, 2017

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