comparison 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
comparison
equal deleted inserted replaced
250:311447fe3dd0 256:da5e6e00fb41
30 self.record = record 30 self.record = record
31 self.copy_assets = copy_assets 31 self.copy_assets = copy_assets
32 self.site_root = app.config.get('site/root') 32 self.site_root = app.config.get('site/root')
33 self.pretty_urls = app.config.get('site/pretty_urls') 33 self.pretty_urls = app.config.get('site/pretty_urls')
34 self.pagination_suffix = app.config.get('site/pagination_suffix') 34 self.pagination_suffix = app.config.get('site/pagination_suffix')
35
36 def getOutputUri(self, uri, num):
37 suffix = self.pagination_suffix.replace('%num%', str(num))
38 if self.pretty_urls:
39 # Output will be:
40 # - `uri/name`
41 # - `uri/name/2`
42 # - `uri/name.ext`
43 # - `uri/name.ext/2`
44 if num <= 1:
45 return uri
46 return uri + suffix
47 else:
48 # Output will be:
49 # - `uri/name.html`
50 # - `uri/name/2.html`
51 # - `uri/name.ext`
52 # - `uri/name/2.ext`
53 if uri == '/':
54 if num <= 1:
55 return '/'
56 return '/' + suffix.lstrip('/')
57 else:
58 if num <= 1:
59 return uri
60 #TODO: watch out for tags with dots in them.
61 base_uri, ext = os.path.splitext(uri)
62 return base_uri + suffix + ext
63 35
64 def getOutputPath(self, uri): 36 def getOutputPath(self, uri):
65 bake_path = [self.out_dir] 37 bake_path = [self.out_dir]
66 decoded_uri = urllib.parse.unquote(uri.lstrip('/')) 38 decoded_uri = urllib.parse.unquote(uri.lstrip('/'))
67 if self.pretty_urls: 39 if self.pretty_urls:
107 custom_data = {tax.term_name: taxonomy_term} 79 custom_data = {tax.term_name: taxonomy_term}
108 route_metadata.update({tax.term_name: slugified_term}) 80 route_metadata.update({tax.term_name: slugified_term})
109 81
110 # Generate the URL using the route. 82 # Generate the URL using the route.
111 page = factory.buildPage() 83 page = factory.buildPage()
112 uri = route.getUri(route_metadata, page, include_site_root=False) 84 uri = route.getUri(route_metadata, provider=page,
85 include_site_root=False)
113 86
114 override = self.record.getOverrideEntry(factory, uri) 87 override = self.record.getOverrideEntry(factory, uri)
115 if override is not None: 88 if override is not None:
116 override_source = self.app.getSource(override.source_name) 89 override_source = self.app.getSource(override.source_name)
117 if override_source.realm == factory.source.realm: 90 if override_source.realm == factory.source.realm:
159 "since sources were using during that pass." 132 "since sources were using during that pass."
160 % uri) 133 % uri)
161 invalidate_formatting = True 134 invalidate_formatting = True
162 135
163 while has_more_subs: 136 while has_more_subs:
164 sub_uri = self.getOutputUri(uri, cur_sub) 137 sub_uri = route.getUri(route_metadata, sub_num=cur_sub,
138 provider=page, include_site_root=False)
165 out_path = self.getOutputPath(sub_uri) 139 out_path = self.getOutputPath(sub_uri)
166 140
167 # Check for up-to-date outputs. 141 # Check for up-to-date outputs.
168 do_bake = True 142 do_bake = True
169 if not force_this: 143 if not force_this: