浏览代码

Ability to exclude URLs from a sitemap

Adds the ability to exclude a URL for being added to a sitemap (very common need).
Alex Leventer 10 年之前
父节点
当前提交
e3d7a603fc
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      sitemap/sitemap.py

+ 5 - 1
sitemap/sitemap.py

@@ -161,9 +161,13 @@ class SitemapGenerator(object):
             chfreq = self.changefreqs['indexes']
 
         pageurl = '' if page.url == 'index.html' else page.url
+        
+        #Exclude URLs from the sitemap:
+        sitemapExclude = []
 
         if self.format == 'xml':
-            fd.write(XML_URL.format(self.siteurl, pageurl, lastmod, chfreq, pri))
+            if pageurl not in sitemapExclude:
+                fd.write(XML_URL.format(self.siteurl, pageurl, lastmod, chfreq, pri))
         else:
             fd.write(self.siteurl + '/' + pageurl + '\n')