-
Notifications
You must be signed in to change notification settings - Fork 206
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
base: master
Are you sure you want to change the base?
Create JSON feed #173
Conversation
@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? |
Huge 👍 on this. |
lib/jekyll-feed/feed.json
Outdated
{% endif %} | ||
"items": [ | ||
{% assign posts = site.posts | where_exp: "post", "post.draft != true" %} | ||
{% for post in posts limmit: 10 %} |
There was a problem hiding this comment.
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__) |
There was a problem hiding this comment.
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__)
There was a problem hiding this comment.
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 }}", |
There was a problem hiding this comment.
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 }}
?
There was a problem hiding this comment.
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.
lib/jekyll-feed/feed.json
Outdated
} | ||
], | ||
{% endif %} | ||
"tags": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"tags": {{ post.tags | jsonify }},
@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 }}, |
There was a problem hiding this comment.
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 }}, |
There was a problem hiding this comment.
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
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. |
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)