Specify site_url
in MkDocs configuration for correct sitemap
#1054
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1053.
To correctly generate the
sitemap.xml
, thesite_url
must be specified inmkdocs.yml
.Having a valid sitemap can help search engines index a site's content.
What I've done here is to make
site_url
switchable depending on an environment variable,MKDOCS_SITE_URL
and then simply set that on build. As this is only really required for deployment, I've just put this in the deployment workflow, instead of adding some wrapper or to do the build with the environment variable supplied.This keeps the local development setup exactly as it was, with no value set for
site_url
.I'm reasonably convinced that this is the right approach because:
site_url
mkdocs serve
, the site URL is ignored anyway!)https://docs.opensafely.org/some-path…
even for Cloudflare test deployments, technically, should a search engine somehow stumble upon those pages