You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by di...@apache.org on 2021/03/11 23:30:21 UTC

[allura] 01/01: added new app.sitemap_xml() that is used when generating sitemap.xml

This is an automated email from the ASF dual-hosted git repository.

dill0wn pushed a commit to branch dw/wiki_nofollow_sitemap
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 1c755315e757b36b9dfc3b113d0476182f93c732
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Thu Mar 11 18:14:19 2021 -0500

    added new app.sitemap_xml() that is used when generating sitemap.xml
---
 Allura/allura/app.py                          |  9 +++++++++
 Allura/allura/model/project.py                | 12 ++++++++++--
 Allura/allura/scripts/create_sitemap_files.py |  2 +-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index fb59e52..fdd1fca 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -595,6 +595,15 @@ class Application(object):
             sitemap_without_children.append(sm_copy)
         return sitemap_without_children
 
+    def sitemap_xml(self):
+        """Return a list of :class:`SitemapEntries <allura.app.SitemapEntry>`
+        to add to the sitemap.xml for this Application.
+
+        Default implementation returns the contents of :attr:`main_menu`
+        :return:
+        """
+        return self.main_menu()
+
     def sidebar_menu(self):
         """Return a list of :class:`SitemapEntries <allura.app.SitemapEntry>`
         to render in the left sidebar for this Application.
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 5819a8f..1ce3e9d 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -524,7 +524,7 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
         return result
 
     def sitemap(self, excluded_tools=None, included_tools=None,
-            tools_only=False, per_tool_limit=SITEMAP_PER_TOOL_LIMIT):
+            tools_only=False, per_tool_limit=SITEMAP_PER_TOOL_LIMIT, xml=False):
         """
         Return the project sitemap.
 
@@ -542,6 +542,10 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
             Max number of entries included in the sitemap for a single tool
             type. Use `None` to include all.
 
+        :param bool xml:
+            If True, return sitemap entries for use in the sitemap.xml
+            instead of site navigation.
+
         """
         from allura.app import SitemapEntry
         entries = []
@@ -596,7 +600,11 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
             else:
                 app = App(self, ac)
             if app.is_visible_to(c.user):
-                for sm in app.main_menu():
+                if xml:
+                    sms = app.sitemap_xml()
+                else:
+                    sms = app.main_menu()
+                for sm in sms:
                     entry = sm.bind_app(app)
                     entry.tool_name = ac.tool_name
                     entry.ui_icon = 'tool-%s' % entry.tool_name.lower()
diff --git a/Allura/allura/scripts/create_sitemap_files.py b/Allura/allura/scripts/create_sitemap_files.py
index 1eaeb07..d99914d 100644
--- a/Allura/allura/scripts/create_sitemap_files.py
+++ b/Allura/allura/scripts/create_sitemap_files.py
@@ -116,7 +116,7 @@ class CreateSitemapFiles(ScriptTask):
             for p in chunk:
                 c.project = p
                 try:
-                    for s in p.sitemap(excluded_tools=options.exclude_tools):
+                    for s in p.sitemap(excluded_tools=options.exclude_tools, xml=True):
                         url = config['base_url'] + s.url if s.url[0] == '/' else s.url
                         locs.append({'url': url,
                                      'date': p.last_updated.strftime("%Y-%m-%d")})