Pārlūkot izejas kodu

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 gadi atpakaļ
vecāks
revīzija
e3d7a603fc
1 mainītis faili ar 5 papildinājumiem un 1 dzēšanām
  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')