Repository: getnikola/nikola

Issue:
Add an option to `nikola new_post` to create yyyy/mm/dd directory structures
A lot of people want to have a `yyyy/mm/dd/slug` directory structure. So, let’s make it an option somewhere in `nikola new_post` (that can be also set as enabled by default in `conf.py`) to automatically create that directory tree for them.

Then there’s Jekyll-esque “replace dashes with slashes”, but that’s a story for another time.



Discussion:
If it could also allow custom URL structures that would be great. Currently have had to hack the post.py file in order to set the:

`self.folder = <my custom folder structure>`

I guess a conf format token string would work "Y/M/D" for your case, but relying purely on pre-defined tokens means if someone wants something that is possibel with tokens they cannot.

There any reason why a signal task couldn't be added 'folder_structure'?

Uh, what do you mean? Do you know you can do something like `posts/something/or/other.rst` and end up with `output/posts/something/or/other/`? If that’s not it, please clarify.

When you say `yyyy/mm/dd/slug`, does this mean `output/yyyy/mm/dd/slug` or `output/posts/yyyy/mm/dd/slug`?
Depends on your POSTS config…

Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -534,6 +534,8 @@ def __init__(self, **config):
             'MARKDOWN_EXTENSIONS': ['fenced_code', 'codehilite'],  # FIXME: Add 'extras' in v8
             'MAX_IMAGE_SIZE': 1280,
             'MATHJAX_CONFIG': '',
+            'NEW_POST_DATE_PATH': False,
+            'NEW_POST_DATE_PATH_FORMAT': '%Y/%m/%d',
             'OLD_THEME_SUPPORT': True,
             'OUTPUT_FOLDER': 'output',
             'POSTS': (("posts/*.txt", "posts", "post.tmpl"),),
diff --git a/nikola/plugins/command/new_post.py b/nikola/plugins/command/new_post.py
--- a/nikola/plugins/command/new_post.py
+++ b/nikola/plugins/command/new_post.py
@@ -204,7 +204,14 @@ class CommandNewPost(Command):
             'default': '',
             'help': 'Import an existing file instead of creating a placeholder'
         },
-
+        {
+            'name': 'date-path',
+            'short': 'd',
+            'long': 'date-path',
+            'type': bool,
+            'default': False,
+            'help': 'Create post with date path (eg. year/month/day, see NEW_POST_DATE_PATH_FORMAT in config)'
+        },
     ]
 
     def _execute(self, options, args):
@@ -234,6 +241,9 @@ def _execute(self, options, args):
         twofile = options['twofile']
         import_file = options['import']
         wants_available = options['available-formats']
+        date_path_opt = options['date-path']
+        date_path_auto = self.site.config['NEW_POST_DATE_PATH']
+        date_path_format = self.site.config['NEW_POST_DATE_PATH_FORMAT'].strip('/')
 
         if wants_available:
             self.print_compilers()
@@ -330,10 +340,14 @@ def _execute(self, options, args):
             pattern = os.path.basename(entry[0])
             suffix = pattern[1:]
             output_path = os.path.dirname(entry[0])
+            if date_path_auto or date_path_opt:
+                output_path += os.sep + datetime.datetime.now(self.site.tzinfo).strftime(date_path_format)
 
             txt_path = os.path.join(output_path, slug + suffix)
             meta_path = os.path.join(output_path, slug + ".meta")
         else:
+            if date_path_opt:
+                LOGGER.warn("A path has been specified, ignoring -d")
             txt_path = os.path.join(self.site.original_cwd, path)
             meta_path = os.path.splitext(txt_path)[0] + ".meta"
 


Test patch: