From 77ea6079de49797980e96d1d1601893901ff9704 Mon Sep 17 00:00:00 2001 From: waldek Date: Mon, 6 Mar 2023 10:18:13 +1100 Subject: [PATCH] adds the first header as a title to blog posts --- jetforce/app/static_md.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/jetforce/app/static_md.py b/jetforce/app/static_md.py index 41010ae..1f9670f 100644 --- a/jetforce/app/static_md.py +++ b/jetforce/app/static_md.py @@ -1,6 +1,7 @@ import typing import os import pathlib +import datetime import urllib import md2gemini from .static import StaticDirectoryApplication @@ -141,8 +142,18 @@ class StaticMarkdownDirectoryApplication(StaticDirectoryApplication): buffer += f"=>/{encoded_path}/\t{file.name}/\r\n".encode() else: if file.stem.isdigit(): - tz = pytz.timezone("Europe/Brussels") - label = datetime.datetime.fromtimestamp(int(file.stem), tz=tz) + # this is a blogpost, let's make a decent label + date = datetime.datetime.fromtimestamp(int(file.stem)) + with file.open("r") as fp: + while True: + data = fp.readline() + if data.startswith("#"): + title = data.replace("#", "").strip() + break + if not data: + title = "Untitled" + break + label = "{}: {}".format(date, title) else: label = f"{file.name}" buffer += f"=>/{encoded_path}\t{label}\r\n".encode()