aboutsummaryrefslogtreecommitdiff
path: root/pandoc-blog/generate-index.py
blob: 3e73f272244ef03a620e0f390b9abaecc828e5f3 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from pathlib import Path
import sys

index = sys.argv[1]
posts = sys.argv[2:]

posts_directory = "posts"

def strip_store_hash(filename):
    return filename[33:]

with open(index, "w") as index_file:
    for post in posts:
        with open(post) as post_file:
            for line in post_file:
                if line.startswith("title:"):
                    title = line.removeprefix("title:").strip()
                    slug = strip_store_hash(Path(post).stem)
                    print(f"- [{title}]({posts_directory}/{slug}.html)",
                          file=index_file)