Skip header elements when generating an RSS feed

This commit is contained in:
Fabio Manganiello 2021-01-26 01:59:18 +01:00
parent 8a62c6a915
commit 8975ae8e09
2 changed files with 8 additions and 5 deletions

View file

@ -51,7 +51,7 @@ def get_page_metadata(page: str) -> dict:
return metadata return metadata
def get_page(page: str, title: Optional[str] = None): def get_page(page: str, title: Optional[str] = None, skip_header: bool = False):
if not page.endswith('.md'): if not page.endswith('.md'):
page = page + '.md' page = page + '.md'
@ -63,14 +63,15 @@ def get_page(page: str, title: Optional[str] = None):
description=metadata.get('description'), description=metadata.get('description'),
published=(metadata['published'].strftime('%b %d, %Y') published=(metadata['published'].strftime('%b %d, %Y')
if metadata.get('published') else None), if metadata.get('published') else None),
content=markdown(f.read(), extensions=['fenced_code', 'codehilite'])) content=markdown(f.read(), extensions=['fenced_code', 'codehilite']),
skip_header=skip_header)
def get_pages(with_content: bool = False) -> list: def get_pages(with_content: bool = False, skip_header: bool = False) -> list:
return sorted([ return sorted([
{ {
'path': path, 'path': path,
'content': get_page(path) if with_content else '', 'content': get_page(path, skip_header=skip_header) if with_content else '',
**get_page_metadata(os.path.basename(path)), **get_page_metadata(os.path.basename(path)),
} }
for path in glob(os.path.join(pages_dir, '*.md')) for path in glob(os.path.join(pages_dir, '*.md'))
@ -104,7 +105,7 @@ def article_route(article: str):
@app.route('/rss', methods=['GET']) @app.route('/rss', methods=['GET'])
def rss_route(): def rss_route():
pages = get_pages(with_content=True) pages = get_pages(with_content=True, skip_header=True)
return Response('''<?xml version="1.0" encoding="UTF-8" ?> return Response('''<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/> <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/>

View file

@ -4,6 +4,7 @@
<main> <main>
<div class="container"> <div class="container">
{% if not skip_header %}
<div class="title"> <div class="title">
<h1>{{ title }}</h1> <h1>{{ title }}</h1>
</div> </div>
@ -19,6 +20,7 @@
Published on {{ published }} Published on {{ published }}
</div> </div>
{% endif %} {% endif %}
{% endif %}
<div class="content"> <div class="content">
{{ content | safe }} {{ content | safe }}