2012-12-07 07:14:45 +00:00
|
|
|
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd.
|
|
|
|
# License: GNU General Public License (v3). For more information see license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
2013-05-22 10:21:47 +00:00
|
|
|
|
2012-12-07 07:14:45 +00:00
|
|
|
frame_xml = """<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">%s
|
|
|
|
</urlset>"""
|
|
|
|
|
|
|
|
link_xml = """\n<url><loc>%s</loc><lastmod>%s</lastmod></url>"""
|
|
|
|
|
|
|
|
# generate the sitemap XML
|
|
|
|
def generate(domain):
|
|
|
|
global frame_xml, link_xml
|
|
|
|
import urllib, os
|
|
|
|
import webnotes
|
2013-04-02 05:11:37 +00:00
|
|
|
import webnotes.webutils
|
2013-04-16 15:27:09 +00:00
|
|
|
from webnotes.utils import nowdate
|
2012-12-07 07:14:45 +00:00
|
|
|
|
|
|
|
# settings
|
|
|
|
max_items = 1000
|
2013-04-16 15:27:09 +00:00
|
|
|
count = 0
|
2012-12-07 07:14:45 +00:00
|
|
|
|
|
|
|
site_map = ''
|
|
|
|
if domain:
|
2013-04-16 15:27:09 +00:00
|
|
|
today = nowdate()
|
|
|
|
|
|
|
|
# generated pages
|
|
|
|
for doctype, opts in webnotes.webutils.get_generators().items():
|
2012-12-07 07:14:45 +00:00
|
|
|
pages = webnotes.conn.sql("""select page_name, `modified`
|
|
|
|
from `tab%s` where ifnull(%s,0)=1
|
2013-04-16 15:27:09 +00:00
|
|
|
order by modified desc""" % (doctype, opts.get("condition_field")))
|
2012-12-07 07:14:45 +00:00
|
|
|
|
|
|
|
for p in pages:
|
2013-04-16 15:27:09 +00:00
|
|
|
if count >= max_items: break
|
2013-05-22 10:21:47 +00:00
|
|
|
if p[0]:
|
|
|
|
page_url = os.path.join(domain, urllib.quote(p[0]))
|
|
|
|
modified = p[1].strftime('%Y-%m-%d')
|
|
|
|
site_map += link_xml % (page_url, modified)
|
|
|
|
count += 1
|
2013-04-16 15:27:09 +00:00
|
|
|
|
|
|
|
if count >= max_items: break
|
|
|
|
|
|
|
|
# standard pages
|
|
|
|
for page, opts in webnotes.get_config()["web"]["pages"].items():
|
|
|
|
if "no_cache" in opts:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if count >= max_items: break
|
|
|
|
page_url = os.path.join(domain, urllib.quote(page))
|
|
|
|
modified = today
|
|
|
|
site_map += link_xml % (page_url, modified)
|
|
|
|
count += 1
|
2012-12-07 07:14:45 +00:00
|
|
|
|
2013-04-16 15:27:09 +00:00
|
|
|
return frame_xml % site_map
|