Mercurial > piecrust2
diff piecrust/routing.py @ 262:61145dcd56e0
routing: Better generate URLs according to the site configuration.
This fixes problems now that even the chef server generates URLs that are
appropriate given the `pretty_urls` and `trailing_slash` settings.
Add some tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 24 Feb 2015 08:06:25 -0800 |
parents | da5e6e00fb41 |
children | 422052d2e978 |
line wrap: on
line diff
--- a/piecrust/routing.py Tue Feb 24 08:04:49 2015 -0800 +++ b/piecrust/routing.py Tue Feb 24 08:06:25 2015 -0800 @@ -114,7 +114,7 @@ suffix = None if sub_num > 1: # Note that we know the pagination suffix starts with a slash. - suffix = self.pagination_suffix_format % sub_num + suffix = self.pagination_suffix_format % {'num': sub_num} if self.pretty_urls: # Output will be: @@ -123,7 +123,10 @@ # - `subdir/name.ext` # - `subdir/name.ext/2` if suffix: - uri = uri.rstrip('/') + suffix + if uri == '': + uri = suffix.lstrip('/') + else: + uri = uri.rstrip('/') + suffix if self.trailing_slash: uri = uri.rstrip('/') + '/' else: @@ -132,13 +135,17 @@ # - `subdir/name/2.html` # - `subdir/name.ext` # - `subdir/name/2.ext` - base_uri, ext = os.path.splitext(uri) - if not ext: - ext = '.html' - if suffix: - uri = base_uri + suffix + ext + if uri == '': + if suffix: + uri = suffix.lstrip('/') + '.html' else: - uri = base_uri + ext + base_uri, ext = os.path.splitext(uri) + if not ext: + ext = '.html' + if suffix: + uri = base_uri + suffix + ext + else: + uri = base_uri + ext if include_site_root: uri = self.uri_root + uri