comparison piecrust/serving/util.py @ 711:ab5c6a8ae90a

bake: Replace hard-coded taxonomy support with "generator" system. * Taxonomies are now implemented one or more `TaxonomyGenerator`s. * A `BlogArchivesGenerator` stub is there but non-functional.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 26 May 2016 19:52:47 -0700
parents 81d9c3a3a0b5
children 606f6d57b5df
comparison
equal deleted inserted replaced
710:e85f29b28b84 711:ab5c6a8ae90a
30 self.page_num = 1 30 self.page_num = 1
31 self.not_found_errors = [] 31 self.not_found_errors = []
32 32
33 33
34 def find_routes(routes, uri): 34 def find_routes(routes, uri):
35 """ Returns routes matching the given URL, but puts generator routes
36 at the end.
37 """
35 res = [] 38 res = []
36 tax_res = [] 39 gen_res = []
37 for route in routes: 40 for route in routes:
38 metadata = route.matchUri(uri) 41 metadata = route.matchUri(uri)
39 if metadata is not None: 42 if metadata is not None:
40 if route.is_taxonomy_route: 43 if route.is_source_route:
41 tax_res.append((route, metadata)) 44 res.append((route, metadata))
42 else: 45 else:
43 res.append((route, metadata)) 46 gen_res.append((route, metadata))
44 return res + tax_res 47 return res + gen_res
45 48
46 49
47 def get_requested_page(app, req_path): 50 def get_requested_page(app, req_path):
48 # Try to find what matches the requested URL. 51 # Try to find what matches the requested URL.
49 req_path, page_num = split_sub_uri(app, req_path) 52 req_path, page_num = split_sub_uri(app, req_path)
69 req_page.not_found_errors = not_found_errors 72 req_page.not_found_errors = not_found_errors
70 return req_page 73 return req_page
71 74
72 75
73 def _get_requested_page_for_route(app, route, route_metadata, req_path): 76 def _get_requested_page_for_route(app, route, route_metadata, req_path):
74 taxonomy = None 77 if not route.is_generator_route:
75 source = app.getSource(route.source_name) 78 source = app.getSource(route.source_name)
76 if route.taxonomy_name is None:
77 factory = source.findPageFactory(route_metadata, MODE_PARSING) 79 factory = source.findPageFactory(route_metadata, MODE_PARSING)
78 if factory is None: 80 if factory is None:
79 raise PageNotFoundError("No path found for '%s' in source '%s'." % 81 raise PageNotFoundError(
80 (req_path, source.name)) 82 "No path found for '%s' in source '%s'." %
83 (req_path, source.name))
81 else: 84 else:
82 taxonomy = app.getTaxonomy(route.taxonomy_name) 85 factory = route.generator.getPageFactory(route_metadata)
83 86 if factory is None:
84 # This will raise `PageNotFoundError` naturally if not found. 87 raise PageNotFoundError(
85 tax_page_ref = taxonomy.getPageRef(source) 88 "No path found for '%s' in generator '%s'." %
86 factory = tax_page_ref.getFactory() 89 (req_path, route.generator.name))
87 90
88 # Build the page. 91 # Build the page.
89 page = factory.buildPage() 92 page = factory.buildPage()
90 qp = QualifiedPage(page, route, route_metadata) 93 qp = QualifiedPage(page, route, route_metadata)
91 return qp 94 return qp