Skip to content

Commit 4ad118f

Browse files
committedMay 8, 2015
Dates are not unique. Warnings are alarming. Arrays are enough.
1 parent 5205306 commit 4ad118f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed
 

Diff for: ‎v7/recent_posts_json/README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ as /index.html. Intended to be used in JavaScripts. For example to
33
promote the most recent posts at the bottom of older posts.
44

55
By default, the JSON file will include:
6-
{
7-
<JS Date object>: {
6+
[
7+
{
8+
"date": <JS Date object>,
89
"title": <post-title>,
9-
"iri": <relative-link-to-post>
10+
"loc": <relative-link-to-post>
1011
},
11-
}
12+
]
1213

1314
Optionally, it can be expanded to include thumbnails or descriptions:
14-
{ <JS Date object>: {
15-
"title": <post-title>, "iri": <post-relative-link>,
15+
[ {
16+
"date" <JS Date object>, "title": <post-title>, "loc": <post-relative-link>,
1617
"desc": <post-meta-description>,
1718
"img": <post-meta-thumbnail>
18-
}, }
19+
], }
1920

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

Diff for: ‎v7/recent_posts_json/recent_posts_json.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,20 @@ def gen_tasks(self):
8989
yield utils.apply_filters(task, kw["filters"])
9090

9191
def make_json(self, posts, descriptions, previewimage, output_path):
92-
recent_posts = {}
92+
recent_posts = []
9393
for post in posts:
9494
date = int(time.mktime(post.date.timetuple()) * 1000) # JavaScript Date
9595
link = post.permalink(absolute=False)
9696
title = post.title()
97-
recent_posts[date] = {"title": title,
98-
"iri": link}
97+
entry = {"date": date,
98+
"title": title,
99+
"loc": link}
99100
if descriptions:
100-
recent_posts[date]["desc"] = post.description()
101+
entry.update({["desc"]: post.description() })
101102
if previewimage:
102-
recent_posts[date]["img"] = post.previewimage()
103+
entry.update({["img"]: post.previewimage() })
104+
recent_posts.append(entry)
103105
data = json.dumps(recent_posts, indent=2)
104-
utils.LOGGER.warn(data)
105106
with io.open(output_path, "w+", encoding="utf8") as outf:
106107
outf.write(data)
107108

0 commit comments

Comments
 (0)