diff 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
line wrap: on
line diff
--- a/piecrust/sources/default.py	Sun Apr 26 08:34:27 2015 -0700
+++ b/piecrust/sources/default.py	Sun Apr 26 15:07:40 2015 -0700
@@ -55,10 +55,14 @@
                 yield PageFactory(self, fac_path, metadata)
 
     def resolveRef(self, ref_path):
-        return os.path.normpath(
+        path = os.path.normpath(
                 os.path.join(self.fs_endpoint_path, ref_path.lstrip("\\/")))
+        slug = self._makeSlug(ref_path)
+        metadata = {'slug': slug}
+        self._populateMetadata(ref_path, metadata)
+        return path, metadata
 
-    def findPagePath(self, metadata, mode):
+    def findPageFactory(self, metadata, mode):
         uri_path = metadata.get('slug', '')
         if not uri_path:
             uri_path = '_index'
@@ -71,7 +75,7 @@
             rel_path = os.path.relpath(path, self.fs_endpoint_path)
             rel_path = rel_path.replace('\\', '/')
             self._populateMetadata(rel_path, metadata, mode)
-            return rel_path, metadata
+            return PageFactory(self, rel_path, metadata)
 
         if ext == '':
             paths_to_check = [
@@ -84,9 +88,9 @@
                 rel_path = os.path.relpath(path, self.fs_endpoint_path)
                 rel_path = rel_path.replace('\\', '/')
                 self._populateMetadata(rel_path, metadata, mode)
-                return rel_path, metadata
+                return PageFactory(self, rel_path, metadata)
 
-        return None, None
+        return None
 
     def listPath(self, rel_path):
         rel_path = rel_path.lstrip('\\/')