Repository: getnikola/nikola

Issue:
Sitemaps are not rebuilt
`touch pages/test-1.html
nikola build
mv pages/test-1.html pages/test-2.html
nikola build`

sitemap.xml is not rebuilt. Contains test-1.html (expected) but not test-2.html (woopsy). Output contains both (expected).

`nikola check --clean-files`

Removes test-1.html from output but also does not rebuild sitemap.xml.



Discussion:
On 27/08/14 16:00, Daniel Aleksandersen wrote:

> |touch pages/test-1.html
> nikola build
> mv pages/test-1.html pages/test-2.html
> nikola build|
> 
> sitemap.xml is not rebuilt. Contains test-1.html (expected) but not 
> test-2.html (woopsy). Output contains both (expected).

Is pages where you keep your output? If yes, then sure, Nikola doesn't 
track your output at all, really, except to rebuild when a file is missing.

PAGES = ( ("pages/*.html", "pages", "story.tmpl"), )

Sorry about not providing enough context.

So when the file is moved, it should be treated as a new file.

When output is deleted (using --clean-files) then sitemap should be rebuilt.

On 27/08/14 16:21, Daniel Aleksandersen wrote:

> PAGES = ( ("pages/*.html", "about", "story.tmpl"), )

In that case it still makes sense because the output doesn't change when 
you move that file around, because it still has the same slug.

The slug (the file is empty) is made from the filename.

There are indeed two files in output (oldname and newname).

After upgrading from 7.0.1 to 7.1.0, the `output/sitemap.xml` and `output/sitemapindex.xml` files are not updated when there is a site change.  Specifically, if I add a new post, then `nikola build` the site maps are both the old versions.

(http://getnikola.com/blog/nikola-v710-released.html#comment-1578873024)

32f4c0d4fad12624fd0d697669aef46a67d6d7f6 is the first bad commit

```
commit 32f4c0d4fad12624fd0d697669aef46a67d6d7f6
Author: Roberto Alsina <ralsina@netmanagers.com.ar>
Date:   Sun Feb 9 11:48:21 2014 -0300

    Fix for a part of #1032

:100644 100644 32f85a317a8ae6f20f266f12ff9c7af84f79157d 1914c8845ac528a7b17ebc27842d63c197503191 M      CHANGES.txt
:040000 040000 808cdc722f0e4fec5b60a78b108802a24a6b58b6 e4efbe241e9bf1f2e9225652cbfc05f96de194ca M      nikola
```

#1032 is _Make life easier and stop requiring building twice to get the full site_.

Sitemaps are a mess.

Fix upcoming!


Resolving patch:
diff --git a/nikola/plugins/task/sitemap/__init__.py b/nikola/plugins/task/sitemap/__init__.py
--- a/nikola/plugins/task/sitemap/__init__.py
+++ b/nikola/plugins/task/sitemap/__init__.py
@@ -208,7 +208,27 @@ def write_sitemapindex():
         # to scan locations.
         def scan_locs_task():
             scan_locs()
-            return {'locations': list(urlset.keys()) + list(sitemapindex.keys())}
+
+            # Generate a list of file dependencies for the actual generation
+            # task, so rebuilds are triggered.  (Issue #1032)
+            output = kw["output_folder"]
+            file_dep = []
+
+            for i in urlset.keys():
+                p = os.path.join(output, urlparse(i).path.lstrip('/'))
+                if not p.endswith('sitemap.xml') and not p.endswith('/'):
+                    file_dep.append(p)
+                if p.endswith('/') and os.path.exists(p + 'index.html'):
+                    file_dep.append(p + 'index.html')
+
+            for i in sitemapindex.keys():
+                p = os.path.join(output, urlparse(i).path.lstrip('/'))
+                if not p.endswith('sitemap.xml') and not p.endswith('/'):
+                    file_dep.append(p)
+                if p.endswith('/') and os.path.exists(p + 'index.html'):
+                    file_dep.append(p + 'index.html')
+
+            return {'file_dep': file_dep}
 
         yield {
             "basename": "_scan_locs",


Test patch: