Skip to content

Commit

Permalink
Merge pull request #94 from milo-wata/master
Browse files Browse the repository at this point in the history
A bite-sized today's update API; issue #32
  • Loading branch information
mkiser authored Jun 1, 2017
2 parents e348e71 + a208580 commit 4a74c4d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
35 changes: 35 additions & 0 deletions _plugins/itemizer.rb
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)
5 changes: 5 additions & 0 deletions api/today.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: null
---

{{ site.posts[0] | itemize }}

0 comments on commit 4a74c4d

Please sign in to comment.