Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the generation date (Y-m-d) to the sitemap.xml #219

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/test_check_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_simple_single_sitemap_output():
in content
), "<sitemap> element is properly emitted"

assert "<!-- 5 urls -->" in content, "URLs counter is properly added"
assert "<!-- 5 urls in 1 sub-sitemaps -->" in content, "URLs counter is properly added"


def test_encode_urls():
Expand Down
8 changes: 6 additions & 2 deletions xml_sitemap_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import gzip # https://docs.python.org/3/library/gzip.html
import logging

from datetime import datetime

from typing import List, Iterator, IO
from xml.sax.saxutils import escape as escape_xml

Expand Down Expand Up @@ -192,12 +194,14 @@ def _write_index(self):
with open(f"{self.path}/sitemap.xml", mode="wt", encoding="utf-8") as index:
self.logger.info(f"Will write sitemaps index XML to {index.name}")

generated_at = datetime.now().strftime("%Y-%m-%d") # e.g. 2024-11-22
macbre marked this conversation as resolved.
Show resolved Hide resolved

index.writelines(
[
'<?xml version="1.0" encoding="UTF-8"?>\n',
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n',
f"\t<!-- Powered by {POWERED_BY_URL} -->\n",
f"\t<!-- {len(self)} urls -->\n",
f"\t<!-- Generated at {generated_at} by {POWERED_BY_URL} -->\n",
macbre marked this conversation as resolved.
Show resolved Hide resolved
f"\t<!-- {len(self)} urls in {len(self.sitemaps)} sub-sitemaps -->\n",
]
)

Expand Down
Loading