Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: Enrico Tröger enrico.troeger@uvena.de Date: Sun, 30 Jun 2019 12:46:03 UTC Commit: 3b62baf048984a1bf60549470c360403f9283a52 https://github.com/geany/www.geany.org/commit/3b62baf048984a1bf60549470c3604...
Log Message: ----------- Exclude API or legacy URLs from /sitemap.xml
Those URLs cannot or should not be called directly and so also not indexed by search engines.
Modified Paths: -------------- geany/sitemaps.py latest_version/urls.py pastebin/urls.py
Modified: geany/sitemaps.py 24 lines changed, 16 insertions(+), 8 deletions(-) =================================================================== @@ -92,9 +92,10 @@ class StaticSitemap(sitemaps.Sitemap): priority = 0.5
# ---------------------------------------------------------------------- - def __init__(self, domain, patterns): + def __init__(self, domain, patterns, exclude_views=None): self._domain = domain self._patterns = patterns + self._exclude_views = exclude_views or list() self._site = None self._url_mapping = {} self._get_site() @@ -111,7 +112,8 @@ def get_static_items(self): # ---------------------------------------------------------------------- def _initialize(self): for pattern in self._patterns: - if getattr(pattern, 'name', None) is not None: + view_name = getattr(pattern, 'name', None) + if view_name is not None and view_name not in self._exclude_views: url_resolved = self._resolve_url(pattern.name) if url_resolved: self._url_mapping[pattern.name] = url_resolved @@ -153,11 +155,11 @@ def __init__(self): self._static_items = None
# ---------------------------------------------------------------------- - def add(self, generator_class, url_patterns, site_domain=None): + def add(self, generator_class, url_patterns, site_domain=None, exclude_views=None): if site_domain is None: site = Site.objects.get(id=settings.SITE_ID) site_domain = site.domain - sitemap_generator_item = (generator_class, url_patterns, site_domain) + sitemap_generator_item = (generator_class, url_patterns, site_domain, exclude_views) self._sitemap_generators.append(sitemap_generator_item)
# ---------------------------------------------------------------------- @@ -176,17 +178,23 @@ def get_all_items(self): # ---------------------------------------------------------------------- def _get_static_items(self): static_items = list() - for sitemap_generator_class, url_patterns, site_domain in self._sitemap_generators: - generator = sitemap_generator_class(site_domain, url_patterns) + for generator_class, url_patterns, site_domain, exclude_views in self._sitemap_generators: + generator = generator_class( + site_domain, + url_patterns, + exclude_views=exclude_views) items = generator.get_static_items() static_items.extend(items) return static_items
# ---------------------------------------------------------------------- def _get_dynamic_items(self): dynamic_items = list() - for sitemap_generator_class, url_patterns, site_domain in self._sitemap_generators: - generator = sitemap_generator_class(site_domain, url_patterns) + for generator_class, url_patterns, site_domain, exclude_views in self._sitemap_generators: + generator = generator_class( + site_domain, + url_patterns, + exclude_views=exclude_views) items = generator.get_dynamic_items() dynamic_items.extend(items) return dynamic_items
Modified: latest_version/urls.py 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -32,4 +32,4 @@ )
# register our urlpatterns to the global sitemap generator -sitemap_registry.add(StaticSitemap, urlpatterns) +sitemap_registry.add(StaticSitemap, urlpatterns, exclude_views=['latest_version_legacy'])
Modified: pastebin/urls.py 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -57,4 +57,4 @@
# Sitemap framework -sitemap_registry.add(StaticSitemap, urlpatterns) +sitemap_registry.add(StaticSitemap, urlpatterns, exclude_views=['snippet_api'])
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).