-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from milo-wata/master
A bite-sized today's update API; issue #32
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Jekyll plugin to itemize each post for JSON output | ||
# Parses the current pattern of every item beginning with | ||
# <p><Number>/ ... | ||
|
||
require 'jekyll' | ||
require 'json' | ||
|
||
|
||
module Jekyll | ||
module Itemizer | ||
|
||
def itemize(post) | ||
|
||
# splits the contents into items for each story. Slice off | ||
# the first one, since it's an empty string | ||
item_list = post.content.split(/<p>\d\//).slice(1..-1) | ||
|
||
# make the list into an indexed array | ||
items = Hash[(1...item_list.size).zip item_list] | ||
|
||
# setup the entire output with any other desired keys | ||
output = ({ | ||
:title => post['title'], | ||
:description => post['description'], | ||
:date => post['date'], | ||
:items => items | ||
}) | ||
|
||
# ship it! | ||
output.to_json | ||
end | ||
|
||
end | ||
end | ||
Liquid::Template.register_filter(Jekyll::Itemizer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
layout: null | ||
--- | ||
|
||
{{ site.posts[0] | itemize }} |