changeset 1127:4cc020ff2537

prepare: Fix crash when preparing new pages.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 28 Feb 2018 20:16:33 -0800
parents be550e1f6423
children 6ab1299c1058
files piecrust/sources/default.py piecrust/sources/posts.py tests/cli/test_scaffolding.yaml
diffstat 3 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/piecrust/sources/default.py	Wed Feb 28 20:16:04 2018 -0800
+++ b/piecrust/sources/default.py	Wed Feb 28 20:16:33 2018 -0800
@@ -100,7 +100,7 @@
         metadata = self._createItemMetadata(path)
         config = metadata.setdefault('config', {})
         config.update({'title': uri_to_title(
-            os.path.basename(metadata['slug']))})
+            os.path.basename(metadata['route_params']['slug']))})
         return ContentItem(path, metadata)
 
     def getInteractiveFields(self):
--- a/piecrust/sources/posts.py	Wed Feb 28 20:16:04 2018 -0800
+++ b/piecrust/sources/posts.py	Wed Feb 28 20:16:33 2018 -0800
@@ -174,8 +174,10 @@
                 try:
                     year, month, day = [int(s) for s in date.split('/')]
                 except ValueError:
-                    raise Exception("Dates must be of the form: "
-                                    "YEAR/MONTH/DAY.")
+                    raise Exception(
+                        "Dates must be of the form 'YEAR/MONTH/DAY', "
+                        "got '%s'." %
+                        str(date))
                 dt = datetime.date(year, month, day)
         elif isinstance(date, datetime.datetime):
             dt = datetime.date(date.year, date.month, date.day)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/cli/test_scaffolding.yaml	Wed Feb 28 20:16:33 2018 -0800
@@ -0,0 +1,19 @@
+---
+no_kitchen: true
+args: init .
+files:
+    - config.yml
+---
+no_kitchen: true
+args: init myblog
+files:
+    - myblog/config.yml
+---
+args: prepare page foobar
+files:
+    - kitchen/pages/foobar.md
+---
+args: prepare post -d 2017/01/08 new-post
+files:
+    - kitchen/posts/2017-01-08_new-post.md
+