From 46318a04b42a73a21c6426fd26e48ebe22af5a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=9A=D0=B0=D1=81=D0=B8?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Wed, 15 May 2019 19:13:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BA=D0=B0=D0=B7=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20lastmod=20=D0=B2=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B5=20si?= =?UTF-8?q?temap.xml=20[closes=20#24]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flatfilecms/templates/sitemap.jinja2 | 5 ++++- flatfilecms/views/__init__.py | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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')),