You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by gc...@apache.org on 2022/04/04 16:48:46 UTC
[allura] 02/02: [#8421] SEO - omit /blogs/ from sitemap if no posts
This is an automated email from the ASF dual-hosted git repository.
gcruz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit bf6afe1190f72dc4dda24f0d656018175d8219a6
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Wed Mar 23 00:32:04 2022 +0000
[#8421] SEO - omit /blogs/ from sitemap if no posts
---
ForgeBlog/forgeblog/main.py | 20 ++++++++++++++++++++
ForgeBlog/forgeblog/tests/test_app.py | 23 +++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/ForgeBlog/forgeblog/main.py b/ForgeBlog/forgeblog/main.py
index 417c669a2..40d474fef 100644
--- a/ForgeBlog/forgeblog/main.py
+++ b/ForgeBlog/forgeblog/main.py
@@ -155,6 +155,26 @@ class ForgeBlogApp(Application):
return [
SitemapEntry(menu_id, '.')[self.sidebar_menu()]]
+ 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>`
+ """
+ if self.should_noindex():
+ return []
+ return self.main_menu()
+
+ def should_noindex(self):
+ post = BM.BlogPost.query.get(
+ app_config_id=self.config._id,
+ state='published',
+ deleted=False)
+ if post:
+ return False
+ return True
+
@property
def show_discussion(self):
if 'show_discussion' in self.config.options:
diff --git a/ForgeBlog/forgeblog/tests/test_app.py b/ForgeBlog/forgeblog/tests/test_app.py
index a1b706af5..98cc59fda 100644
--- a/ForgeBlog/forgeblog/tests/test_app.py
+++ b/ForgeBlog/forgeblog/tests/test_app.py
@@ -49,6 +49,29 @@ class TestApp:
c.project.uninstall_app('blog')
assert not BM.BlogPost.query.get(title='Test title')
+ @td.with_tool('test', 'Blog', 'blog')
+ def test_sitemap_xml(self):
+ assert_equal([], c.app.sitemap_xml())
+ BM.BlogPost.new(
+ title='Blog Title',
+ state='draft',
+ text='This is my first blog Post',
+ )
+ assert_equal([], c.app.sitemap_xml())
+ BM.BlogPost.new(
+ title='Blog Title',
+ state='published',
+ text='This is my first blog Post',
+ deleted=True
+ )
+ assert_equal([], c.app.sitemap_xml())
+ BM.BlogPost.new(
+ title='Blog Title',
+ state='published',
+ text='This is my first blog Post',
+ )
+ assert_equal(1, len(c.app.sitemap_xml()))
+
class TestBulkExport: