Указание lastmod в файле sitemap.xml [closes #24]

master
Антон Касимов 2019-05-15 19:13:37 +03:00
parent c467375bec
commit 46318a04b4
2 changed files with 11 additions and 2 deletions

View File

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{%- for item in pages %}
{%- for item, lastmod in pages %}
<url>
<loc>{{data.base_url}}/{{item}}</loc>
{%- if lastmod %}
<lastmod>{{lastmod}}</lastmod>
{%- endif %}
</url>
{%- endfor %}
</urlset>

View File

@ -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')),