Skip to content
Permalink
Browse files

Dates are not unique. Warnings are alarming. Arrays are enough.

  • Loading branch information
da2x committed May 8, 2015
1 parent 5205306 commit 4ad118fa819eda677c42e5d701b6af796f34f417
Showing with 15 additions and 13 deletions.
  1. +8 −7 v7/recent_posts_json/README.md
  2. +7 −6 v7/recent_posts_json/recent_posts_json.py
@@ -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.

@@ -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)

0 comments on commit 4ad118f

Please sign in to comment.