2023-05-21 14:24:54 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
# todo: Show related git history of a file?
|
|
|
|
|
|
|
|
from sys import argv, exit
|
|
|
|
import time
|
|
|
|
|
|
|
|
from article_utils import the_line_after_metadata, parse_metadata, MONTHS
|
|
|
|
|
|
|
|
if len(argv) <= 1:
|
|
|
|
print("No file was supplied")
|
|
|
|
exit(-1)
|
|
|
|
|
|
|
|
with open(argv[1], "r") as f:
|
|
|
|
content = f.readlines()
|
|
|
|
i = the_line_after_metadata(content)
|
|
|
|
|
|
|
|
metadata = parse_metadata(argv[1])
|
|
|
|
|
|
|
|
HEAD_EMBED = """
|
|
|
|
<div style="display: flex;">
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
|
|
|
## mjestečko ##
|
|
|
|
|
|
|
|
<ul class="nav">
|
|
|
|
<li><a href="/">main page</a></li>
|
2023-05-21 16:04:57 +00:00
|
|
|
<li><a href="https://git.poto.cafe/veclavtalica/mjestecko">source</a></li>
|
2023-05-21 14:24:54 +00:00
|
|
|
<li><a href="/articles/mjestečko.html">about</a></li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="container">
|
|
|
|
"""
|
|
|
|
|
|
|
|
TAIL_EMBED = """
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
|
|
|
|
title = metadata.get("title", "Oopsie, somebody forgot to name the article!")
|
|
|
|
article_head = "\n# " + title + "\n" if title else \
|
|
|
|
"# Oopsie, somebody forgot to give it a title!\n"
|
|
|
|
|
|
|
|
brief = metadata.get("brief")
|
|
|
|
if not brief is None:
|
|
|
|
article_head += f"""
|
|
|
|
*{brief}*
|
|
|
|
"""
|
|
|
|
|
|
|
|
date = metadata.get("date")
|
|
|
|
if not date is None:
|
|
|
|
article_head += f"""
|
|
|
|
-- Date: *{MONTHS[date.tm_mon]} {date.tm_mday}, {date.tm_year}*
|
|
|
|
"""
|
|
|
|
|
|
|
|
last_edit = metadata.get("last_edit")
|
|
|
|
if not last_edit is None:
|
|
|
|
if date is None or last_edit.tm_mon != date.tm_mon or \
|
|
|
|
last_edit.tm_mday != date.tm_mday or last_edit.tm_year != date.tm_year:
|
|
|
|
article_head += f"""
|
|
|
|
-- Edit: *{MONTHS[last_edit.tm_mon]} {last_edit.tm_mday}, {last_edit.tm_year}*
|
|
|
|
"""
|
|
|
|
|
|
|
|
# todo: Hyperlinks to appropriate tag pages.
|
|
|
|
tags = metadata.get("tags")
|
|
|
|
if tags:
|
|
|
|
article_head += f"""
|
|
|
|
-- Tags: *{",".join(tags)}*
|
|
|
|
"""
|
|
|
|
|
|
|
|
print(''.join(content[:i]) + HEAD_EMBED + article_head + ''.join(content[i:]) + TAIL_EMBED)
|