init
This commit is contained in:
commit
0398828c01
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "tools/mmd"]
|
||||||
|
path = tools/mmd
|
||||||
|
url = https://github.com/fletcher/MultiMarkdown-6
|
14
compile.py
Executable file
14
compile.py
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from os import walk
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
subprocess.run("./tools/main_page_generator.py ./articles | ./tools/mmd/build/multimarkdown > ./html/index.html", shell=True)
|
||||||
|
subprocess.run("mkdir -p ./html/articles", shell=True)
|
||||||
|
|
||||||
|
for root, dirs, _ in walk("./articles"):
|
||||||
|
for d in dirs:
|
||||||
|
subprocess.run(
|
||||||
|
f"""./tools/article_wrapper.py ./articles/{d}/page.mmd | ./tools/mmd/build/multimarkdown > ./html/articles/{d}.html""",
|
||||||
|
shell=True
|
||||||
|
)
|
9
prepare.sh
Executable file
9
prepare.sh
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
git submodule init
|
||||||
|
git submodule update
|
||||||
|
cd tools/mmd
|
||||||
|
make release
|
||||||
|
cd build
|
||||||
|
make
|
||||||
|
cd ../..
|
BIN
tools/__pycache__/article_utils.cpython-38.pyc
Normal file
BIN
tools/__pycache__/article_utils.cpython-38.pyc
Normal file
Binary file not shown.
41
tools/article_utils.py
Normal file
41
tools/article_utils.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import time, subprocess
|
||||||
|
|
||||||
|
MONTHS = {
|
||||||
|
1: "January",
|
||||||
|
2: "February",
|
||||||
|
3: "March",
|
||||||
|
4: "April",
|
||||||
|
5: "May",
|
||||||
|
6: "June",
|
||||||
|
7: "July",
|
||||||
|
8: "August",
|
||||||
|
9: "September",
|
||||||
|
10: "October",
|
||||||
|
11: "November",
|
||||||
|
12: "December"
|
||||||
|
}
|
||||||
|
|
||||||
|
def the_line_after_metadata(lines: []) -> int:
|
||||||
|
i = 0
|
||||||
|
while lines[i].strip():
|
||||||
|
i += 1
|
||||||
|
return i
|
||||||
|
|
||||||
|
def parse_metadata(filepath: str) -> {}:
|
||||||
|
result = {}
|
||||||
|
with open(filepath, "r") as f:
|
||||||
|
content = f.readlines()
|
||||||
|
i = the_line_after_metadata(content)
|
||||||
|
|
||||||
|
for line in content[:i]:
|
||||||
|
delim = line.find(":")
|
||||||
|
key, val = (line[:delim].strip(), line[delim+1:].strip())
|
||||||
|
if key == "Date":
|
||||||
|
result["date"] = time.gmtime(int(val))
|
||||||
|
elif key == "Tags":
|
||||||
|
result["tags"] = val.split(",")
|
||||||
|
else:
|
||||||
|
result[key.lower()] = val
|
||||||
|
result["last_edit"] = time.gmtime(int(subprocess.getoutput(r"stat -c %Y " + filepath)))
|
||||||
|
|
||||||
|
return result
|
72
tools/article_wrapper.py
Executable file
72
tools/article_wrapper.py
Executable file
@ -0,0 +1,72 @@
|
|||||||
|
#!/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>
|
||||||
|
<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)
|
44
tools/main_page_generator.py
Executable file
44
tools/main_page_generator.py
Executable file
@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from sys import argv, exit
|
||||||
|
from os import walk, path
|
||||||
|
import time, urllib.parse
|
||||||
|
|
||||||
|
from article_utils import parse_metadata, MONTHS
|
||||||
|
|
||||||
|
if len(argv) <= 1:
|
||||||
|
print("No directory was supplied")
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
|
page = """Title: mjestečko
|
||||||
|
CSS: /style.css
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
# mjestečko #
|
||||||
|
|
||||||
|
Personal blog of one Veclav Talica.
|
||||||
|
|
||||||
|
### 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"""
|
||||||
|
page += f"""{metadata.get("brief", "")}\n\n"""
|
||||||
|
if "tags" in metadata:
|
||||||
|
page += f"""*{','.join(metadata["tags"])}*\n\n"""
|
||||||
|
|
||||||
|
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}*
|
||||||
|
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
|
||||||
|
print(page)
|
1
tools/mmd
Submodule
1
tools/mmd
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 281827895db0190d41bda3c1d29a012b63dfd09b
|
Loading…
Reference in New Issue
Block a user