This commit is contained in:
Midgard 2020-06-16 02:10:26 +02:00
parent 1582122ca2
commit 24a41ca958
Signed by untrusted user who does not match committer: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 69 additions and 1 deletions

View file

@ -7,12 +7,16 @@ PYTHON ::= venv/bin/python
.PHONY: all clean public
all: $(BUILD_DIR)/index.html $(BUILD_DIR)/syntax.css public $(BLOG_HTML)
all: $(BUILD_DIR)/index.html $(BUILD_DIR)/feed.xml $(BUILD_DIR)/syntax.css public $(BLOG_HTML)
$(BUILD_DIR)/index.html: templates/index.html $(BLOG) page.py
@mkdir -p "$(@D)"
$(PYTHON) page.py --index "$<" "$@" $(BLOG)
$(BUILD_DIR)/rss.xml: $(BLOG) rss.py page.py
@mkdir -p "$(@D)"
$(PYTHON) rss.py $(BLOG) > "$@"
$(BUILD_DIR)/blog/%.html: blog/%.md templates/blog.html page.py
@mkdir -p "$(@D)"
$(PYTHON) page.py "$<" "$@"

64
rss.py Executable file
View file

@ -0,0 +1,64 @@
#!/usr/bin/env python3
import sys
from functools import partial as p
from ipo import ipo, write, starstarmap
from page import blog_page_metadata
BASE_URL = "https://www.braindeaddev.com/P5t7oFqPF7oEX"
DOC_TEMPLATE = """<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Midgard's blog</title>
<description></description>
<lastBuildDate>{last_updated}</lastBuildDate>
<author>Midgard</author>
<link>{url}</link>{0}
</channel>
</rss>"""
ITEM_TEMPLATE = """
<item>
<title>{title}</title>
<guid>{path}</guid>
<pubDate>{published_rfc822}</pubDate>
<link>{url}</link>
<description>{summary}</description>
</item>"""
# <category>{category}</category>
def iso8601torfc822(iso8601):
# pylint: disable=invalid-name
y, m, d = map(int, iso8601.split("-"))
month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][m]
return f"{d} {month} {y} 00:00:00 UTC"
def main():
items = (
ipo(sys.argv[1:]) |
p(map, blog_page_metadata) |
p(sorted, key=lambda x: x["published"]) |
p(map, lambda x: {
**x,
"published_rfc822": iso8601torfc822(x["published"]),
"url": BASE_URL + x["path"]
}) | list
)
last_date = items.data[-1]["published_rfc822"]
(
items |
p(starstarmap, ITEM_TEMPLATE.format) |
"".join |
p(DOC_TEMPLATE.format, url=BASE_URL, last_updated=last_date) |
write
)
if __name__ == '__main__':
main()