Include last modified date in sitemap

This commit is contained in:
Magnus Hagander
2012-01-14 16:55:53 +01:00
parent ad895a7661
commit 78ab264578
4 changed files with 16 additions and 10 deletions

View File

@ -12,7 +12,7 @@ class Version(PgModel, models.Model):
relnotes = models.CharField(max_length=32, null=False, blank=False)
current = models.BooleanField(null=False, blank=False, default=False)
supported = models.BooleanField(null=False, blank=False, default=True)
docsloaded = models.DateTimeField(null=True, blank=True, help_text="The timestamp of the latest docs load. Really only used for developer docs for now, but set for all of them.")
docsloaded = models.DateTimeField(null=True, blank=True, help_text="The timestamp of the latest docs load. Used to control indexing and info on developer docs.")
firstreldate = models.DateField(null=False, blank=False, help_text="The date of the .0 release in this tree")
eoldate = models.DateField(null=False, blank=False, help_text="The planned EOL date for this tree")

View File

@ -138,8 +138,10 @@ def sitemap(request):
pages+=1
x.startElement('url', {})
x.add_xml_element('loc', 'http://www.postgresql.org/%s' % urllib.quote(p[0]))
if p[1]:
if len(p) > 1 and p[1]:
x.add_xml_element('priority', unicode(p[1]))
if len(p) > 2 and p[2]:
x.add_xml_element('lastmod', p[2].isoformat() + "Z")
x.endElement('url')
x.endElement('urlset')
x.endDocument()

View File

@ -1,16 +1,20 @@
from datetime import date
from models import DocPage
from django.db import connection
from core.models import Version
def get_struct():
now = date.today()
currentversion = Version.objects.get(current=True)
for d in DocPage.objects.all().extra(where=['version in (select tree from core_version where supported)']):
yield ('docs/%s/static/%s' % (d.version, d.file),
None)
# Can't use a model here, because we don't (for some reason) have a
# hard link to the versions table here
curs = connection.cursor()
curs.execute("SELECT d.version, d.file, v.docsloaded FROM docs d INNER JOIN core_version v ON v.tree=d.version WHERE v.supported")
for version, filename, loaded in curs.fetchall():
yield ('docs/%s/static/%s' % (version, filename),
None, loaded)
#FIXME ^ do something smart with priorities on older
#versions
if d.version == currentversion.tree:
yield ('docs/current/static/%s' % d.file,
1.0)
if version == currentversion.tree:
yield ('docs/current/static/%s' % filename,
1.0, loaded)

View File

@ -4,7 +4,7 @@ def get_all_pages_struct():
"""
Return an iterator over all distinct pages on the site.
Each page is returned as a tuple consisting of:
(url, search weight)
(url, search weight, last_modified)
It will do so by looking for the module "struct" in all
installed applications, and calling the get_struct() function