diff piecrust/baking/single.py @ 329:422052d2e978

internal: Try handling URLs in a consistent way. * Now URLs passed to, and returned from, routes will always be absolute URLs, i.e. URLs including the site root. * Validate the site root at config loading time to make sure it starts and ends with a slash. * Get rid of unused stuff. * Add tests.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 31 Mar 2015 23:03:28 -0700
parents 65e6d72f3877
children b034f6f15e22
line wrap: on
line diff
--- a/piecrust/baking/single.py	Tue Mar 31 22:38:56 2015 -0700
+++ b/piecrust/baking/single.py	Tue Mar 31 23:03:28 2015 -0700
@@ -11,6 +11,7 @@
         PASS_FORMATTING, PASS_RENDERING)
 from piecrust.sources.base import (PageFactory,
         REALM_NAMES, REALM_USER, REALM_THEME)
+from piecrust.uriutil import split_uri
 
 
 logger = logging.getLogger(__name__)
@@ -41,8 +42,10 @@
         self.pagination_suffix = app.config.get('site/pagination_suffix')
 
     def getOutputPath(self, uri):
+        uri_root, uri_path = split_uri(self.app, uri)
+
         bake_path = [self.out_dir]
-        decoded_uri = urllib.parse.unquote(uri.lstrip('/'))
+        decoded_uri = urllib.parse.unquote(uri_path)
         if self.pretty_urls:
             bake_path.append(decoded_uri)
             bake_path.append('index.html')
@@ -71,8 +74,7 @@
 
         # Generate the URL using the route.
         page = factory.buildPage()
-        uri = route.getUri(route_metadata, provider=page,
-                           include_site_root=False)
+        uri = route.getUri(route_metadata, provider=page)
 
         override = self.record.getOverrideEntry(factory, uri)
         if override is not None:
@@ -125,7 +127,7 @@
 
         while has_more_subs:
             sub_uri = route.getUri(route_metadata, sub_num=cur_sub,
-                                   provider=page, include_site_root=False)
+                                   provider=page)
             out_path = self.getOutputPath(sub_uri)
 
             # Check for up-to-date outputs.