From a09253b2cf4181ae9a6772a50544c8bfa11b0b85 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Mon, 6 Jan 2025 12:12:51 +0100 Subject: [PATCH] RSS --- src/compiler.py | 6 ++++++ src/rss_generator.py | 12 ++++++++++++ src/server.py | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/rss_generator.py diff --git a/src/compiler.py b/src/compiler.py index 64f2026..58788b5 100644 --- a/src/compiler.py +++ b/src/compiler.py @@ -9,6 +9,7 @@ from minify_html import minify from article import Article, Page, Site from template import TemplateEnvironment +from rss_generator import generate_rss def compile(work_directory: str, template_directory: str=None, target_directory: str=None, force: bool=False, render_drafts: bool=False) -> str: if not isdir(work_directory): @@ -72,6 +73,11 @@ def compile(work_directory: str, template_directory: str=None, target_directory: articles.sort(key=lambda a : a.created_at, reverse=True) + rss_feed = generate_rss(site, articles) + file = open(join(target_directory, 'posts.rss'), 'w') + file.write(rss_feed) + file.close() + page_index = 1 pages = ceil(len(articles) / articles_per_page) while len(articles) > 0: diff --git a/src/rss_generator.py b/src/rss_generator.py new file mode 100644 index 0000000..2e23225 --- /dev/null +++ b/src/rss_generator.py @@ -0,0 +1,12 @@ +from article import Site, Article + +def generate_rss(site: Site, articles: list[Article]) -> str: + content = '' + content += f'{site.name}{site.url}' + + for article in articles: + content += f'{article.title}{site.url}/article/{article.id}.html{article.summary}{article.created_at.strftime("%a, %d %b %Y %H:%M:%S %Z")}' + + content += '' + + return content \ No newline at end of file diff --git a/src/server.py b/src/server.py index 46a0039..785351f 100644 --- a/src/server.py +++ b/src/server.py @@ -18,4 +18,4 @@ def run(directory: str): return app.send_static_file(path) - app.run() \ No newline at end of file + app.run(host='0.0.0.0') \ No newline at end of file