Skip to content

Commit 4f97e17

Browse files
committed
Correct lastmod time zone offset in sitemaps
Some sitemap parsers (including Google's) are apparently rather particular about the TZ offset formatting and can't handle ISO 8601. Change-Id: If27cb226a64dd58390b71b5833f99e862264dcd6 Signed-off-by: Jeremy Stanley <fungi@yuggoth.org>
1 parent c6b5d46 commit 4f97e17

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎sitemap/generator/spiders/sitemap_file.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,11 @@ def parse_item(self, response):
131131
timestamp = response.headers['Date']
132132
lastmod = time.strptime(timestamp.decode("utf-8"),
133133
"%a, %d %b %Y %H:%M:%S %Z")
134-
item['lastmod'] = time.strftime("%Y-%m-%dT%H:%M:%S%z", lastmod)
134+
formatted_lastmod = time.strftime("%Y-%m-%dT%H:%M:%S%z", lastmod)
135+
# the sitemap protocol expects W3C Datetime format, which uses
136+
# a colon between the hours and minutes of the time zone offset
137+
# https://www.sitemaps.org/protocol.html
138+
formatted_lastmod = (
139+
formatted_lastmod[:-2] + ":" + formatted_lastmod[-2:])
140+
item['lastmod'] = formatted_lastmod
135141
return item

0 commit comments

Comments
 (0)