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

Fix sitemap generation #14481

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions bedrock/sitemaps/management/commands/update_sitemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from bedrock.sitemaps.utils import update_sitemaps


# Note that this command is only called by www-sitemap-generator, which uses the Docker image
# of Bedrock to regenerate sitemap data
class Command(BaseCommand):
args = ""
help = "Update XML sitemaps based on the list of localized pages."
Expand Down
9 changes: 9 additions & 0 deletions bedrock/sitemaps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ def get_static_urls():
for key, values in resolvers.get_resolver(None).reverse_dict.lists():
for value in values:
path = value[0][0][0]

# Re: https://github.com/mozilla/bedrock/issues/14480
# Since the refactor to use Django's i18n mechanism, not our
# original Prefixer, resolved URLs are automatically prepended
# with settings.LANGUAGE_CODE, which downstream use of this data
# is not expecting. The simplest fix is to drop that part of the path.
_lang_prefix = f"{settings.LANGUAGE_CODE}/"
path = path.replace(_lang_prefix, "", 1)

# Exclude pages that we don't want be indexed by search engines.
# Some other URLs are also unnecessary for the sitemap.
if any(exclude.search(path) for exclude in excludes):
Expand Down