RSS
This commit is contained in:
parent
d557bce477
commit
a09253b2cf
3 changed files with 19 additions and 1 deletions
|
@ -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:
|
||||
|
|
12
src/rss_generator.py
Normal file
12
src/rss_generator.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from article import Site, Article
|
||||
|
||||
def generate_rss(site: Site, articles: list[Article]) -> str:
|
||||
content = '<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0">'
|
||||
content += f'<channel><title>{site.name}</title><link>{site.url}</link>'
|
||||
|
||||
for article in articles:
|
||||
content += f'<item><title>{article.title}</title><link>{site.url}/article/{article.id}.html</link><description>{article.summary}</description><pubDate>{article.created_at.strftime("%a, %d %b %Y %H:%M:%S %Z")}</pubDate></item>'
|
||||
|
||||
content += '</channel></rss>'
|
||||
|
||||
return content
|
|
@ -18,4 +18,4 @@ def run(directory: str):
|
|||
return app.send_static_file(path)
|
||||
|
||||
|
||||
app.run()
|
||||
app.run(host='0.0.0.0')
|
Reference in a new issue