Added get_sitemap_urls method to page and use it in sitemaps

This commit is contained in:
Karl Hobley 2014-06-23 14:08:42 +01:00
parent d0fefc5f97
commit d76c8613fb
2 changed files with 22 additions and 7 deletions

View file

@ -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, {

View file

@ -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():