Repository: getnikola/nikola

Issue:
Wordpress import: remove date from final url post
After importing my Wordpress blog (http://humitos.wordpress.com) I found that all of the final urls had the date at the beginning, and I didn't want that. For example, this one
- /2013/08/16/la-cecilia-la-diferencia-de-lo-posible/

ends in:
- /20130816la-cecilia-la-diferencia-de-lo-posible/

and I prefer:
- /la-cecilia-la-diferencia-de-lo-posible/

So, I removed the 8 first character from the url slug by doing this modification

```
diff --git a/nikola/plugins/command/import_wordpress.py b/nikola/plugins/command/import_wordpress.py
index 1aded89..6468104 100644
--- a/nikola/plugins/command/import_wordpress.py
+++ b/nikola/plugins/command/import_wordpress.py
@@ -359,6 +359,10 @@ class CommandImportWordpress(Command, ImportMixin):
         if isinstance(path, utils.bytes_str):
             path = path.decode('utf8')
         slug = utils.slugify(path)
+
+        # Remove date form the slug
+        slug = utils.slugify(path)[8:]
+
         if not slug:  # it happens if the post has no "nice" URL
             slug = get_text_tag(
                 item, '{{{0}}}post_name'.format(wordpress_namespace), None)
```

I think that not all the wordpress blogs have the urls in that way, so I think this could be an option from the import_wordpress command.



Discussion:
Why not do it sanely, actually make them into directories?  **[Cool URIs don’t change.](http://www.w3.org/Provider/Style/URI.html)**  And WordPress has sane ones.

When this was written, Nikola only supported flat trees of posts. So yes, that's a good idea.


Resolving patch:
diff --git a/nikola/plugins/command/import_wordpress.py b/nikola/plugins/command/import_wordpress.py
--- a/nikola/plugins/command/import_wordpress.py
+++ b/nikola/plugins/command/import_wordpress.py
@@ -350,14 +350,17 @@ def import_item(self, item, wordpress_namespace, out_folder=None):
         # link is something like http://foo.com/2012/09/01/hello-world/
         # So, take the path, utils.slugify it, and that's our slug
         link = get_text_tag(item, 'link', None)
-        path = unquote(urlparse(link).path)
+        path = unquote(urlparse(link).path.strip('/'))
 
         # In python 2, path is a str. slug requires a unicode
         # object. According to wikipedia, unquoted strings will
         # usually be UTF8
         if isinstance(path, utils.bytes_str):
             path = path.decode('utf8')
-        slug = utils.slugify(path)
+        pathlist = path.split('/')
+        if len(pathlist) > 1:
+            out_folder = os.path.join(*([out_folder] + pathlist[:-1]))
+        slug = utils.slugify(pathlist[-1])
         if not slug:  # it happens if the post has no "nice" URL
             slug = get_text_tag(
                 item, '{{{0}}}post_name'.format(wordpress_namespace), None)


Test patch:
diff --git a/tests/test_command_import_wordpress.py b/tests/test_command_import_wordpress.py
--- a/tests/test_command_import_wordpress.py
+++ b/tests/test_command_import_wordpress.py
@@ -173,7 +173,7 @@ def test_importing_posts_and_attachments(self):
             'kontakt', '2009-07-16 20:20:32', None, [])
 
         self.assertTrue(write_content.called)
-        write_content.assert_any_call('new_site/posts/200704hoert.wp'.replace('/', os.sep),
+        write_content.assert_any_call('new_site/posts/2007/04/hoert.wp'.replace('/', os.sep),
                                       """An image.
 
 <img class="size-full wp-image-16" title="caption test" src="http://some.blog/wp-content/uploads/2009/07/caption_test.jpg" alt="caption test" width="739" height="517" />
@@ -193,7 +193,7 @@ def test_importing_posts_and_attachments(self):
 """)
 
         write_content.assert_any_call(
-            'new_site/posts/200807arzt-und-pfusch-s-i-c-k.wp'.replace('/', os.sep),
+            'new_site/posts/2008/07/arzt-und-pfusch-s-i-c-k.wp'.replace('/', os.sep),
             '''<img class="size-full wp-image-10 alignright" title="Arzt+Pfusch - S.I.C.K." src="http://some.blog/wp-content/uploads/2008/07/arzt_und_pfusch-sick-cover.png" alt="Arzt+Pfusch - S.I.C.K." width="210" height="209" />Arzt+Pfusch - S.I.C.K.Gerade bin ich \xfcber das Album <em>S.I.C.K</em> von <a title="Arzt+Pfusch" href="http://www.arztpfusch.com/" target="_blank">Arzt+Pfusch</a> gestolpert, welches Arzt+Pfusch zum Download f\xfcr lau anbieten. Das Album steht unter einer Creative Commons <a href="http://creativecommons.org/licenses/by-nc-nd/3.0/de/">BY-NC-ND</a>-Lizenz.
 Die Ladung <em>noisebmstupidevildustrial</em> gibts als MP3s mit <a href="http://www.archive.org/download/dmp005/dmp005_64kb_mp3.zip">64kbps</a> und <a href="http://www.archive.org/download/dmp005/dmp005_vbr_mp3.zip">VBR</a>, als Ogg Vorbis und als FLAC (letztere <a href="http://www.archive.org/details/dmp005">hier</a>). <a href="http://www.archive.org/download/dmp005/dmp005-artwork.zip">Artwork</a> und <a href="http://www.archive.org/download/dmp005/dmp005-lyrics.txt">Lyrics</a> gibts nochmal einzeln zum Download.''')
         write_content.assert_any_call(
@@ -214,11 +214,11 @@ def test_importing_posts_and_attachments(self):
 
         self.assertEqual(
             self.import_command.url_map['http://some.blog/2007/04/hoert/'],
-            'http://some.blog/posts/200704hoert.html')
+            'http://some.blog/posts/2007/04/hoert.html')
         self.assertEqual(
             self.import_command.url_map[
                 'http://some.blog/2008/07/arzt-und-pfusch-s-i-c-k/'],
-            'http://some.blog/posts/200807arzt-und-pfusch-s-i-c-k.html')
+            'http://some.blog/posts/2008/07/arzt-und-pfusch-s-i-c-k.html')
         self.assertEqual(
             self.import_command.url_map['http://some.blog/kontakt/'],
             'http://some.blog/stories/kontakt.html')