Skip to content

Commit

Permalink
append posts to atom feed to keep post order from new to old (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexming authored Apr 3, 2023
1 parent ebfb408 commit f664689
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion roots/test-build/post.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. post:: 2020-12-01
.. post:: 2022-12-01
:tags: Foo Tag, BarTag

Foo Post Title
Expand Down
2 changes: 1 addition & 1 deletion src/ablog/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def generate_atom_feeds(app):
content = None
else:
content = post.to_html(pagename, fulltext=feed_fulltext)
feed_entry = feed.add_entry()
feed_entry = feed.add_entry(order="append")
feed_entry.id(post_url)
feed_entry.link(href=post_url)
feed_entry.author({"name": author.name for author in post.author})
Expand Down
11 changes: 11 additions & 0 deletions src/ablog/tests/test_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from datetime import datetime

import lxml
import pytest

POST_DATETIME_FMT = "%Y-%m-%dT%H:%M:%S%z"


@pytest.mark.sphinx("html", testroot="build") # using roots/test-build
def test_build(app, status, warning):
Expand Down Expand Up @@ -41,6 +45,8 @@ def test_feed(app, status, warning):
assert categories[1].attrib["term"] == "FooTag"
content = entry.find("{http://www.w3.org/2005/Atom}content")
assert "Foo post content." in content.text
update_time = entry.find("{http://www.w3.org/2005/Atom}updated")
first_entry_date = datetime.strptime(update_time.text, POST_DATETIME_FMT)

empty_entry = entries[1]
title = empty_entry.find("{http://www.w3.org/2005/Atom}title")
Expand All @@ -51,6 +57,11 @@ def test_feed(app, status, warning):
assert len(categories) == 0
content = empty_entry.find("{http://www.w3.org/2005/Atom}content")
assert 'id="foo-empty-post"' in content.text
update_time = empty_entry.find("{http://www.w3.org/2005/Atom}updated")
second_entry_date = datetime.strptime(update_time.text, POST_DATETIME_FMT)

# check order of post based on their dates
assert first_entry_date > second_entry_date

social_path = app.outdir / "blog/social.xml"
assert (social_path).exists()
Expand Down

0 comments on commit f664689

Please sign in to comment.