mjestecko/tools/main_page_generator.py

46 lines
1.2 KiB
Python
Raw Normal View History

2023-05-21 14:24:54 +00:00
#!/usr/bin/python3
from sys import argv, exit
from os import walk, path
from random import choice
2023-05-21 14:24:54 +00:00
import time, urllib.parse
from article_utils import parse_metadata, MONTHS
from page_shares import wrap_page
2023-05-21 14:24:54 +00:00
if len(argv) <= 1:
print("No directory was supplied")
exit(-1)
page_metadata = """Title: mjestečko
2023-05-21 14:24:54 +00:00
CSS: /style.css
"""
adjectives = ["*wild*", "**wacky**", "very humble", "**most serious**"]
2023-05-21 14:24:54 +00:00
page = f"""Personal blog of one {choice(adjectives)} Veclav Talica.
2023-05-21 14:24:54 +00:00
---
2023-05-21 14:24:54 +00:00
### Articles ###
"""
# todo: Sort by date first.
for root, dirs, _ in walk(argv[1]):
for d in dirs:
metadata = parse_metadata(path.abspath(root + '/' + d + "/page.mmd"))
article = urllib.parse.quote(d)
page += (
f"""[{metadata.get("Title", "No title given! What a clusterfuck!")}](/articles/{article}.html)\n\n"""
f""">{metadata.get("Brief", "")}\n\n"""
)
if "Tags" in metadata:
page += f""">*{','.join(metadata["Tags"])}*\n---\n"""
2023-05-21 14:24:54 +00:00
curtime = time.gmtime(int(time.time()))
2023-05-22 09:11:24 +00:00
page += f"Last compiled: *{MONTHS[curtime.tm_mon]} {curtime.tm_mday}, {curtime.tm_year} {curtime.tm_hour}:{curtime.tm_min:02d}*\n\n"
2023-05-21 14:24:54 +00:00
print(page_metadata + wrap_page(page))