diff piecrust/sources/posts.py @ 853:f070a4fc033c

core: Continue PieCrust3 refactor, simplify pages. The asset pipeline is still the only function pipeline at this point. * No more `QualifiedPage`, and several other pieces of code deleted. * Data providers are simpler and more focused. For instance, the page iterator doesn't try to support other types of items. * Route parameters are proper known source metadata to remove the confusion between the two. * Make the baker and pipeline more correctly manage records and record histories. * Add support for record collapsing and deleting stale outputs in the asset pipeline.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 21 May 2017 00:06:59 -0700
parents 4850f8c21b6e
children 08e02c2a2a1a
line wrap: on
line diff
--- a/piecrust/sources/posts.py	Wed May 17 00:11:48 2017 -0700
+++ b/piecrust/sources/posts.py	Sun May 21 00:06:59 2017 -0700
@@ -10,8 +10,7 @@
     FSContentSource, InvalidFileSystemEndpointError)
 from piecrust.sources.interfaces import (
     IPreparingSource, IInteractiveSource, InteractiveField)
-from piecrust.sources.mixins import (
-    SimplePaginationSourceMixin, SimpleAssetsSubDirMixin)
+from piecrust.sources.mixins import SimpleAssetsSubDirMixin
 from piecrust.uriutil import uri_to_title
 
 
@@ -24,7 +23,10 @@
     PATH_FORMAT = None
 
     def __init__(self, app, name, config):
-        FSContentSource.__init__(self, app, name, config)
+        super().__init__(app, name, config)
+
+        config.setdefault('data_type', 'page_iterator')
+
         self.auto_formats = app.config.get('site/auto_formats')
         self.default_auto_format = app.config.get('site/default_auto_format')
         self.supported_extensions = list(self.auto_formats)
@@ -135,12 +137,6 @@
             RouteParameter('month', RouteParameter.TYPE_INT2),
             RouteParameter('year', RouteParameter.TYPE_INT4)]
 
-    def getSourceIterator(self):
-        if self._source_it_cache is None:
-            it = SimplePaginationSourceMixin.getSourceIterator(self)
-            self._source_it_cache = list(it)
-        return self._source_it_cache
-
     def setupPrepareParser(self, parser, app):
         parser.add_argument(
             '-d', '--date', help="The date of the post, "
@@ -201,15 +197,24 @@
                                                  self.fs_endpoint_path)
         return True
 
-    def _makeContentItem(self, path, slug, year, month, day):
-        path = path.replace('\\', '/')
+    def _makeContentItem(self, rel_path, slug, year, month, day):
+        path = os.path.join(self.fs_endpoint_path, rel_path)
         timestamp = datetime.date(year, month, day)
         metadata = {
-            'slug': slug,
-            'year': year,
-            'month': month,
-            'day': day,
-            'date': timestamp}
+            'route_params': {
+                'slug': slug,
+                'year': year,
+                'month': month,
+                'day': day},
+            'date': timestamp
+        }
+
+        _, ext = os.path.splitext(path)
+        if ext:
+            fmt = self.auto_formats.get(ext.lstrip('.'))
+            if fmt:
+                metadata['config'] = {'format': fmt}
+
         return ContentItem(path, metadata)