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

[allura] branch master updated (c690455 -> 8fbeb78)

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

brondsem pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git.


    from c690455  Avoid error on incorrect url
     new cc183b6  added new app.sitemap_xml() that is used when generating sitemap.xml
     new 8fbeb78  wiki pages with noindex are omitted from sitemap.xml

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Allura/allura/app.py                               |  9 +++++++++
 Allura/allura/model/project.py                     | 12 +++++++++--
 Allura/allura/scripts/create_sitemap_files.py      |  2 +-
 .../tests/scripts/test_create_sitemap_files.py     |  4 ++--
 ForgeWiki/forgewiki/wiki_main.py                   | 23 +++++++++++++++++++---
 5 files changed, 42 insertions(+), 8 deletions(-)


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

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit cc183b6c9f8708ce98e67ec967267860fcb28ded
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")})


[allura] 02/02: wiki pages with noindex are omitted from sitemap.xml

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 8fbeb7890bae82f5b3d4c15a87b856648b8686cb
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Fri Mar 12 13:23:32 2021 -0500

    wiki pages with noindex are omitted from sitemap.xml
---
 .../tests/scripts/test_create_sitemap_files.py     |  4 ++--
 ForgeWiki/forgewiki/wiki_main.py                   | 23 +++++++++++++++++++---
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/Allura/allura/tests/scripts/test_create_sitemap_files.py b/Allura/allura/tests/scripts/test_create_sitemap_files.py
index 3852f82..ce70610 100644
--- a/Allura/allura/tests/scripts/test_create_sitemap_files.py
+++ b/Allura/allura/tests/scripts/test_create_sitemap_files.py
@@ -22,7 +22,7 @@ from shutil import rmtree
 import xml.etree.ElementTree as ET
 
 from tg import tmpl_context as c
-from nose.tools import assert_in
+from nose.tools import assert_in, assert_not_in
 from testfixtures import TempDirectory
 
 from alluratest.controller import setup_basic_test
@@ -56,5 +56,5 @@ class TestCreateSitemapFiles(object):
 
             xml_0 = ET.parse(os.path.join(tmpdir.path, 'sitemap-0.xml'))
             urls = [loc.text for loc in xml_0.findall('ns0:url/ns0:loc', ns)]
-            assert_in('http://localhost/p/wiki/', urls)
+            assert_not_in('http://localhost/p/wiki/', urls)  # blank wiki pages omitted from sitemap
             assert_in('http://localhost/p/test/sub1/', urls)
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index f150305..4d47311 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -208,13 +208,25 @@ The wiki uses [Markdown](%s) syntax.
         self.config.options['AllowEmailPosting'] = bool(show)
 
     def main_menu(self):
-        '''Apps should provide their entries to be added to the main nav
+        """Apps should provide their entries to be added to the main nav
         :return: a list of :class:`SitemapEntries <allura.app.SitemapEntry>`
-        '''
+        """
         return [SitemapEntry(
             self.config.options.mount_label,
             '.')]
 
+    def sitemap_xml(self):
+        """
+        Used for generating sitemap.xml.
+        If the root page has default content, omit it from the sitemap.xml.
+        Assumes :attr:`main_menu` will return an entry pointing to the root page.
+        :return: a list of :class:`SitemapEntries <allura.app.SitemapEntry>`
+        """
+        root_page = WM.Page.query.get(app_config_id=self.config._id, title=self.root_page_name)
+        if self.should_noindex_page(root_page):
+            return []
+        return self.main_menu()
+
     @property
     @h.exceptionless([], log)
     def sitemap(self):
@@ -228,6 +240,11 @@ The wiki uses [Markdown](%s) syntax.
             return [
                 SitemapEntry(menu_id, '.')[SitemapEntry('Pages')[pages]]]
 
+    def should_noindex_page(self, page):
+        """Checks whether a page should not be indexed."""
+        # If page has default name (i.e. 'Home') and has not been edited, noindex.
+        return page and page['title'] == self.default_root_page_name and page['version'] == 1
+
     def create_common_wiki_menu(self, has_create_access, admin_menu=False):
         links = []
         if has_create_access:
@@ -604,7 +621,7 @@ class PageController(BaseController, FeedController):
             page_subscribed=subscribed_to_page,
             hide_left_bar=hide_left_bar, show_meta=c.app.show_right_bar,
             pagenum=pagenum, limit=limit, count=post_count,
-            noindex=True if page['title'] == 'Home' and page['version'] == 1 else False)
+            noindex=c.app.should_noindex_page(self.page))
 
     @without_trailing_slash
     @expose('jinja:forgewiki:templates/wiki/page_edit.html')