comparison piecrust/sources/default.py @ 363:dd25bd3ce1f9

serve: Refactoring and fixes to be able to serve taxonomy pages. * Page sources' `findPagePath` is renamed to `findPageFactory`, so that it also returns source metadata. * Page refs now store possible hits more properly, and use the previous point to also store metadata. As a result, they can also return a proper factory. * Implement `findPageFactory` correctly in all built-in sources. * When the Chef server matches a taxonomy page, get the source metadata from the page ref in order to make a more proper page. * Make the `getRoute(s)` functions explicitely say if they want taxonomy routes or not.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 26 Apr 2015 15:07:40 -0700
parents f130365568ff
children 81d2fd526c82
comparison
equal deleted inserted replaced
362:ff595828a364 363:dd25bd3ce1f9
53 fac_path = fac_path.replace('\\', '/') 53 fac_path = fac_path.replace('\\', '/')
54 self._populateMetadata(fac_path, metadata) 54 self._populateMetadata(fac_path, metadata)
55 yield PageFactory(self, fac_path, metadata) 55 yield PageFactory(self, fac_path, metadata)
56 56
57 def resolveRef(self, ref_path): 57 def resolveRef(self, ref_path):
58 return os.path.normpath( 58 path = os.path.normpath(
59 os.path.join(self.fs_endpoint_path, ref_path.lstrip("\\/"))) 59 os.path.join(self.fs_endpoint_path, ref_path.lstrip("\\/")))
60 slug = self._makeSlug(ref_path)
61 metadata = {'slug': slug}
62 self._populateMetadata(ref_path, metadata)
63 return path, metadata
60 64
61 def findPagePath(self, metadata, mode): 65 def findPageFactory(self, metadata, mode):
62 uri_path = metadata.get('slug', '') 66 uri_path = metadata.get('slug', '')
63 if not uri_path: 67 if not uri_path:
64 uri_path = '_index' 68 uri_path = '_index'
65 path = os.path.join(self.fs_endpoint_path, uri_path) 69 path = os.path.join(self.fs_endpoint_path, uri_path)
66 _, ext = os.path.splitext(path) 70 _, ext = os.path.splitext(path)
69 if ext == '': 73 if ext == '':
70 path = '%s.%s' % (path, self.default_auto_format) 74 path = '%s.%s' % (path, self.default_auto_format)
71 rel_path = os.path.relpath(path, self.fs_endpoint_path) 75 rel_path = os.path.relpath(path, self.fs_endpoint_path)
72 rel_path = rel_path.replace('\\', '/') 76 rel_path = rel_path.replace('\\', '/')
73 self._populateMetadata(rel_path, metadata, mode) 77 self._populateMetadata(rel_path, metadata, mode)
74 return rel_path, metadata 78 return PageFactory(self, rel_path, metadata)
75 79
76 if ext == '': 80 if ext == '':
77 paths_to_check = [ 81 paths_to_check = [
78 '%s.%s' % (path, e) 82 '%s.%s' % (path, e)
79 for e in self.supported_extensions] 83 for e in self.supported_extensions]
82 for path in paths_to_check: 86 for path in paths_to_check:
83 if os.path.isfile(path): 87 if os.path.isfile(path):
84 rel_path = os.path.relpath(path, self.fs_endpoint_path) 88 rel_path = os.path.relpath(path, self.fs_endpoint_path)
85 rel_path = rel_path.replace('\\', '/') 89 rel_path = rel_path.replace('\\', '/')
86 self._populateMetadata(rel_path, metadata, mode) 90 self._populateMetadata(rel_path, metadata, mode)
87 return rel_path, metadata 91 return PageFactory(self, rel_path, metadata)
88 92
89 return None, None 93 return None
90 94
91 def listPath(self, rel_path): 95 def listPath(self, rel_path):
92 rel_path = rel_path.lstrip('\\/') 96 rel_path = rel_path.lstrip('\\/')
93 path = os.path.join(self.fs_endpoint_path, rel_path) 97 path = os.path.join(self.fs_endpoint_path, rel_path)
94 names = sorted(os.listdir(path)) 98 names = sorted(os.listdir(path))