def get_static_urls()

in bedrock/sitemaps/utils.py [0:0]


def get_static_urls():
    urls = {}
    client = Client()
    excludes = [
        re.compile(r)
        for r in settings.NOINDEX_URLS
        + [
            r".*%\(.*\).*",
            r".*//$",
            r"^media/",
            r"^robots\.txt$",
            # Redirects in en-US. Added via EXTRA_INDEX_URLS
            r"firefox-klar/$",
        ]
    ]

    # start with the ones we know we want
    urls.update(settings.EXTRA_INDEX_URLS)

    # get_resolver is an undocumented but convenient function.
    # Try to retrieve all valid URLs on this site.
    # NOTE: have to use `lists()` here since the standard
    # `items()` only returns the first item in the list for the
    # view since `reverse_dict` is a `MultiValueDict`.
    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):
                continue

            path_prefix = path.split("/", 2)[0]
            nonlocale = path_prefix in settings.SUPPORTED_NONLOCALES
            path = f"/{path}"
            if nonlocale:
                locales = []
            else:
                with patch("lib.l10n_utils.django_render") as render:
                    render.return_value = HttpResponse()
                    client.get("/" + settings.LANGUAGE_CODE + path)

                # Exclude urls that did not call render
                if not render.called:
                    continue

                locales = set(render.call_args[0][2]["translations"].keys())

                # Firefox Focus has a different URL in German
                if path == "/privacy/firefox-focus/":
                    locales -= {"de"}

                # just remove any locales not in our prod list
                locales = list(locales.intersection(settings.PROD_LANGUAGES))

            if path not in urls:
                urls[path] = locales

    return urls