From dc48e2b38cf5ccd875948121df14a6b3ca397d4f Mon Sep 17 00:00:00 2001 From: ktyl Date: Sun, 14 Aug 2022 00:50:04 +0100 Subject: [PATCH] ensure index entries are ordered chronologically --- scripts/mkblogindex.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/mkblogindex.py b/scripts/mkblogindex.py index 516a586..febbc86 100644 --- a/scripts/mkblogindex.py +++ b/scripts/mkblogindex.py @@ -26,6 +26,8 @@ title_pattern = re.compile("

(.+)

") posts = [p for p in posts if path_pattern.match(p)] posts.reverse() +links = [] + # for each file we want to output an tag with a relative href to the site root for path in posts: m = re.match(path_pattern, path) @@ -45,5 +47,13 @@ for path in posts: # clean leading directories to get the relative path we'll use for the link url = re.sub(dir_pattern, r"\2", path) - print(f'
  • {date}{title}
  • ') + item = (date, f'
  • {date}{title}
  • ') + links.append(item) + +# make sure we're properly ordered in reverse date order lol +links = sorted(links, key=lambda x: x[0]) +links.reverse() + +for l in links: + print(l[1])