diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-05-18 20:31:14 -0600 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-05-18 20:35:04 -0600 |
| commit | c7ff1c0a664803e9788a73b9edfbe4606aa2eee7 (patch) | |
| tree | 9a4f2959aa5886c10df80e3a9bdfaebda0893369 | |
| parent | a598e3b037da9f0354a9d306ae3e1dd6ac4ac48c (diff) | |
| download | muhqs-game-c7ff1c0a664803e9788a73b9edfbe4606aa2eee7.tar.gz muhqs-game-c7ff1c0a664803e9788a73b9edfbe4606aa2eee7.zip | |
add rss feed
| -rw-r--r-- | html/Makefile | 10 | ||||
| -rw-r--r-- | html/feed/create_feed.py | 61 | ||||
| -rw-r--r-- | html/feed/items/news_feed_available.xml | 6 | ||||
| -rw-r--r-- | html/index.md | 2 |
4 files changed, 77 insertions, 2 deletions
diff --git a/html/Makefile b/html/Makefile index 49678014..80e36940 100644 --- a/html/Makefile +++ b/html/Makefile @@ -66,7 +66,8 @@ FILES_TO_COPY_TARGETS := $(addprefix $(BUILDDIR)/,$(FILES_TO_COPY)) all: $(HTML) $(RULES_HTML) maps misc $(BLOG_POSTS_HTML) misc: $(BUILDDIR)/latex-build $(BUILDDIR)/cards-data $(FILES_TO_COPY_TARGETS) \ - $(BUILDDIR)/webtools.wasm + $(BUILDDIR)/webtools.wasm \ + $(BUILDDIR)/feed.rss wasm_exec.js: $(shell go env GOROOT)/lib/wasm/wasm_exec.js cp $< $@ @@ -137,3 +138,10 @@ endef $(eval $(call generateHtml, $(BUILDDIR),)) $(eval $(call generateRulesHtml, $(BUILDDIR)/rules, -N)) $(eval $(call generateHtml, $(BUILDDIR)/blog,)) + +FEEDSRC = feed +GEN_FEED = $(FEEDSRC)/create_feed.py +FEEDITEMS = $(wildcard $(FEEDSRC)/items/*) + +$(BUILDDIR)/feed.rss: $(FEEDITEMS) $(GEN_FEED) + $(VERBOSE)python3 $(GEN_FEED) $(FEEDITEMS) > $@ diff --git a/html/feed/create_feed.py b/html/feed/create_feed.py new file mode 100644 index 00000000..17f2afdf --- /dev/null +++ b/html/feed/create_feed.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +"""Create a rss feed from a list of item files""" + +import argparse +from email.utils import parsedate_to_datetime, formatdate +from datetime import datetime +from string import Template +import sys +import xml.etree.ElementTree as ET + +FEED_HEAD = """<?xml version="1.0" encoding="UTF-8"?> +<rss version="2.0"> +<channel> +<title>$title</title> +<link>$link</link> +<description>$description</description> +<language>$language</language> +<pubDate>$pubDate</pubDate>""" + +FEED_TAIL = """</channel> +</rss>""" + + +def item_date_to_epoch(item) -> int: + """return the time from epoch to the pubDate of an item""" + pub_date = item.find('pubDate') + date = parsedate_to_datetime(pub_date.text) + return date.timestamp() + + +def main(): + """read item files sort them and print a sorted rss feed""" + parser = argparse.ArgumentParser() + parser.add_argument('--link', default='https://muhq.space/muhqs-game') + parser.add_argument('--title', default="Muhq's Game") + parser.add_argument('--description', + default="What is happening with muhq's game?") + parser.add_argument('--language', default='en') + parser.add_argument('--pubDate', default='Sun, 18 May 2025 20:21:20 -0600') + parser.add_argument('items', nargs='*') + args = parser.parse_args() + + head = Template(FEED_HEAD) + print(head.substitute(**args.__dict__)) + + items = [] + for item_path in args.items: + items.append(ET.parse(item_path)) + + items.sort(reverse=True, key=item_date_to_epoch) + + last_build_date = formatdate(datetime.now().timestamp()) + print(f'<lastBuildDate>{last_build_date}</lastBuildDate>') + for item in items: + item.write(sys.stdout, encoding='unicode') + print() + print(FEED_TAIL) + + +if __name__ == '__main__': + main() diff --git a/html/feed/items/news_feed_available.xml b/html/feed/items/news_feed_available.xml new file mode 100644 index 00000000..19b2d90d --- /dev/null +++ b/html/feed/items/news_feed_available.xml @@ -0,0 +1,6 @@ +<item> +<title>News feed available</title> +<description>Stay informed about what is happening with muhq's game.</description> +<link>https://muhq.space/muhqs-game</link> +<pubDate>Sun, 18 May 2025 20:22:47 -0600</pubDate> +</item> diff --git a/html/index.md b/html/index.md index a889b53d..43e7202a 100644 --- a/html/index.md +++ b/html/index.md @@ -1,7 +1,7 @@ % Muhq's Game (working title) <hr> -[rules](rules.html) [cards](cards.html) [decks](decks.html) [maps](maps.html) [web-tools](tools.html) [blog](blog/) +[rules](rules.html) [cards](cards.html) [decks](decks.html) [maps](maps.html) [web-tools](tools.html) [blog](blog/) [feed](feed.rss) <hr> Muhq's game is a mashup of multiple game mechanics I enjoy. |
