#!/usr/bin/env python3
# Forked from:
# https://github.com/dmbaturin/soupault.neocities.org/blob/314be103fb917edb06ca70f18b6f9370b120f5f5/scripts/index.py
import sys
import json
import pystache
template = """
<div class="entry">
<h3><a href="{{url}}">{{{title}}}</a></h3>
<p>Posted: {{date}}</p>
<p>{{{excerpt}}}</p>
<a href="{{url}}">Read more...</a>
</div>
"""
renderer = pystache.Renderer()
read = sys.stdin.readline()
index_entries = json.loads(read)
for entry in index_entries:
# Don't try to list files that aren't blog posts.
if entry["title"] is not None and entry["date"] is not None:
print(renderer.render(template, entry))