From c6846781ed7e11c90e703c56b4e9f7659b127941 Mon Sep 17 00:00:00 2001 From: kayomn Date: Fri, 18 Aug 2023 00:16:32 +0100 Subject: [PATCH] Initial commit --- .gitignore | 5 ++ posts/2023-08-16-hello-world.md | 13 +++++ publish.py | 84 +++++++++++++++++++++++++++++++++ templates/rss_feed.rss | 16 +++++++ templates/site_base.html | 19 ++++++++ templates/site_feed.html | 13 +++++ templates/site_post.html | 7 +++ 7 files changed, 157 insertions(+) create mode 100644 .gitignore create mode 100644 posts/2023-08-16-hello-world.md create mode 100644 publish.py create mode 100644 templates/rss_feed.rss create mode 100644 templates/site_base.html create mode 100644 templates/site_feed.html create mode 100644 templates/site_post.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9fe2c23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +output/ +bin/ +lib/ +lib64 +pyvenv.cfg diff --git a/posts/2023-08-16-hello-world.md b/posts/2023-08-16-hello-world.md new file mode 100644 index 0000000..5ace3f6 --- /dev/null +++ b/posts/2023-08-16-hello-world.md @@ -0,0 +1,13 @@ +# Hello, World + +This is a test of the new announcement feed system. + +From here on, all announcements regarding all things Source Control will come through here. That includes notices of maintenance, downtime, as well as more general updates about the service. + +The biggest motivator for this move, aside from my personal want to do some web design for a change, was to start breaking moves on our community dependence on Discord. For too long now, it's been the one and only avenue through which all maintenance notices and forewords about website changes have been announced. + +Aside from the heavy reliance on a third-party and that being against the a key mission statement of why this website exists, Discord is also a lacking syndication system. Posts can be pinned and announcements can push notifications to personal devices, sure, but it's far more tailored to a conversational experience than a platform for news propagation. + +Our new solution uses RSS, and allows us to distribute information without having to worry about third parties being involved in the process. With it being a web standard and core technology of the internet, it's been tested by time and has a higher level of reliability than Discord or any highly dynamic internet-based service for that matter. + +Aside from visiting the website directly to view updates, you can also subscribe to our RSS feed at [https://pizzawednes.day/feed.rss](https://pizzawednes.day/feed.rss) and receive notifications to any device you wish to that supports RSS content. Further, we will continue pushing announcement to Discord - now through an RSS relay bot. diff --git a/publish.py b/publish.py new file mode 100644 index 0000000..ecb099b --- /dev/null +++ b/publish.py @@ -0,0 +1,84 @@ +import datetime +import jinja2 +import markdown +import os +import strip_markdown +import typing + +class Post(typing.NamedTuple): + title: str + path: str + pub_date: datetime.datetime + +base_url = "https://pizzawednes.day/" +cwd_path = os.getcwd() +output_path = os.path.join(cwd_path, "output") + +if not os.path.exists(output_path): + os.mkdir(output_path) + +feed_path = os.path.join(output_path, "feed") + +if not os.path.exists(feed_path): + os.mkdir(feed_path) + +jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.join(cwd_path, "templates"))) +posts_path = os.path.join(cwd_path, "posts") +post_template = jinja_env.get_template("site_post.html") +datetime_format_len = 10 +markdown_extension = ".md" +posts: list[Post] = [] + +for filename in os.listdir(posts_path): + if not filename.endswith(markdown_extension): + continue + + if len(filename) < datetime_format_len: + continue + + pub_date = datetime.datetime.min + + try: + pub_date = datetime.datetime.strptime(filename[0:datetime_format_len], "%Y-%m-%d").replace( + hour=0, + minute=0, + second=0, + microsecond=0, + ) + except ValueError: + pass + + with open(os.path.join(posts_path, filename)) as source_file: + content = source_file.read() + title = "" + + try: + first_newline_index = content.index('\n') + title = strip_markdown.strip_markdown(content[0:first_newline_index]) + except ValueError: + pass + + slug = filename[:-len(markdown_extension)] + + posts.append(Post( + title=title, + path=os.path.join("feed", slug), + pub_date=pub_date, + )) + + with open(f"{os.path.join(feed_path, slug)}.html", "w") as output_file: + output_file.write(post_template.render( + title = title, + content = markdown.markdown(content), + )) + +with open(f"{feed_path}.rss", "w") as file: + file.write(jinja_env.get_template("rss_feed.rss").render( + base_url = base_url, + posts = posts, + )) + +with open(f"{feed_path}.html", "w") as file: + file.write(jinja_env.get_template("site_feed.html").render( + posts = posts, + )) \ No newline at end of file diff --git a/templates/rss_feed.rss b/templates/rss_feed.rss new file mode 100644 index 0000000..7e2581d --- /dev/null +++ b/templates/rss_feed.rss @@ -0,0 +1,16 @@ + + + + Pizza Wednesday Feed + {{ base_url }} + Announcements regarding pizzawednes.day and related services + + {% for post in posts %} + + {{ post.title }} + {{ base_url }}{{ post.path }} + {{ post.pub_date.strftime('%a, %d %b %Y %H:%M:%S %z') }} + + {% endfor %} + + diff --git a/templates/site_base.html b/templates/site_base.html new file mode 100644 index 0000000..288511f --- /dev/null +++ b/templates/site_base.html @@ -0,0 +1,19 @@ + + + + + {% block title %}Pizza Wednesday{% endblock %} + + + +
Pizza Wednesday
+ + + +
+ {% block content %}{% endblock %} +
+ + diff --git a/templates/site_feed.html b/templates/site_feed.html new file mode 100644 index 0000000..45b81d6 --- /dev/null +++ b/templates/site_feed.html @@ -0,0 +1,13 @@ +{% extends "site_base.html" %} + +{% block title %}Pizza Wednesday Feed{% endblock %} + +{% block content %} +{% for post in posts %} +
+
{{ post.title }}
+
{{ base_url }}{{ post.path }}
+
{{ post.pub_date.strftime('%a, %d %b %Y %H:%M:%S %z') }}
+
+{% endfor %} +{% endblock %} \ No newline at end of file diff --git a/templates/site_post.html b/templates/site_post.html new file mode 100644 index 0000000..ae5b532 --- /dev/null +++ b/templates/site_post.html @@ -0,0 +1,7 @@ +{% extends "site_base.html" %} + +{% block title %}{{ title }} - Pizza Wednesday Feed{% endblock %} + +{% block content %} + {{ content }} +{% endblock %} \ No newline at end of file