Compare commits

..

6 Commits

Author SHA1 Message Date
veclav talica
969d7ee5c1 add rss link to side panel 2023-05-22 18:38:08 +05:00
veclav talica
64938e2bbb exit shell on subprocess error 2023-05-22 18:30:16 +05:00
veclav talica
6a9f8572c9 move MONTHS to page_shares, add weekday dict 2023-05-22 18:29:58 +05:00
veclav talica
5cc4ff44a6 rss feed generation 2023-05-22 18:29:20 +05:00
veclav talica
fde6cfe644 move adjectives to page_shares.py 2023-05-22 16:21:00 +05:00
veclav talica
590f344c6d seed the rng by time 2023-05-22 16:18:54 +05:00
7 changed files with 108 additions and 23 deletions

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set +e
mkdir -p ./html/articles mkdir -p ./html/articles
./tools/main_page_generator.py ./articles | ./tools/mmd/build/multimarkdown > ./html/index.html ./tools/main_page_generator.py ./articles | ./tools/mmd/build/multimarkdown > ./html/index.html
@ -9,3 +11,5 @@ for d in ./articles/*; do
./tools/article_wrapper.py "$d/page.mmd" | ./tools/mmd/build/multimarkdown > "./html/articles/$(basename -- $d).html" ./tools/article_wrapper.py "$d/page.mmd" | ./tools/mmd/build/multimarkdown > "./html/articles/$(basename -- $d).html"
fi fi
done done
./tools/feed_generator.py ./articles/ https://mjestecko.neocities.org/ > ./html/feed.xml

View File

@ -1,20 +1,5 @@
import time, subprocess 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: def the_line_after_metadata(lines: []) -> int:
i = 0 i = 0
while lines[i].strip(): while lines[i].strip():

View File

@ -5,8 +5,8 @@
from sys import argv, exit 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
from page_shares import wrap_page from page_shares import wrap_page, MONTHS
if len(argv) <= 1: if len(argv) <= 1:
print("No file was supplied") print("No file was supplied")

64
tools/feed_generator.py Executable file
View File

@ -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"""<rss version="2.0">
<channel>
<title>mjestečko</title>
<link>{address}</link>
<description>Personal blog of one {choice(ADJECTIVES)} Veclav Talica</description>
<language>en</language>
<lastBuildDate>{stringify_date(time.gmtime(int(time.time())))}</lastBuildDate>
"""
body_taker = re.compile(r"<body>(.*)</body>", re.DOTALL)
for root, dirs, _ in walk(argv[1]):
for d in dirs:
metadata = parse_metadata(path.abspath(root + '/' + d + "/page.mmd"))
feed += (
" <item>\n"
f""" <title>{metadata.get("Title", "No title!? ;-;")}</title>\n"""
)
body = subprocess.getoutput(f"./tools/mmd/build/multimarkdown {root}/{d}/page.mmd")
feed += (
" <description>\n"
" <![CDATA[\n"
f"{indent(body_taker.search(body)[1], ' ' * 12)}\n"
" ]]>\n"
" </description>\n"
)
if "Date" in metadata:
feed += \
f""" <pubDate>{stringify_date(metadata["Date"])}</pubDate>\n"""
feed += (
f""" <guid>/articles/{d}</guid>\n"""
f""" <link>{address}/articles/{urllib.parse.quote(d)}</link>\n"""
" </item>\n"
)
feed += """ </channel>
</rss>"""
print(feed)

View File

@ -2,24 +2,24 @@
from sys import argv, exit from sys import argv, exit
from os import walk, path from os import walk, path
from random import choice from random import choice, seed
import time, urllib.parse import time, urllib.parse
from article_utils import parse_metadata, MONTHS from article_utils import parse_metadata
from page_shares import wrap_page from page_shares import wrap_page, ADJECTIVES, MONTHS
if len(argv) <= 1: if len(argv) <= 1:
print("No directory was supplied") print("No directory was supplied")
exit(-1) exit(-1)
seed()
page_metadata = """Title: mjestečko page_metadata = """Title: mjestečko
CSS: /style.css CSS: /style.css
""" """
adjectives = ["*wild*", "**wacky**", "very humble", "**most serious**"] page = f"""Personal blog of one {choice(ADJECTIVES)} Veclav Talica.
page = f"""Personal blog of one {choice(adjectives)} Veclav Talica.
--- ---

View File

@ -9,6 +9,7 @@ HEAD_EMBED = """
<ul class="nav"> <ul class="nav">
<li><a href="/">main page</a></li> <li><a href="/">main page</a></li>
<li><a href="https://git.poto.cafe/veclavtalica/mjestecko">source</a></li> <li><a href="https://git.poto.cafe/veclavtalica/mjestecko">source</a></li>
<li><a href="/feed.xml">rss</a></li>
<li><a href="/articles/mjestečko.html">about</a></li> <li><a href="/articles/mjestečko.html">about</a></li>
</ul> </ul>
@ -26,5 +27,32 @@ TAIL_EMBED = """
""" """
ADJECTIVES = ["*wild*", "**wacky**", "very humble", "**most serious**"]
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"
}
WEEKDAYS = {
0: "Monday",
1: "Tuesday",
2: "Wednesday",
3: "Thursday",
4: "Friday",
5: "Saturday",
6: "Sunday"
}
def wrap_page(page: str) -> str: def wrap_page(page: str) -> str:
return HEAD_EMBED + page + TAIL_EMBED return HEAD_EMBED + page + TAIL_EMBED

4
tools/rfc822.py Normal file
View File

@ -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"