Skip to content

Commit

Permalink
Fix #2651 -- append file name if new_post gets directory name
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Feb 15, 2017
1 parent 95d869d commit 8bd206c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Expand Up @@ -4,8 +4,10 @@ New in master
Features
--------

* Append file name (generated from title) if ``nikola new_post``
receives directory name as path (Issue #2651)
* Add ``META_GENERATOR_TAG`` option in conf.py allowing the meta generator
to be disabled if needed. (Issue #2628)
tag to be disabled (Issue #2628)
* Add ``YUI_COMPRESSOR_EXECUTABLE``, ``CLOSURE_COMPILER_EXECUTABLE``,
``OPTIPNG_EXECUTABLE``, ``JPEGOPTIM_EXECUTABLE`` and
``HTML_TIDY_EXECUTABLE`` to configure executables for built-in filters.
Expand Down
3 changes: 2 additions & 1 deletion docs/manual.txt
Expand Up @@ -567,7 +567,8 @@ The ``new_post`` command supports some options:

The optional ``path`` parameter tells Nikola exactly where to put it instead of guessing from your config.
So, if you do ``nikola new_post posts/random/foo.txt`` you will have a post in that path, with
"foo" as its slug.
"foo" as its slug. You can also provide a directory name, in which case Nikola
will append the file name for you (generated from title).

The ``-d, --date-path`` option automates creation of ``year/month/day`` or
similar directory structures. It can be enabled on a per-post basis, or you can
Expand Down
9 changes: 8 additions & 1 deletion nikola/plugins/command/new_post.py
Expand Up @@ -311,7 +311,14 @@ def _execute(self, options, args):
path = path.decode(sys.stdin.encoding)
except (AttributeError, TypeError): # for tests
path = path.decode('utf-8')
slug = utils.slugify(os.path.splitext(os.path.basename(path))[0], lang=self.site.default_lang)
if os.path.isdir(path):
# If the user provides a directory, add the file name generated from title (Issue #2651)
slug = utils.slugify(title, lang=self.site.default_lang)
pattern = os.path.basename(entry[0])
suffix = pattern[1:]
path = os.path.join(path, slug + suffix)
else:
slug = utils.slugify(os.path.splitext(os.path.basename(path))[0], lang=self.site.default_lang)

if isinstance(author, utils.bytes_str):
try:
Expand Down

0 comments on commit 8bd206c

Please sign in to comment.