diff piecrust/baking/single.py @ 256:da5e6e00fb41

bake/serve: Make previewed and baked URLs consistent. The preview server now handles the `pretty_urls` setting correctly instead of forcing it. The `trailing_slash` and `pagination_suffix` setting are also doing the same between the 2 systems.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 22 Feb 2015 22:01:58 -0800
parents 55087da9a72e
children 61145dcd56e0
line wrap: on
line diff
--- a/piecrust/baking/single.py	Fri Feb 20 23:44:23 2015 -0800
+++ b/piecrust/baking/single.py	Sun Feb 22 22:01:58 2015 -0800
@@ -33,34 +33,6 @@
         self.pretty_urls = app.config.get('site/pretty_urls')
         self.pagination_suffix = app.config.get('site/pagination_suffix')
 
-    def getOutputUri(self, uri, num):
-        suffix = self.pagination_suffix.replace('%num%', str(num))
-        if self.pretty_urls:
-            # Output will be:
-            # - `uri/name`
-            # - `uri/name/2`
-            # - `uri/name.ext`
-            # - `uri/name.ext/2`
-            if num <= 1:
-                return uri
-            return uri + suffix
-        else:
-            # Output will be:
-            # - `uri/name.html`
-            # - `uri/name/2.html`
-            # - `uri/name.ext`
-            # - `uri/name/2.ext`
-            if uri == '/':
-                if num <= 1:
-                    return '/'
-                return '/' + suffix.lstrip('/')
-            else:
-                if num <= 1:
-                    return uri
-                #TODO: watch out for tags with dots in them.
-                base_uri, ext = os.path.splitext(uri)
-                return base_uri + suffix + ext
-
     def getOutputPath(self, uri):
         bake_path = [self.out_dir]
         decoded_uri = urllib.parse.unquote(uri.lstrip('/'))
@@ -109,7 +81,8 @@
 
         # Generate the URL using the route.
         page = factory.buildPage()
-        uri = route.getUri(route_metadata, page, include_site_root=False)
+        uri = route.getUri(route_metadata, provider=page,
+                           include_site_root=False)
 
         override = self.record.getOverrideEntry(factory, uri)
         if override is not None:
@@ -161,7 +134,8 @@
                     invalidate_formatting = True
 
         while has_more_subs:
-            sub_uri = self.getOutputUri(uri, cur_sub)
+            sub_uri = route.getUri(route_metadata, sub_num=cur_sub,
+                                   provider=page, include_site_root=False)
             out_path = self.getOutputPath(sub_uri)
 
             # Check for up-to-date outputs.