Changeset 23


Ignore:
Timestamp:
11/10/06 20:54:20 (5 years ago)
Author:
harald
Message:
  • Add Google Sitemaps confirmation page option
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sitemap-plugin/trunk/sitemap/api.py

    r19 r23  
    7777    contributors = ExtensionPoint(ISitemapContributor) 
    7878     
     79    confirmationpage = Option('sitemap', 'confirmationpage', '', 
     80       """Name of the Google Sitemaps confirmation page (e.g. googleeb3689b3689b3689.html).""") 
     81     
    7982    path = '/sitemap.xml' 
    8083     
     
    102105    def match_request(self, req): 
    103106        """Return whether the handler wants to process the given request.""" 
    104         return req.path_info == self.path 
     107        return req.path_info == self.path or (len (self.confirmationpage) > 0 and req.path_info == self.confirmationpage) 
    105108 
    106109    def process_request(self, req): 
     
    108111        simply send the response itself and not return anything. 
    109112        """ 
    110         doc = Document() 
    111         urlset = doc.createElement("urlset") 
    112         a = doc.createAttribute('xmlns') 
    113         a.value = self.ns 
    114         urlset.setAttributeNode(a) 
    115         for c in self.contributors: 
    116             for ressource_data in c.get_data(req): 
    117                 urlset.appendChild(ressource_data.to_node(doc)) 
     113        if req.path_info == self.confirmationpage: 
     114                req.send_response(200) 
     115            req.send_header('Content-Type', 'text/plain') 
     116            req.end_headers() 
     117            req.write('Hello Google!') 
     118             
     119        else: 
     120            doc = Document() 
     121            urlset = doc.createElement("urlset") 
     122            a = doc.createAttribute('xmlns') 
     123            a.value = self.ns 
     124            urlset.setAttributeNode(a) 
     125            for c in self.contributors: 
     126                for ressource_data in c.get_data(req): 
     127                    urlset.appendChild(ressource_data.to_node(doc)) 
    118128 
    119         doc.appendChild(urlset) 
    120         req.send_response(200) 
    121         req.send_header('Content-Type', 'text/xml;charset=UTF-8') 
    122         req.end_headers() 
     129            doc.appendChild(urlset) 
     130            req.send_response(200) 
     131            req.send_header('Content-Type', 'text/xml;charset=UTF-8') 
     132            req.end_headers() 
    123133 
    124         req.write(doc.toxml('UTF-8')) 
     134            req.write(doc.toxml('UTF-8')) 
    125135         
    126136    def send_ping(self): 
Note: See TracChangeset for help on using the changeset viewer.