# HG changeset patch # User Ludovic Chabant # Date 1487225874 28800 # Node ID f0930178fd01206e67bc69de8da37c3652c84d33 # Parent 7f3043f9f26fde58fd5f44033e41c2a05338ea6d internal: Make `posts` sources cache their list of pages. diff -r 7f3043f9f26f -r f0930178fd01 piecrust/sources/posts.py --- a/piecrust/sources/posts.py Wed Feb 15 22:17:13 2017 -0800 +++ b/piecrust/sources/posts.py Wed Feb 15 22:17:54 2017 -0800 @@ -22,11 +22,12 @@ PATH_FORMAT = None def __init__(self, app, name, config): - super(PostsSource, self).__init__(app, name, config) + PageSource.__init__(self, app, name, config) self.fs_endpoint = config.get('fs_endpoint', name) self.fs_endpoint_path = os.path.join(self.root_dir, self.fs_endpoint) self.supported_extensions = list(app.config.get('site/auto_formats').keys()) self.default_auto_format = app.config.get('site/default_auto_format') + self._source_it_cache = None @property def path_format(self): @@ -73,7 +74,6 @@ int(m.group(2)), int(m.group(3))) - def findPageFactory(self, metadata, mode): year = metadata.get('year') month = metadata.get('month') @@ -138,6 +138,12 @@ fac_metadata = self._parseMetadataFromPath(rel_path) return PageFactory(self, rel_path, fac_metadata) + 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, "