~hristoast/hristoast

ref: 766050abd12f117f2f1a47b8587a81f109778261 hristoast/scripts/index.py -rwxr-xr-x 856 bytes
766050abHristos N. Triantafillou This is needed 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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))