jdillard / sphinx-sitemap

Sphinx extension to generate a multi-lingual, multi-version sitemap for HTML builds
https://sphinx-sitemap.readthedocs.io/en/latest/index.html
MIT License
55 stars 21 forks source link

Add configuration option `sitemap_lastmod` #94

Open berhoel opened 2 months ago

berhoel commented 2 months ago

I added a configuration option to generate lastmod entries for the urls.

The Option can either be set to True (current date is used) or a string with the desired lastmod date.

I introduced another small patch in adding {posargs} to the pytest call in tox.ini, which allows specifying additional command line options for the pytest call when starting tox .

jdillard commented 2 months ago

Thanks!

The Option can either be set to True (current date is used) or a string with the desired lastmod date.

I'm not the biggest fan of having a variable be multiple types. What do you think of making the user configure their conf.py as something like:

sitemap_lastmod = "2024-08-13"
# or
import datetime
sitemap_lastmod = f"{datetime.datetime.now():%Y-%m-%d}"
berhoel commented 2 months ago

Fair enough, I modified the pull request accordingly.

jdillard commented 2 months ago

Hrm, I'm kind of torn on this implementation. I looked up "best practices" for lastmod and found some information on how it should be used:

Note that the date must be set to the date the linked page was last modified, not when the sitemap is generated.

Source: https://www.sitemaps.org/protocol.html

As well as potential consequences for misusing it:

Google appears to store "last significant update" time/date in epoch format for URLs. You can supply lastmod in XML sitemap. Google has boolean on whether to trust you or not based on whether you're a naughty liar

Source: https://www.seroundtable.com/google-sitemap-lastmod-binary-trust-37554.html

I'm not sure I want to promote a method that has the potential to lose trust with search engines. This was why I would prefer to use Git information to determine the last modified date for each page: https://github.com/jdillard/sphinx-sitemap/issues/3