
import classes.module

class Module(classes.module.Module):
    sitemap = []
    
    def __init__(self, builder):
        sitemap =[{
            'url': '',
          'priority': '1.0',
        }, {
            'url': 'images/',
            'priority': '0.8',
        }]

    def interpret(self, page, builder):
        mapurl = {
            'url': 'images/' + page.src_path[2:] + '/',
            'priority': '0.5',
        }
        if page.src_path.count('/') == 1:
            mapurl['priority'] = '0.7'

        if mapurl['url'] != 'images//' and mapurl['url'] != 'images/not-found/' and mapurl['url'] != 'images/removed/':
            self.sitemap.append(mapurl)

    def render(self, builder):
        sitemap = '<?xml version="1.0" encoding="UTF-8"?>'+"\n"
        sitemap += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'+"\n"
        for url in self.sitemap:
            sitemap += "\t<url>\n"
            sitemap += "\t\t<loc>"+builder.config['url']+url['url']+"</loc>\n"
            sitemap += "\t\t<priority>"+url['priority']+"</priority>\n"
            sitemap += "\t</url>\n"
        sitemap += '</urlset>'
        file = open(builder.dist + '/../sitemap.xml', 'w')
        file.write(sitemap)
        file.close()


@@ -1,8 +1,27 @@
+%0Aimport collections
 %0Aimport 
@@ -73,16 +73,17 @@
 odule):%0A
+%0A
     site
@@ -92,10 +92,12 @@
 p = 
-%5B%5D
+None
 %0A   
@@ -110,21 +110,28 @@
 def 
-__init__(self
+interpret(self, page
 , bu
@@ -138,32 +138,40 @@
 ilder):%0A        
+if self.
 sitemap =%5B%7B%0A    
@@ -167,10 +167,15 @@
 ap =
-%5B%7B
+= None:
 %0A   
@@ -187,490 +187,799 @@
     
-'url': '',%0A          'priority': '1.0',%0A        %7D, %7B%0A            'url': 'images/',%0A            'priority': '0.8',%0A        %7D%5D%0A%0A    def interpret(self, page, builder):%0A        
+self.sitemap = collections.OrderedDict()%0A            for url in builder.config.get('sitemap_overrides', %5B%5D):%0A                if url%5B'loc'%5D is None:%0A                    url%5B'loc'%5D = '/'%0A                self.site
 map
+%5B
 url
- = %7B%0A            'url': 'images/' + page.src_path%5B2:%5D + '/',%0A            'priority': '0.5',%0A        %7D%0A        if page.src_path.count('/') == 1:%0A            mapurl%5B'priority'%5D = '0.7'%0A%0A        if mapurl%5B'url'%5D != 'images//' and mapurl%5B'url'%5D != 'images/not-found/'
+%5B'loc'%5D%5D = url%0A%0A        sitemap_path = page.src_path%5B2:%5D%0A        if len(sitemap_path) %3E 0:%0A            sitemap_path += '/'%0A        if page.src_path.count('/') == 1:%0A            priority = builder.config.get('sitemap_priority_toplevel', '0.7')%0A        else:%0A            priority = builder.config.get('sitemap_priority_default', '0.5')%0A        url = %7B%0A            'loc': builder.config.get('path', '/') + sitemap_path,%0A            'priority': priority,%0A        %7D%0A        %0A        if url%5B'loc'%5D not in self.sitemap
  and 
-map
 url%5B'
-url'%5D != 'images/removed/'
+loc'%5D not in builder.config.get('sitemap_ignore', %5B%5D)
 :%0A  
@@ -1004,23 +1004,26 @@
 emap
-.append(map
+%5Burl%5B'loc'%5D%5D = 
 url
-)
 %0A%0A  
@@ -1214,31 +1214,179 @@
     
-for url in self.sitemap
+if hasattr(self.sitemap, 'iteritems'):%0A            values = self.sitemap.iteritems()%0A        else:%0A            values = self.sitemap.items()%0A        for loc, url in values
 :%0A  
@@ -1480,20 +1480,24 @@
 '%5D+url%5B'
-url'
+loc'%5D%5B1:
 %5D+%22%3C/loc
@@ -1541,16 +1541,20 @@
 ority%3E%22+
+str(
 url%5B'pri
@@ -1560,16 +1560,17 @@
 iority'%5D
+)
 +%22%3C/prio

move application specific code from sitemap module to config