Skip to content

Commit b408df9

Browse files
sneakers-the-ratlwasser
authored andcommitted
use mtime to set rss feed timestamp
1 parent 4a1a586 commit b408df9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

_ext/rss.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,26 @@ class RSSItem:
3333
def from_meta(cls, page_name: str, meta: dict, app: "Sphinx") -> "RSSItem":
3434
"""Create from a page's metadata"""
3535
url = urljoin(app.config.html_baseurl, app.builder.get_target_uri(page_name))
36+
3637
# purposely don't use `get` here because we want to error if these fields are absent
3738
return RSSItem(
3839
title=meta[":og:title"],
3940
description=meta[":og:description"],
40-
date=datetime.fromisoformat(meta["date"]),
41+
date=cls.get_date_updated(page_name, meta, app),
4142
author=meta.get(":og:author", "pyOpenSci"),
4243
url=url,
4344
)
4445

46+
@staticmethod
47+
def get_date_updated(page_name: str, meta: dict, app: "Sphinx") -> datetime:
48+
"""if the page has an explicit date_updated, use that, otherwise get mtime"""
49+
if 'date_updated' in meta:
50+
return datetime.fromisoformat(meta['date_updated'])
51+
else:
52+
page_path = app.srcdir / (page_name + ".md")
53+
mtime = page_path.stat().st_mtime
54+
return datetime.fromtimestamp(mtime)
55+
4556
def render(self) -> str:
4657
return f"""\
4758
<item>

0 commit comments

Comments
 (0)