diff --git a/compile.sh b/compile.sh index 0a08067..e894934 100755 --- a/compile.sh +++ b/compile.sh @@ -9,3 +9,5 @@ for d in ./articles/*; do ./tools/article_wrapper.py "$d/page.mmd" | ./tools/mmd/build/multimarkdown > "./html/articles/$(basename -- $d).html" fi done + +./tools/feed_generator.py ./articles/ https://mjestecko.neocities.org/ > ./html/feed.xml diff --git a/tools/feed_generator.py b/tools/feed_generator.py new file mode 100755 index 0000000..29461f2 --- /dev/null +++ b/tools/feed_generator.py @@ -0,0 +1,64 @@ +#!/usr/bin/python3 + +from sys import argv, exit +from os import walk, path +from random import choice, seed +from textwrap import indent +import time, urllib.parse, re, subprocess + +from article_utils import parse_metadata +from page_shares import ADJECTIVES +from rfc822 import stringify_date + +if len(argv) <= 1: + print("No directory was supplied") + exit(-1) + +if len(argv) <= 2: + print("No address was supplied") + exit(-1) + +seed() + +address = argv[2] + +# todo: Find the latest pubDate +feed = f""" + + mjestečko + {address} + Personal blog of one {choice(ADJECTIVES)} Veclav Talica + en + {stringify_date(time.gmtime(int(time.time())))} +""" + +body_taker = re.compile(r"(.*)", re.DOTALL) + +for root, dirs, _ in walk(argv[1]): + for d in dirs: + metadata = parse_metadata(path.abspath(root + '/' + d + "/page.mmd")) + feed += ( + " \n" + f""" {metadata.get("Title", "No title!? ;-;")}\n""" + ) + body = subprocess.getoutput(f"./tools/mmd/build/multimarkdown {root}/{d}/page.mmd") + feed += ( + " \n" + " \n" + " \n" + ) + if "Date" in metadata: + feed += \ + f""" {stringify_date(metadata["Date"])}\n""" + feed += ( + f""" /articles/{d}\n""" + f""" {address}/articles/{urllib.parse.quote(d)}\n""" + " \n" + ) + +feed += """ +""" + +print(feed) diff --git a/tools/rfc822.py b/tools/rfc822.py new file mode 100644 index 0000000..5636ff1 --- /dev/null +++ b/tools/rfc822.py @@ -0,0 +1,4 @@ +from page_shares import MONTHS, WEEKDAYS + +def stringify_date(date) -> str: + return f"{WEEKDAYS[date.tm_wday][:3]}, {date.tm_mday} {MONTHS[date.tm_mon][:3]} {date.tm_year} {date.tm_hour:02d}:{date.tm_min:02d}:{date.tm_sec:02d} GMT"