Skip to content

Commit

Permalink
Fix sitemap generation (#14481)
Browse files Browse the repository at this point in the history
* Add comment to help future selves

* Stop automatically prepending the default language code on the URLs emitted in sitemap.json

...so that we don't break www-sitemap-generator when it then prepends various locales to the URLs

Fixes #14480
  • Loading branch information
stevejalim committed Apr 19, 2024
1 parent e6e5bd4 commit 64ce2a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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

0 comments on commit 64ce2a4

Please sign in to comment.