mirror of
https://github.com/alvierahman90/gronk.git
synced 2025-05-10 14:36:05 +00:00
sort posts in rss feed by date
This commit is contained in:
parent
8300c4ba45
commit
7bee57bcd5
36
gronk.py
36
gronk.py
@ -14,6 +14,7 @@ import time
|
|||||||
import magic
|
import magic
|
||||||
import regex as re
|
import regex as re
|
||||||
import pprint
|
import pprint
|
||||||
|
from datetime import datetime as dt
|
||||||
|
|
||||||
import frontmatter
|
import frontmatter
|
||||||
import jinja2
|
import jinja2
|
||||||
@ -246,6 +247,13 @@ class FileMap:
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
def rfc822_date_sorter_key(date):
|
||||||
|
if date is None:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
int(dt.strptime(date, '%a, %d %b %Y %H:%M:%S %z').timestamp())
|
||||||
|
|
||||||
|
|
||||||
def update_required(src_filepath, output_filepath):
|
def update_required(src_filepath, output_filepath):
|
||||||
"""
|
"""
|
||||||
check if file requires an update,
|
check if file requires an update,
|
||||||
@ -531,6 +539,22 @@ def main(args):
|
|||||||
}
|
}
|
||||||
posts.append(post)
|
posts.append(post)
|
||||||
|
|
||||||
|
posts.sort(
|
||||||
|
key=lambda p: rfc822_date_sorter_key(p.get('pub_date')),
|
||||||
|
reverse=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# render rss feed
|
||||||
|
rss = JINJA_TEMPLATE_BLOG_FEED.render(
|
||||||
|
title=root_properties.get('title', ''),
|
||||||
|
description=root_properties.get('content', ''),
|
||||||
|
base_url=FILEMAP.get_base_url(),
|
||||||
|
link=f"{FILEMAP.get_base_url()}{root_properties['dst_path']['web']}",
|
||||||
|
language='en-GB',
|
||||||
|
posts=posts,
|
||||||
|
)
|
||||||
|
root_properties['dst_path']['raw'].joinpath('feed.xml').write_text(rss)
|
||||||
|
|
||||||
#pprint.pprint(root_properties)
|
#pprint.pprint(root_properties)
|
||||||
# render index
|
# render index
|
||||||
html = (JINJA_TEMPLATE_BLOGINDEX if root_properties['blog'] else JINJA_TEMPLATE_INDEX).render(
|
html = (JINJA_TEMPLATE_BLOGINDEX if root_properties['blog'] else JINJA_TEMPLATE_INDEX).render(
|
||||||
@ -549,18 +573,6 @@ def main(args):
|
|||||||
)
|
)
|
||||||
root_properties['dst_path']['raw'].joinpath('index.html').write_text(html)
|
root_properties['dst_path']['raw'].joinpath('index.html').write_text(html)
|
||||||
|
|
||||||
# render rss feed if blog
|
|
||||||
if root_properties['blog']:
|
|
||||||
rss = JINJA_TEMPLATE_BLOG_FEED.render(
|
|
||||||
title=root_properties.get('title', ''),
|
|
||||||
description=root_properties.get('content', ''),
|
|
||||||
base_url=FILEMAP.get_base_url(),
|
|
||||||
link=f"{FILEMAP.get_base_url()}{root_properties['dst_path']['web']}",
|
|
||||||
language='en-GB',
|
|
||||||
posts=posts,
|
|
||||||
)
|
|
||||||
root_properties['dst_path']['raw'].joinpath('feed.xml').write_text(rss)
|
|
||||||
|
|
||||||
# render each file
|
# render each file
|
||||||
for file in files:
|
for file in files:
|
||||||
render_file(root.joinpath(file))
|
render_file(root.joinpath(file))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user