Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
328:2a5996e0d3ec | 329:422052d2e978 |
---|---|
9 page_value_accessor) | 9 page_value_accessor) |
10 from piecrust.rendering import (PageRenderingContext, render_page, | 10 from piecrust.rendering import (PageRenderingContext, render_page, |
11 PASS_FORMATTING, PASS_RENDERING) | 11 PASS_FORMATTING, PASS_RENDERING) |
12 from piecrust.sources.base import (PageFactory, | 12 from piecrust.sources.base import (PageFactory, |
13 REALM_NAMES, REALM_USER, REALM_THEME) | 13 REALM_NAMES, REALM_USER, REALM_THEME) |
14 from piecrust.uriutil import split_uri | |
14 | 15 |
15 | 16 |
16 logger = logging.getLogger(__name__) | 17 logger = logging.getLogger(__name__) |
17 | 18 |
18 | 19 |
39 self.site_root = app.config.get('site/root') | 40 self.site_root = app.config.get('site/root') |
40 self.pretty_urls = app.config.get('site/pretty_urls') | 41 self.pretty_urls = app.config.get('site/pretty_urls') |
41 self.pagination_suffix = app.config.get('site/pagination_suffix') | 42 self.pagination_suffix = app.config.get('site/pagination_suffix') |
42 | 43 |
43 def getOutputPath(self, uri): | 44 def getOutputPath(self, uri): |
45 uri_root, uri_path = split_uri(self.app, uri) | |
46 | |
44 bake_path = [self.out_dir] | 47 bake_path = [self.out_dir] |
45 decoded_uri = urllib.parse.unquote(uri.lstrip('/')) | 48 decoded_uri = urllib.parse.unquote(uri_path) |
46 if self.pretty_urls: | 49 if self.pretty_urls: |
47 bake_path.append(decoded_uri) | 50 bake_path.append(decoded_uri) |
48 bake_path.append('index.html') | 51 bake_path.append('index.html') |
49 elif decoded_uri == '': | 52 elif decoded_uri == '': |
50 bake_path.append('index.html') | 53 bake_path.append('index.html') |
69 slugified_term = taxonomy_term | 72 slugified_term = taxonomy_term |
70 route_metadata.update({taxonomy.setting_name: slugified_term}) | 73 route_metadata.update({taxonomy.setting_name: slugified_term}) |
71 | 74 |
72 # Generate the URL using the route. | 75 # Generate the URL using the route. |
73 page = factory.buildPage() | 76 page = factory.buildPage() |
74 uri = route.getUri(route_metadata, provider=page, | 77 uri = route.getUri(route_metadata, provider=page) |
75 include_site_root=False) | |
76 | 78 |
77 override = self.record.getOverrideEntry(factory, uri) | 79 override = self.record.getOverrideEntry(factory, uri) |
78 if override is not None: | 80 if override is not None: |
79 override_source = self.app.getSource(override.source_name) | 81 override_source = self.app.getSource(override.source_name) |
80 if override_source.realm == factory.source.realm: | 82 if override_source.realm == factory.source.realm: |
123 % uri) | 125 % uri) |
124 invalidate_formatting = True | 126 invalidate_formatting = True |
125 | 127 |
126 while has_more_subs: | 128 while has_more_subs: |
127 sub_uri = route.getUri(route_metadata, sub_num=cur_sub, | 129 sub_uri = route.getUri(route_metadata, sub_num=cur_sub, |
128 provider=page, include_site_root=False) | 130 provider=page) |
129 out_path = self.getOutputPath(sub_uri) | 131 out_path = self.getOutputPath(sub_uri) |
130 | 132 |
131 # Check for up-to-date outputs. | 133 # Check for up-to-date outputs. |
132 do_bake = True | 134 do_bake = True |
133 if not force_this: | 135 if not force_this: |