Указание lastmod в файле sitemap.xml [closes #24]
parent
c467375bec
commit
46318a04b4
|
@ -1,8 +1,11 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
{%- for item in pages %}
|
{%- for item, lastmod in pages %}
|
||||||
<url>
|
<url>
|
||||||
<loc>{{data.base_url}}/{{item}}</loc>
|
<loc>{{data.base_url}}/{{item}}</loc>
|
||||||
|
{%- if lastmod %}
|
||||||
|
<lastmod>{{lastmod}}</lastmod>
|
||||||
|
{%- endif %}
|
||||||
</url>
|
</url>
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
</urlset>
|
</urlset>
|
||||||
|
|
|
@ -53,7 +53,13 @@ def sitemap(self, options={}):
|
||||||
for name, item in root.walk():
|
for name, item in root.walk():
|
||||||
if not isinstance(item, Folder) and name != 'sitemap.xml' and not next(
|
if not isinstance(item, Folder) and name != 'sitemap.xml' and not next(
|
||||||
(True for r in ignore if r.match(name)), False):
|
(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')
|
set_content_type(self, 'text/xml')
|
||||||
return render_to_response(
|
return render_to_response(
|
||||||
'{0}.jinja2'.format(post.get('template', 'sitemap')),
|
'{0}.jinja2'.format(post.get('template', 'sitemap')),
|
||||||
|
|
Reference in New Issue