diff --git a/flatfilecms/templates/sitemap.jinja2 b/flatfilecms/templates/sitemap.jinja2 index 26510da..02b5ddd 100644 --- a/flatfilecms/templates/sitemap.jinja2 +++ b/flatfilecms/templates/sitemap.jinja2 @@ -1,8 +1,11 @@ - {%- for item in pages %} + {%- for item, lastmod in pages %} {{data.base_url}}/{{item}} + {%- if lastmod %} + {{lastmod}} + {%- endif %} {%- endfor %} diff --git a/flatfilecms/views/__init__.py b/flatfilecms/views/__init__.py index 53124d5..a051d61 100644 --- a/flatfilecms/views/__init__.py +++ b/flatfilecms/views/__init__.py @@ -53,7 +53,13 @@ def sitemap(self, options={}): for name, item in root.walk(): if not isinstance(item, Folder) and name != 'sitemap.xml' and not next( (True for r in ignore if r.match(name)), False): - post['pages'].append(name) + lastmod = None + if isinstance(item, + (YAML, Markdown)) and ('published' in item.page + or 'updated' in item.page): + lastmod = (item.page.get('updated') + or item.page.get('published')).strftime('%Y-%m-%d') + post['pages'].append((name, lastmod)) set_content_type(self, 'text/xml') return render_to_response( '{0}.jinja2'.format(post.get('template', 'sitemap')),