comparison piecrust/sources/pageref.py @ 369:4b1019bb2533

serve: Giant refactor to change how we handle data when serving pages. * We need a distinction between source metadata and route metadata. In most cases they're the same, but in cases like taxonomy pages, route metadata contains more things that can't be in source metadata if we want to re-use cached pages. * Create a new `QualifiedPage` type which is a page with a specific route and route metadata. Pass this around in many places. * Instead of passing an URL around, use the route in the `QualifiedPage` to generate URLs. This is better since it removes the guess-work from trying to generate URLs for sub-pages. * Deep-copy app and page configurations before passing them around to things that could modify them, like data builders and such. * Exclude taxonomy pages from iterator data providers. * Properly nest iterator data providers for when the theme and user page sources are merged inside `site.pages`.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 03 May 2015 18:47:10 -0700
parents dd25bd3ce1f9
children e7b865f8f335
comparison
equal deleted inserted replaced
368:2408eb6f4da8 369:4b1019bb2533
1 import re 1 import re
2 import os.path 2 import os.path
3 import copy
3 from piecrust.sources.base import PageFactory 4 from piecrust.sources.base import PageFactory
4 5
5 6
6 page_ref_pattern = re.compile(r'(?P<src>[\w]+)\:(?P<path>.*?)(;|$)') 7 page_ref_pattern = re.compile(r'(?P<src>[\w]+)\:(?P<path>.*?)(;|$)')
7 8
72 def possible_paths(self): 73 def possible_paths(self):
73 self._load() 74 self._load()
74 return [h.path for h in self._hits] 75 return [h.path for h in self._hits]
75 76
76 def getFactory(self): 77 def getFactory(self):
77 return PageFactory(self.source, self.rel_path, self.metadata) 78 return PageFactory(self.source, self.rel_path,
79 copy.deepcopy(self.metadata))
78 80
79 @property 81 @property
80 def _first_valid_hit(self): 82 def _first_valid_hit(self):
81 return self._hits[self._first_valid_hit_index] 83 return self._hits[self._first_valid_hit_index]
82 84
93 source_name = m.group('src') 95 source_name = m.group('src')
94 source = self.app.getSource(source_name) 96 source = self.app.getSource(source_name)
95 if source is None: 97 if source is None:
96 raise Exception("No such source: %s" % source_name) 98 raise Exception("No such source: %s" % source_name)
97 rel_path = m.group('path') 99 rel_path = m.group('path')
98 path, metadata = source.resolveRef(rel_path)
99 if '%ext%' in rel_path: 100 if '%ext%' in rel_path:
100 for e in self._exts: 101 for e in self._exts:
102 cur_rel_path = rel_path.replace('%ext%', e)
103 path, metadata = source.resolveRef(cur_rel_path)
101 self._hits.append(self._HitInfo( 104 self._hits.append(self._HitInfo(
102 source_name, 105 source_name, cur_rel_path, path, metadata))
103 rel_path.replace('%ext%', e),
104 path.replace('%ext%', e),
105 metadata))
106 else: 106 else:
107 path, metadata = source.resolveRef(rel_path)
107 self._hits.append( 108 self._hits.append(
108 self._HitInfo(source_name, rel_path, path, metadata)) 109 self._HitInfo(source_name, rel_path, path, metadata))
109 110
110 def _checkHits(self): 111 def _checkHits(self):
111 if self._first_valid_hit_index >= 0: 112 if self._first_valid_hit_index >= 0: