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 <[email protected]> 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')
