adds the first header as a title to blog posts
This commit is contained in:
parent
1942a2bcc7
commit
77ea6079de
|
@ -1,6 +1,7 @@
|
||||||
import typing
|
import typing
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import datetime
|
||||||
import urllib
|
import urllib
|
||||||
import md2gemini
|
import md2gemini
|
||||||
from .static import StaticDirectoryApplication
|
from .static import StaticDirectoryApplication
|
||||||
|
@ -141,8 +142,18 @@ class StaticMarkdownDirectoryApplication(StaticDirectoryApplication):
|
||||||
buffer += f"=>/{encoded_path}/\t{file.name}/\r\n".encode()
|
buffer += f"=>/{encoded_path}/\t{file.name}/\r\n".encode()
|
||||||
else:
|
else:
|
||||||
if file.stem.isdigit():
|
if file.stem.isdigit():
|
||||||
tz = pytz.timezone("Europe/Brussels")
|
# this is a blogpost, let's make a decent label
|
||||||
label = datetime.datetime.fromtimestamp(int(file.stem), tz=tz)
|
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:
|
else:
|
||||||
label = f"{file.name}"
|
label = f"{file.name}"
|
||||||
buffer += f"=>/{encoded_path}\t{label}\r\n".encode()
|
buffer += f"=>/{encoded_path}\t{label}\r\n".encode()
|
||||||
|
|
Loading…
Reference in New Issue