We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
sitemap.xml contains pages that don't exist
My settings.xml says:

```
AUTHOR_SAVE_AS = ''
```

in order to force pelican to not generate author pages.

When I include:

```
PLUGINS = [sitemap]
SITEMAP = {'format': 'xml'}
```

my sitemap.xml contains:

  <url>
    <loc>http://example.com/author/brian.html</loc>
    <lastmod>2012-10-07T19:42:14-00:00</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.5</priority>
  </url>

The referenced file does not exist in my output directory.

The same holds true for `/archives.html`, `/tags.html`, `/categories.html`, and `/category/*.html`.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pelican/plugins/sitemap.py`
Content:
```
1 import os.path
2 
3 from datetime import datetime
4 from logging import debug, warning, error, info
5 from codecs import open
6 
7 from pelican import signals, contents
8 
9 TXT_HEADER = u"""{0}/index.html
10 {0}/archives.html
11 {0}/tags.html
12 {0}/categories.html
13 """
14 
15 XML_HEADER = u"""<?xml version="1.0" encoding="utf-8"?>
16 <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17          xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
18          xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
19 
20   <url>
21     <loc>{0}/index.html</loc>
22     <lastmod>{1}</lastmod>
23     <changefreq>{2}</changefreq>
24     <priority>{3}</priority>
25   </url>
26 
27   <url>
28     <loc>{0}/archives.html</loc>
29     <lastmod>{1}</lastmod>
30     <changefreq>{2}</changefreq>
31     <priority>{3}</priority>
32   </url>
33 
34   <url>
35     <loc>{0}/tags.html</loc>
36     <lastmod>{1}</lastmod>
37     <changefreq>{2}</changefreq>
38     <priority>{3}</priority>
39   </url>
40 
41   <url>
42     <loc>{0}/categories.html</loc>
43     <lastmod>{1}</lastmod>
44     <changefreq>{2}</changefreq>
45     <priority>{3}</priority>
46   </url>
47 """
48 
49 XML_URL = u"""
50   <url>
51     <loc>{0}/{1}</loc>
52     <lastmod>{2}</lastmod>
53     <changefreq>{3}</changefreq>
54     <priority>{4}</priority>
55   </url>
56 """
57 
58 XML_FOOTER = u"""
59 </urlset>
60 """
61 
62 
63 def format_date(date):
64     if date.tzinfo:
65         tz = date.strftime('%s')
66         tz = tz[:-2] + ':' + tz[-2:]
67     else:
68         tz = "-00:00"
69     return date.strftime("%Y-%m-%dT%H:%M:%S") + tz
70 
71 
72 
73 class SitemapGenerator(object):
74 
75     def __init__(self, context, settings, path, theme, output_path, *null):
76 
77         self.output_path = output_path
78         self.context = context
79         self.now = datetime.now()
80         self.siteurl = settings.get('SITEURL')
81 
82         self.format = 'xml'
83 
84         self.changefreqs = {
85             'articles': 'monthly',
86             'indexes': 'daily',
87             'pages': 'monthly'
88         }
89 
90         self.priorities = {
91             'articles': 0.5,
92             'indexes': 0.5,
93             'pages': 0.5
94         }
95 
96         config = settings.get('SITEMAP', {})
97 
98         if not isinstance(config, dict):
99             warning("sitemap plugin: the SITEMAP setting must be a dict")
100         else:
101             fmt = config.get('format')
102             pris = config.get('priorities')
103             chfreqs = config.get('changefreqs')
104 
105             if fmt not in ('xml', 'txt'):
106                 warning("sitemap plugin: SITEMAP['format'] must be `txt' or `xml'")
107                 warning("sitemap plugin: Setting SITEMAP['format'] on `xml'")
108             elif fmt == 'txt':
109                 self.format = fmt
110                 return
111 
112             valid_keys = ('articles', 'indexes', 'pages')
113             valid_chfreqs = ('always', 'hourly', 'daily', 'weekly', 'monthly',
114                     'yearly', 'never')
115 
116             if isinstance(pris, dict):
117                 for k, v in pris.iteritems():
118                     if k in valid_keys and not isinstance(v, (int, float)):
119                         default = self.priorities[k]
120                         warning("sitemap plugin: priorities must be numbers")
121                         warning("sitemap plugin: setting SITEMAP['priorities']"
122                                 "['{0}'] on {1}".format(k, default))
123                         pris[k] = default
124                 self.priorities.update(pris)
125             elif pris is not None:
126                 warning("sitemap plugin: SITEMAP['priorities'] must be a dict")
127                 warning("sitemap plugin: using the default values")
128 
129             if isinstance(chfreqs, dict):
130                 for k, v in chfreqs.iteritems():
131                     if k in valid_keys and v not in valid_chfreqs:
132                         default = self.changefreqs[k]
133                         warning("sitemap plugin: invalid changefreq `{0}'".format(v))
134                         warning("sitemap plugin: setting SITEMAP['changefreqs']"
135                                 "['{0}'] on '{1}'".format(k, default))
136                         chfreqs[k] = default
137                 self.changefreqs.update(chfreqs)
138             elif chfreqs is not None:
139                 warning("sitemap plugin: SITEMAP['changefreqs'] must be a dict")
140                 warning("sitemap plugin: using the default values")
141 
142 
143 
144     def write_url(self, page, fd):
145 
146         if getattr(page, 'status', 'published') != 'published':
147             return
148 
149         lastmod = format_date(getattr(page, 'date', self.now))
150 
151         if isinstance(page, contents.Article):
152             pri = self.priorities['articles']
153             chfreq = self.changefreqs['articles']
154         elif isinstance(page, contents.Page):
155             pri = self.priorities['pages']
156             chfreq = self.changefreqs['pages']
157         else:
158             pri = self.priorities['indexes']
159             chfreq = self.changefreqs['indexes']
160 
161 
162         if self.format == 'xml':
163             fd.write(XML_URL.format(self.siteurl, page.url, lastmod, chfreq, pri))
164         else:
165             fd.write(self.siteurl + '/' + loc + '\n')
166 
167 
168     def generate_output(self, writer):
169         path = os.path.join(self.output_path, 'sitemap.{0}'.format(self.format))
170 
171         pages = self.context['pages'] + self.context['articles'] \
172                 + [ c for (c, a) in self.context['categories']] \
173                 + [ t for (t, a) in self.context['tags']] \
174                 + [ a for (a, b) in self.context['authors']]
175 
176         for article in self.context['articles']:
177             pages += article.translations
178 
179 
180         info('writing {0}'.format(path))
181 
182         with open(path, 'w', encoding='utf-8') as fd:
183 
184             if self.format == 'xml':
185                 fd.write(XML_HEADER.format(
186                         self.siteurl,
187                         format_date(self.now),
188                         self.changefreqs['indexes'],
189                         self.priorities['indexes']
190                     )
191                 )
192             else:
193                 fd.write(TXT_HEADER.format(self.siteurl))
194 
195             for page in pages:
196                 self.write_url(page, fd)
197 
198             if self.format == 'xml':
199                 fd.write(XML_FOOTER)
200 
201 
202 
203 def get_generators(generators):
204     return SitemapGenerator
205 
206 
207 def register():
208     signals.get_generators.connect(get_generators)
209
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pelican/plugins/sitemap.py b/pelican/plugins/sitemap.py
--- a/pelican/plugins/sitemap.py
+++ b/pelican/plugins/sitemap.py
@@ -1,3 +1,4 @@
+import collections
 import os.path
 
 from datetime import datetime
@@ -16,34 +17,6 @@
 <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
          xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
-
-  <url>
-    <loc>{0}/index.html</loc>
-    <lastmod>{1}</lastmod>
-    <changefreq>{2}</changefreq>
-    <priority>{3}</priority>
-  </url>
-
-  <url>
-    <loc>{0}/archives.html</loc>
-    <lastmod>{1}</lastmod>
-    <changefreq>{2}</changefreq>
-    <priority>{3}</priority>
-  </url>
-
-  <url>
-    <loc>{0}/tags.html</loc>
-    <lastmod>{1}</lastmod>
-    <changefreq>{2}</changefreq>
-    <priority>{3}</priority>
-  </url>
-
-  <url>
-    <loc>{0}/categories.html</loc>
-    <lastmod>{1}</lastmod>
-    <changefreq>{2}</changefreq>
-    <priority>{3}</priority>
-  </url>
 """
 
 XML_URL = u"""
@@ -146,6 +119,10 @@
         if getattr(page, 'status', 'published') != 'published':
             return
 
+        page_path = os.path.join(self.output_path, page.url)
+        if not os.path.exists(page_path):
+            return
+
         lastmod = format_date(getattr(page, 'date', self.now))
 
         if isinstance(page, contents.Article):
@@ -176,22 +153,29 @@
         for article in self.context['articles']:
             pages += article.translations
 
-
         info('writing {0}'.format(path))
 
         with open(path, 'w', encoding='utf-8') as fd:
 
             if self.format == 'xml':
-                fd.write(XML_HEADER.format(
-                        self.siteurl,
-                        format_date(self.now),
-                        self.changefreqs['indexes'],
-                        self.priorities['indexes']
-                    )
-                )
+                fd.write(XML_HEADER)
             else:
                 fd.write(TXT_HEADER.format(self.siteurl))
 
+            FakePage = collections.namedtuple('FakePage',
+                                              ['status',
+                                               'date',
+                                               'url'])
+
+            for standard_page_url in ['index.html',
+                                      'archives.html',
+                                      'tags.html',
+                                      'categories.html']:
+                fake = FakePage(status='published',
+                                date=self.now,
+                                url=standard_page_url)
+                self.write_url(fake, fd)
+
             for page in pages:
                 self.write_url(page, fd)
 
@@ -199,7 +183,6 @@
                 fd.write(XML_FOOTER)
 
 
-
 def get_generators(generators):
     return SitemapGenerator

{"golden_diff": "diff --git a/pelican/plugins/sitemap.py b/pelican/plugins/sitemap.py\n--- a/pelican/plugins/sitemap.py\n+++ b/pelican/plugins/sitemap.py\n@@ -1,3 +1,4 @@\n+import collections\n import os.path\n \n from datetime import datetime\n@@ -16,34 +17,6 @@\n <urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n          xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"\n          xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n-\n-  <url>\n-    <loc>{0}/index.html</loc>\n-    <lastmod>{1}</lastmod>\n-    <changefreq>{2}</changefreq>\n-    <priority>{3}</priority>\n-  </url>\n-\n-  <url>\n-    <loc>{0}/archives.html</loc>\n-    <lastmod>{1}</lastmod>\n-    <changefreq>{2}</changefreq>\n-    <priority>{3}</priority>\n-  </url>\n-\n-  <url>\n-    <loc>{0}/tags.html</loc>\n-    <lastmod>{1}</lastmod>\n-    <changefreq>{2}</changefreq>\n-    <priority>{3}</priority>\n-  </url>\n-\n-  <url>\n-    <loc>{0}/categories.html</loc>\n-    <lastmod>{1}</lastmod>\n-    <changefreq>{2}</changefreq>\n-    <priority>{3}</priority>\n-  </url>\n \"\"\"\n \n XML_URL = u\"\"\"\n@@ -146,6 +119,10 @@\n         if getattr(page, 'status', 'published') != 'published':\n             return\n \n+        page_path = os.path.join(self.output_path, page.url)\n+        if not os.path.exists(page_path):\n+            return\n+\n         lastmod = format_date(getattr(page, 'date', self.now))\n \n         if isinstance(page, contents.Article):\n@@ -176,22 +153,29 @@\n         for article in self.context['articles']:\n             pages += article.translations\n \n-\n         info('writing {0}'.format(path))\n \n         with open(path, 'w', encoding='utf-8') as fd:\n \n             if self.format == 'xml':\n-                fd.write(XML_HEADER.format(\n-                        self.siteurl,\n-                        format_date(self.now),\n-                        self.changefreqs['indexes'],\n-                        self.priorities['indexes']\n-                    )\n-                )\n+                fd.write(XML_HEADER)\n             else:\n                 fd.write(TXT_HEADER.format(self.siteurl))\n \n+            FakePage = collections.namedtuple('FakePage',\n+                                              ['status',\n+                                               'date',\n+                                               'url'])\n+\n+            for standard_page_url in ['index.html',\n+                                      'archives.html',\n+                                      'tags.html',\n+                                      'categories.html']:\n+                fake = FakePage(status='published',\n+                                date=self.now,\n+                                url=standard_page_url)\n+                self.write_url(fake, fd)\n+\n             for page in pages:\n                 self.write_url(page, fd)\n \n@@ -199,7 +183,6 @@\n                 fd.write(XML_FOOTER)\n \n \n-\n def get_generators(generators):\n     return SitemapGenerator\n", "issue": "sitemap.xml contains pages that don't exist\nMy settings.xml says:\n\n```\nAUTHOR_SAVE_AS = ''\n```\n\nin order to force pelican to not generate author pages.\n\nWhen I include:\n\n```\nPLUGINS = [sitemap]\nSITEMAP = {'format': 'xml'}\n```\n\nmy sitemap.xml contains:\n\n  <url>\n    <loc>http://example.com/author/brian.html</loc>\n    <lastmod>2012-10-07T19:42:14-00:00</lastmod>\n    <changefreq>daily</changefreq>\n    <priority>0.5</priority>\n  </url>\n\nThe referenced file does not exist in my output directory.\n\nThe same holds true for `/archives.html`, `/tags.html`, `/categories.html`, and `/category/*.html`.\n\n", "before_files": [{"content": "import os.path\n\nfrom datetime import datetime\nfrom logging import debug, warning, error, info\nfrom codecs import open\n\nfrom pelican import signals, contents\n\nTXT_HEADER = u\"\"\"{0}/index.html\n{0}/archives.html\n{0}/tags.html\n{0}/categories.html\n\"\"\"\n\nXML_HEADER = u\"\"\"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"\n         xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n\n  <url>\n    <loc>{0}/index.html</loc>\n    <lastmod>{1}</lastmod>\n    <changefreq>{2}</changefreq>\n    <priority>{3}</priority>\n  </url>\n\n  <url>\n    <loc>{0}/archives.html</loc>\n    <lastmod>{1}</lastmod>\n    <changefreq>{2}</changefreq>\n    <priority>{3}</priority>\n  </url>\n\n  <url>\n    <loc>{0}/tags.html</loc>\n    <lastmod>{1}</lastmod>\n    <changefreq>{2}</changefreq>\n    <priority>{3}</priority>\n  </url>\n\n  <url>\n    <loc>{0}/categories.html</loc>\n    <lastmod>{1}</lastmod>\n    <changefreq>{2}</changefreq>\n    <priority>{3}</priority>\n  </url>\n\"\"\"\n\nXML_URL = u\"\"\"\n  <url>\n    <loc>{0}/{1}</loc>\n    <lastmod>{2}</lastmod>\n    <changefreq>{3}</changefreq>\n    <priority>{4}</priority>\n  </url>\n\"\"\"\n\nXML_FOOTER = u\"\"\"\n</urlset>\n\"\"\"\n\n\ndef format_date(date):\n    if date.tzinfo:\n        tz = date.strftime('%s')\n        tz = tz[:-2] + ':' + tz[-2:]\n    else:\n        tz = \"-00:00\"\n    return date.strftime(\"%Y-%m-%dT%H:%M:%S\") + tz\n\n\n\nclass SitemapGenerator(object):\n\n    def __init__(self, context, settings, path, theme, output_path, *null):\n\n        self.output_path = output_path\n        self.context = context\n        self.now = datetime.now()\n        self.siteurl = settings.get('SITEURL')\n\n        self.format = 'xml'\n\n        self.changefreqs = {\n            'articles': 'monthly',\n            'indexes': 'daily',\n            'pages': 'monthly'\n        }\n\n        self.priorities = {\n            'articles': 0.5,\n            'indexes': 0.5,\n            'pages': 0.5\n        }\n\n        config = settings.get('SITEMAP', {})\n\n        if not isinstance(config, dict):\n            warning(\"sitemap plugin: the SITEMAP setting must be a dict\")\n        else:\n            fmt = config.get('format')\n            pris = config.get('priorities')\n            chfreqs = config.get('changefreqs')\n\n            if fmt not in ('xml', 'txt'):\n                warning(\"sitemap plugin: SITEMAP['format'] must be `txt' or `xml'\")\n                warning(\"sitemap plugin: Setting SITEMAP['format'] on `xml'\")\n            elif fmt == 'txt':\n                self.format = fmt\n                return\n\n            valid_keys = ('articles', 'indexes', 'pages')\n            valid_chfreqs = ('always', 'hourly', 'daily', 'weekly', 'monthly',\n                    'yearly', 'never')\n\n            if isinstance(pris, dict):\n                for k, v in pris.iteritems():\n                    if k in valid_keys and not isinstance(v, (int, float)):\n                        default = self.priorities[k]\n                        warning(\"sitemap plugin: priorities must be numbers\")\n                        warning(\"sitemap plugin: setting SITEMAP['priorities']\"\n                                \"['{0}'] on {1}\".format(k, default))\n                        pris[k] = default\n                self.priorities.update(pris)\n            elif pris is not None:\n                warning(\"sitemap plugin: SITEMAP['priorities'] must be a dict\")\n                warning(\"sitemap plugin: using the default values\")\n\n            if isinstance(chfreqs, dict):\n                for k, v in chfreqs.iteritems():\n                    if k in valid_keys and v not in valid_chfreqs:\n                        default = self.changefreqs[k]\n                        warning(\"sitemap plugin: invalid changefreq `{0}'\".format(v))\n                        warning(\"sitemap plugin: setting SITEMAP['changefreqs']\"\n                                \"['{0}'] on '{1}'\".format(k, default))\n                        chfreqs[k] = default\n                self.changefreqs.update(chfreqs)\n            elif chfreqs is not None:\n                warning(\"sitemap plugin: SITEMAP['changefreqs'] must be a dict\")\n                warning(\"sitemap plugin: using the default values\")\n\n\n\n    def write_url(self, page, fd):\n\n        if getattr(page, 'status', 'published') != 'published':\n            return\n\n        lastmod = format_date(getattr(page, 'date', self.now))\n\n        if isinstance(page, contents.Article):\n            pri = self.priorities['articles']\n            chfreq = self.changefreqs['articles']\n        elif isinstance(page, contents.Page):\n            pri = self.priorities['pages']\n            chfreq = self.changefreqs['pages']\n        else:\n            pri = self.priorities['indexes']\n            chfreq = self.changefreqs['indexes']\n\n\n        if self.format == 'xml':\n            fd.write(XML_URL.format(self.siteurl, page.url, lastmod, chfreq, pri))\n        else:\n            fd.write(self.siteurl + '/' + loc + '\\n')\n\n\n    def generate_output(self, writer):\n        path = os.path.join(self.output_path, 'sitemap.{0}'.format(self.format))\n\n        pages = self.context['pages'] + self.context['articles'] \\\n                + [ c for (c, a) in self.context['categories']] \\\n                + [ t for (t, a) in self.context['tags']] \\\n                + [ a for (a, b) in self.context['authors']]\n\n        for article in self.context['articles']:\n            pages += article.translations\n\n\n        info('writing {0}'.format(path))\n\n        with open(path, 'w', encoding='utf-8') as fd:\n\n            if self.format == 'xml':\n                fd.write(XML_HEADER.format(\n                        self.siteurl,\n                        format_date(self.now),\n                        self.changefreqs['indexes'],\n                        self.priorities['indexes']\n                    )\n                )\n            else:\n                fd.write(TXT_HEADER.format(self.siteurl))\n\n            for page in pages:\n                self.write_url(page, fd)\n\n            if self.format == 'xml':\n                fd.write(XML_FOOTER)\n\n\n\ndef get_generators(generators):\n    return SitemapGenerator\n\n\ndef register():\n    signals.get_generators.connect(get_generators)\n", "path": "pelican/plugins/sitemap.py"}], "after_files": [{"content": "import collections\nimport os.path\n\nfrom datetime import datetime\nfrom logging import debug, warning, error, info\nfrom codecs import open\n\nfrom pelican import signals, contents\n\nTXT_HEADER = u\"\"\"{0}/index.html\n{0}/archives.html\n{0}/tags.html\n{0}/categories.html\n\"\"\"\n\nXML_HEADER = u\"\"\"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"\n         xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n\"\"\"\n\nXML_URL = u\"\"\"\n  <url>\n    <loc>{0}/{1}</loc>\n    <lastmod>{2}</lastmod>\n    <changefreq>{3}</changefreq>\n    <priority>{4}</priority>\n  </url>\n\"\"\"\n\nXML_FOOTER = u\"\"\"\n</urlset>\n\"\"\"\n\n\ndef format_date(date):\n    if date.tzinfo:\n        tz = date.strftime('%s')\n        tz = tz[:-2] + ':' + tz[-2:]\n    else:\n        tz = \"-00:00\"\n    return date.strftime(\"%Y-%m-%dT%H:%M:%S\") + tz\n\n\n\nclass SitemapGenerator(object):\n\n    def __init__(self, context, settings, path, theme, output_path, *null):\n\n        self.output_path = output_path\n        self.context = context\n        self.now = datetime.now()\n        self.siteurl = settings.get('SITEURL')\n\n        self.format = 'xml'\n\n        self.changefreqs = {\n            'articles': 'monthly',\n            'indexes': 'daily',\n            'pages': 'monthly'\n        }\n\n        self.priorities = {\n            'articles': 0.5,\n            'indexes': 0.5,\n            'pages': 0.5\n        }\n\n        config = settings.get('SITEMAP', {})\n\n        if not isinstance(config, dict):\n            warning(\"sitemap plugin: the SITEMAP setting must be a dict\")\n        else:\n            fmt = config.get('format')\n            pris = config.get('priorities')\n            chfreqs = config.get('changefreqs')\n\n            if fmt not in ('xml', 'txt'):\n                warning(\"sitemap plugin: SITEMAP['format'] must be `txt' or `xml'\")\n                warning(\"sitemap plugin: Setting SITEMAP['format'] on `xml'\")\n            elif fmt == 'txt':\n                self.format = fmt\n                return\n\n            valid_keys = ('articles', 'indexes', 'pages')\n            valid_chfreqs = ('always', 'hourly', 'daily', 'weekly', 'monthly',\n                    'yearly', 'never')\n\n            if isinstance(pris, dict):\n                for k, v in pris.iteritems():\n                    if k in valid_keys and not isinstance(v, (int, float)):\n                        default = self.priorities[k]\n                        warning(\"sitemap plugin: priorities must be numbers\")\n                        warning(\"sitemap plugin: setting SITEMAP['priorities']\"\n                                \"['{0}'] on {1}\".format(k, default))\n                        pris[k] = default\n                self.priorities.update(pris)\n            elif pris is not None:\n                warning(\"sitemap plugin: SITEMAP['priorities'] must be a dict\")\n                warning(\"sitemap plugin: using the default values\")\n\n            if isinstance(chfreqs, dict):\n                for k, v in chfreqs.iteritems():\n                    if k in valid_keys and v not in valid_chfreqs:\n                        default = self.changefreqs[k]\n                        warning(\"sitemap plugin: invalid changefreq `{0}'\".format(v))\n                        warning(\"sitemap plugin: setting SITEMAP['changefreqs']\"\n                                \"['{0}'] on '{1}'\".format(k, default))\n                        chfreqs[k] = default\n                self.changefreqs.update(chfreqs)\n            elif chfreqs is not None:\n                warning(\"sitemap plugin: SITEMAP['changefreqs'] must be a dict\")\n                warning(\"sitemap plugin: using the default values\")\n\n\n\n    def write_url(self, page, fd):\n\n        if getattr(page, 'status', 'published') != 'published':\n            return\n\n        page_path = os.path.join(self.output_path, page.url)\n        if not os.path.exists(page_path):\n            return\n\n        lastmod = format_date(getattr(page, 'date', self.now))\n\n        if isinstance(page, contents.Article):\n            pri = self.priorities['articles']\n            chfreq = self.changefreqs['articles']\n        elif isinstance(page, contents.Page):\n            pri = self.priorities['pages']\n            chfreq = self.changefreqs['pages']\n        else:\n            pri = self.priorities['indexes']\n            chfreq = self.changefreqs['indexes']\n\n\n        if self.format == 'xml':\n            fd.write(XML_URL.format(self.siteurl, page.url, lastmod, chfreq, pri))\n        else:\n            fd.write(self.siteurl + '/' + loc + '\\n')\n\n\n    def generate_output(self, writer):\n        path = os.path.join(self.output_path, 'sitemap.{0}'.format(self.format))\n\n        pages = self.context['pages'] + self.context['articles'] \\\n                + [ c for (c, a) in self.context['categories']] \\\n                + [ t for (t, a) in self.context['tags']] \\\n                + [ a for (a, b) in self.context['authors']]\n\n        for article in self.context['articles']:\n            pages += article.translations\n\n        info('writing {0}'.format(path))\n\n        with open(path, 'w', encoding='utf-8') as fd:\n\n            if self.format == 'xml':\n                fd.write(XML_HEADER)\n            else:\n                fd.write(TXT_HEADER.format(self.siteurl))\n\n            FakePage = collections.namedtuple('FakePage',\n                                              ['status',\n                                               'date',\n                                               'url'])\n\n            for standard_page_url in ['index.html',\n                                      'archives.html',\n                                      'tags.html',\n                                      'categories.html']:\n                fake = FakePage(status='published',\n                                date=self.now,\n                                url=standard_page_url)\n                self.write_url(fake, fd)\n\n            for page in pages:\n                self.write_url(page, fd)\n\n            if self.format == 'xml':\n                fd.write(XML_FOOTER)\n\n\ndef get_generators(generators):\n    return SitemapGenerator\n\n\ndef register():\n    signals.get_generators.connect(get_generators)\n", "path": "pelican/plugins/sitemap.py"}]}