blob: 23008af665914af63c811dabd54a06ed5844020d [file] [log] [blame]
Rushabh Mehtaa494b882012-12-07 12:44:45 +05301# Copyright (c) 2012 Web Notes Technologies Pvt Ltd.
2# License: GNU General Public License (v3). For more information see license.txt
3
4from __future__ import unicode_literals
5frame_xml = """<?xml version="1.0" encoding="UTF-8"?>
6<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">%s
7</urlset>"""
8
9link_xml = """\n<url><loc>%s</loc><lastmod>%s</lastmod></url>"""
10
11# generate the sitemap XML
12def generate(domain):
13 global frame_xml, link_xml
14 import urllib, os
15 import webnotes
16 import website.utils
17
18 # settings
19 max_doctypes = 10
20 max_items = 1000
21
22 site_map = ''
23 page_list = []
24
25 if domain:
26 # list of all pages in web cache
27 for doctype in website.utils.page_map:
28 d = website.utils.page_map[doctype];
29 pages = webnotes.conn.sql("""select page_name, `modified`
30 from `tab%s` where ifnull(%s,0)=1
31 order by modified desc""" % (doctype, d.condition_field))
32
33 for p in pages:
34 page_url = os.path.join(domain, urllib.quote(p[0]) + '.html')
35 modified = p[1].strftime('%Y-%m-%d')
36 site_map += link_xml % (page_url, modified)
37
38 return frame_xml % site_map