Rushabh Mehta | a494b88 | 2012-12-07 12:44:45 +0530 | [diff] [blame] | 1 | # Copyright (c) 2012 Web Notes Technologies Pvt Ltd. |
| 2 | # License: GNU General Public License (v3). For more information see license.txt |
| 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | frame_xml = """<?xml version="1.0" encoding="UTF-8"?> |
| 6 | <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">%s |
| 7 | </urlset>""" |
| 8 | |
| 9 | link_xml = """\n<url><loc>%s</loc><lastmod>%s</lastmod></url>""" |
| 10 | |
| 11 | # generate the sitemap XML |
| 12 | def 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: |
Rushabh Mehta | 5f18398 | 2013-01-01 10:55:58 +0530 | [diff] [blame] | 34 | page_url = os.path.join(domain, urllib.quote(p[0])) |
Rushabh Mehta | a494b88 | 2012-12-07 12:44:45 +0530 | [diff] [blame] | 35 | modified = p[1].strftime('%Y-%m-%d') |
| 36 | site_map += link_xml % (page_url, modified) |
| 37 | |
| 38 | return frame_xml % site_map |