Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

56 linhas
1.4 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. frame_xml = """<?xml version="1.0" encoding="UTF-8"?>
  5. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">%s
  6. </urlset>"""
  7. link_xml = """\n<url><loc>%s</loc><lastmod>%s</lastmod></url>"""
  8. # generate the sitemap XML
  9. def generate(domain):
  10. global frame_xml, link_xml
  11. import urllib, os
  12. import webnotes
  13. import webnotes.webutils
  14. from webnotes.utils import nowdate
  15. # settings
  16. max_items = 1000
  17. count = 0
  18. site_map = ''
  19. if domain:
  20. today = nowdate()
  21. # generated pages
  22. for doctype, opts in webnotes.webutils.get_generators().items():
  23. pages = webnotes.conn.sql("""select page_name, `modified`
  24. from `tab%s` where ifnull(%s,0)=1
  25. order by modified desc""" % (doctype, opts.get("condition_field")))
  26. for p in pages:
  27. if count >= max_items: break
  28. if p[0]:
  29. page_url = os.path.join(domain, urllib.quote(p[0]))
  30. modified = p[1].strftime('%Y-%m-%d')
  31. site_map += link_xml % (page_url, modified)
  32. count += 1
  33. if count >= max_items: break
  34. # standard pages
  35. for page, opts in webnotes.get_config()["web"]["pages"].items():
  36. if "no_cache" in opts:
  37. continue
  38. if count >= max_items: break
  39. page_url = os.path.join(domain, urllib.quote(page))
  40. modified = today
  41. site_map += link_xml % (page_url, modified)
  42. count += 1
  43. return frame_xml % site_map