Skip to content

Commit

Permalink
Dates are not unique. Warnings are alarming. Arrays are enough.
Browse files Browse the repository at this point in the history
  • Loading branch information
da2x committed May 8, 2015
1 parent 5205306 commit 4ad118f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
15 changes: 8 additions & 7 deletions v7/recent_posts_json/README.md
Expand Up @@ -3,19 +3,20 @@ as /index.html. Intended to be used in JavaScripts. For example to
promote the most recent posts at the bottom of older posts.

By default, the JSON file will include:
{
<JS Date object>: {
[
{
"date": <JS Date object>,
"title": <post-title>,
"iri": <relative-link-to-post>
"loc": <relative-link-to-post>
},
}
]

Optionally, it can be expanded to include thumbnails or descriptions:
{ <JS Date object>: {
"title": <post-title>, "iri": <post-relative-link>,
[ {
"date" <JS Date object>, "title": <post-title>, "loc": <post-relative-link>,
"desc": <post-meta-description>,
"img": <post-meta-thumbnail>
}, }
], }

Posts are sorted by their post.meta.date as JavaScript dates.

Expand Down
13 changes: 7 additions & 6 deletions v7/recent_posts_json/recent_posts_json.py
Expand Up @@ -89,19 +89,20 @@ def gen_tasks(self):
yield utils.apply_filters(task, kw["filters"])

def make_json(self, posts, descriptions, previewimage, output_path):
recent_posts = {}
recent_posts = []
for post in posts:
date = int(time.mktime(post.date.timetuple()) * 1000) # JavaScript Date
link = post.permalink(absolute=False)
title = post.title()
recent_posts[date] = {"title": title,
"iri": link}
entry = {"date": date,
"title": title,
"loc": link}
if descriptions:
recent_posts[date]["desc"] = post.description()
entry.update({["desc"]: post.description() })
if previewimage:
recent_posts[date]["img"] = post.previewimage()
entry.update({["img"]: post.previewimage() })
recent_posts.append(entry)
data = json.dumps(recent_posts, indent=2)
utils.LOGGER.warn(data)
with io.open(output_path, "w+", encoding="utf8") as outf:
outf.write(data)

Expand Down

0 comments on commit 4ad118f

Please sign in to comment.