From d76c8613fb77683dfdffd74e2cafd4eda4a242ad Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Mon, 23 Jun 2014 14:08:42 +0100 Subject: [PATCH] Added get_sitemap_urls method to page and use it in sitemaps --- .../wagtailsitemaps/sitemap_generator.py | 8 ++----- wagtail/wagtailcore/models.py | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/wagtail/contrib/wagtailsitemaps/sitemap_generator.py b/wagtail/contrib/wagtailsitemaps/sitemap_generator.py index 53b5dd664..eb08d81b7 100644 --- a/wagtail/contrib/wagtailsitemaps/sitemap_generator.py +++ b/wagtail/contrib/wagtailsitemaps/sitemap_generator.py @@ -12,12 +12,8 @@ class Sitemap(object): def get_urls(self): for page in self.get_pages(): - latest_revision = page.get_latest_revision() - - yield { - 'location': page.url, - 'lastmod': latest_revision.created_at if latest_revision else None - } + for url in page.get_sitemap_urls(): + yield url def render(self): return render_to_string(self.template, { diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py index 1f0c98d83..c1e48750b 100644 --- a/wagtail/wagtailcore/models.py +++ b/wagtail/wagtailcore/models.py @@ -623,13 +623,32 @@ class Page(MP_Node, ClusterableModel, Indexed): """ return self.serve(self.dummy_request()) + def get_internal_paths(self): + """ + This returns a list of paths within this page. + This is used for static sites, sitemaps and cache invalidation. + """ + return ['/'] + + def get_sitemap_urls(self): + latest_revision = self.get_latest_revision() + + return [ + { + 'location': self.url + url[1:], + 'lastmod': latest_revision.created_at if latest_revision else None + } + for url in self.get_internal_paths() + ] + def get_static_site_paths(self): """ This is a generator of URL paths to feed into a static site generator Override this if you would like to create static versions of subpages """ # Yield paths for this page - yield '/' + for url in self.get_internal_paths(): + yield url # Yield paths for child pages for child in self.get_children().live():