Initial commit

This commit is contained in:
kayomn 2023-08-18 00:16:32 +01:00
commit c6846781ed
7 changed files with 157 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
output/
bin/
lib/
lib64
pyvenv.cfg

View File

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

84
publish.py Normal file
View File

@ -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,
))

16
templates/rss_feed.rss Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Pizza Wednesday Feed</title>
<link>{{ base_url }}</link>
<description>Announcements regarding pizzawednes.day and related services</description>
{% for post in posts %}
<item>
<title>{{ post.title }}</title>
<link>{{ base_url }}{{ post.path }}</link>
<pubDate>{{ post.pub_date.strftime('%a, %d %b %Y %H:%M:%S %z') }}</pubDate>
</item>
{% endfor %}
</channel>
</rss>

19
templates/site_base.html Normal file
View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}Pizza Wednesday{% endblock %}</title>
</head>
<body>
<div>Pizza Wednesday</div>
<nav>
<a href="/feed">Feed</a>
</nav>
<main>
{% block content %}{% endblock %}
</main>
</body>
</html>

13
templates/site_feed.html Normal file
View File

@ -0,0 +1,13 @@
{% extends "site_base.html" %}
{% block title %}Pizza Wednesday Feed{% endblock %}
{% block content %}
{% for post in posts %}
<div>
<div>{{ post.title }}</div>
<div>{{ base_url }}{{ post.path }}</div>
<div>{{ post.pub_date.strftime('%a, %d %b %Y %H:%M:%S %z') }}</div>
</div>
{% endfor %}
{% endblock %}

7
templates/site_post.html Normal file
View File

@ -0,0 +1,7 @@
{% extends "site_base.html" %}
{% block title %}{{ title }} - Pizza Wednesday Feed{% endblock %}
{% block content %}
{{ content }}
{% endblock %}