~hristoast/hristoast

766050abd12f117f2f1a47b8587a81f109778261 — Hristos N. Triantafillou 1 year, 1 month ago acc24f3
This is needed
1 files changed, 36 insertions(+), 0 deletions(-)

A scripts/index.py
A scripts/index.py => scripts/index.py +36 -0
@@ 0,0 1,36 @@
#!/usr/bin/env python3

# Forked from:
# https://github.com/dmbaturin/soupault.neocities.org/blob/314be103fb917edb06ca70f18b6f9370b120f5f5/scripts/index.py

import sys
import json
import pystache

from datetime import datetime


max_entries = 10
template = """
<div class="entry">
  <span class="bold">{{date}}</span>: <a href="{{url}}">{{{title}}}</a>
</div>
"""
renderer = pystache.Renderer()
read = sys.stdin.read()
sys.stdin.close()
all_entries = json.loads(read)
index_entries = []
this_year = datetime.now().year


for entry in all_entries:
    # Don't try to list files that aren't blog posts.
    if entry["title"] is not None and entry["date"] is not None:
        if len(index_entries) < max_entries:
            index_entries.append(entry)
        else:
            break

for entry in index_entries:
    print(renderer.render(template, entry))