style adjustment, main page consistent with article layout

This commit is contained in:
veclav talica 2023-05-21 22:23:39 +05:00
parent 1ec34652b5
commit a3f3b3410f
4 changed files with 64 additions and 61 deletions

View File

@ -31,11 +31,11 @@ def parse_metadata(filepath: str) -> {}:
delim = line.find(":") delim = line.find(":")
key, val = (line[:delim].strip(), line[delim+1:].strip()) key, val = (line[:delim].strip(), line[delim+1:].strip())
if key == "Date": if key == "Date":
result["date"] = time.gmtime(int(val)) result["Date"] = time.gmtime(int(val))
elif key == "Tags": elif key == "Tags":
result["tags"] = val.split(",") result["Tags"] = val.split(",")
else: else:
result[key.lower()] = val result[key] = val
result["last_edit"] = time.gmtime(int(subprocess.getoutput(r"stat -c %Y " + filepath))) result["Last Edit"] = time.gmtime(int(subprocess.getoutput(r"stat -c %Y " + filepath)))
return result return result

View File

@ -6,6 +6,7 @@ from sys import argv, exit
import time import time
from article_utils import the_line_after_metadata, parse_metadata, MONTHS from article_utils import the_line_after_metadata, parse_metadata, MONTHS
from page_shares import wrap_page
if len(argv) <= 1: if len(argv) <= 1:
print("No file was supplied") print("No file was supplied")
@ -17,57 +18,28 @@ with open(argv[1], "r") as f:
metadata = parse_metadata(argv[1]) metadata = parse_metadata(argv[1])
HEAD_EMBED = """ title = metadata.get("Title", "Oopsie, somebody forgot to name the article!")
<div style="display: flex;"> article_head = "\n# " + title + "\n---\n"
<div> brief = metadata.get("Brief")
## mjestečko ##
<ul class="nav">
<li><a href="/">main page</a></li>
<li><a href="https://git.poto.cafe/veclavtalica/mjestecko">source</a></li>
<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: if not brief is None:
article_head += f""" article_head += f"*{brief}*\n\n"
*{brief}*
"""
date = metadata.get("date") date = metadata.get("Date")
if not date is None: if not date is None:
article_head += f""" article_head += f"-- Created: *{MONTHS[date.tm_mon]} {date.tm_mday}, {date.tm_year}*\n\n"
-- Date: *{MONTHS[date.tm_mon]} {date.tm_mday}, {date.tm_year}*
"""
last_edit = metadata.get("last_edit") last_edit = metadata.get("Last Edit")
if not last_edit is None: if not last_edit is None:
if date is None or last_edit.tm_mon != date.tm_mon or \ 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: last_edit.tm_mday != date.tm_mday or last_edit.tm_year != date.tm_year:
article_head += f""" article_head += f"-- Edited: *{MONTHS[last_edit.tm_mon]} {last_edit.tm_mday}, {last_edit.tm_year}*\n\n"
-- Edit: *{MONTHS[last_edit.tm_mon]} {last_edit.tm_mday}, {last_edit.tm_year}*
"""
# todo: Hyperlinks to appropriate tag pages. # todo: Hyperlinks to appropriate tag pages.
tags = metadata.get("tags") tags = metadata.get("Tags")
if tags: if tags:
article_head += f""" article_head += f"""-- Tags: *{",".join(tags)}*\n\n"""
-- Tags: *{",".join(tags)}*
"""
print(''.join(content[:i]) + HEAD_EMBED + article_head + ''.join(content[i:]) + TAIL_EMBED) article_head += "---\n\n"
print(''.join(content[:i]) + wrap_page(article_head + ''.join(content[i:])))

View File

@ -2,22 +2,26 @@
from sys import argv, exit from sys import argv, exit
from os import walk, path from os import walk, path
from random import choice
import time, urllib.parse import time, urllib.parse
from article_utils import parse_metadata, MONTHS from article_utils import parse_metadata, MONTHS
from page_shares import wrap_page
if len(argv) <= 1: if len(argv) <= 1:
print("No directory was supplied") print("No directory was supplied")
exit(-1) exit(-1)
page = """Title: mjestečko page_metadata = """Title: mjestečko
CSS: /style.css CSS: /style.css
<div class="container"> """
# mjestečko # adjectives = ["*wild*", "**wacky**", "very humble", "**most serious**"]
Personal blog of one Veclav Talica. page = f"""Personal blog of one {choice(adjectives)} Veclav Talica.
---
### Articles ### ### Articles ###
@ -28,17 +32,14 @@ for root, dirs, _ in walk(argv[1]):
for d in dirs: for d in dirs:
metadata = parse_metadata(path.abspath(root + '/' + d + "/page.mmd")) metadata = parse_metadata(path.abspath(root + '/' + d + "/page.mmd"))
article = urllib.parse.quote(d) article = urllib.parse.quote(d)
page += f"""#### [{metadata.get("title", "No title given! What a clusterfuck!")}](/articles/{article}.html) ####\n""" page += (
page += f"""{metadata.get("brief", "")}\n\n""" f"""[{metadata.get("Title", "No title given! What a clusterfuck!")}](/articles/{article}.html)\n\n"""
if "tags" in metadata: f""">{metadata.get("Brief", "")}\n\n"""
page += f"""*{','.join(metadata["tags"])}*\n\n""" )
if "Tags" in metadata:
page += f""">*{','.join(metadata["Tags"])}*\n---\n"""
curtime = time.gmtime(int(time.time())) curtime = time.gmtime(int(time.time()))
page += f"Last compiled: *{MONTHS[curtime.tm_mon]} {curtime.tm_mday}, {curtime.tm_year} {curtime.tm_hour}:{curtime.tm_min:2}*\n\n"
page += f""" print(page_metadata + wrap_page(page))
Last compiled: *{MONTHS[curtime.tm_mon]} {curtime.tm_mday}, {curtime.tm_year} {curtime.tm_hour}:{curtime.tm_min}*
</div>
"""
print(page)

30
tools/page_shares.py Normal file
View File

@ -0,0 +1,30 @@
HEAD_EMBED = """
<div style="display: flex;">
<div>
## mjestečko ##
<ul class="nav">
<li><a href="/">main page</a></li>
<li><a href="https://git.poto.cafe/veclavtalica/mjestecko">source</a></li>
<li><a href="/articles/mjestečko.html">about</a></li>
</ul>
</div>
<div class="container">
"""
TAIL_EMBED = """
---
*Remember, - all you see here is free for use for any purpose whatsoever.*
</div>
"""
def wrap_page(page: str) -> str:
return HEAD_EMBED + page + TAIL_EMBED