comparison piecrust/sources/posts.py @ 841:f0930178fd01

internal: Make `posts` sources cache their list of pages.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 15 Feb 2017 22:17:54 -0800
parents 58ebf50235a5
children 4850f8c21b6e
comparison
equal deleted inserted replaced
840:7f3043f9f26f 841:f0930178fd01
20 class PostsSource(PageSource, IPreparingSource, IInteractiveSource, 20 class PostsSource(PageSource, IPreparingSource, IInteractiveSource,
21 SimplePaginationSourceMixin): 21 SimplePaginationSourceMixin):
22 PATH_FORMAT = None 22 PATH_FORMAT = None
23 23
24 def __init__(self, app, name, config): 24 def __init__(self, app, name, config):
25 super(PostsSource, self).__init__(app, name, config) 25 PageSource.__init__(self, app, name, config)
26 self.fs_endpoint = config.get('fs_endpoint', name) 26 self.fs_endpoint = config.get('fs_endpoint', name)
27 self.fs_endpoint_path = os.path.join(self.root_dir, self.fs_endpoint) 27 self.fs_endpoint_path = os.path.join(self.root_dir, self.fs_endpoint)
28 self.supported_extensions = list(app.config.get('site/auto_formats').keys()) 28 self.supported_extensions = list(app.config.get('site/auto_formats').keys())
29 self.default_auto_format = app.config.get('site/default_auto_format') 29 self.default_auto_format = app.config.get('site/default_auto_format')
30 self._source_it_cache = None
30 31
31 @property 32 @property
32 def path_format(self): 33 def path_format(self):
33 return self.__class__.PATH_FORMAT 34 return self.__class__.PATH_FORMAT
34 35
71 m.group(4), 72 m.group(4),
72 int(m.group(1)), 73 int(m.group(1)),
73 int(m.group(2)), 74 int(m.group(2)),
74 int(m.group(3))) 75 int(m.group(3)))
75 76
76
77 def findPageFactory(self, metadata, mode): 77 def findPageFactory(self, metadata, mode):
78 year = metadata.get('year') 78 year = metadata.get('year')
79 month = metadata.get('month') 79 month = metadata.get('month')
80 day = metadata.get('day') 80 day = metadata.get('day')
81 slug = metadata.get('slug') 81 slug = metadata.get('slug')
135 135
136 rel_path = os.path.relpath(path, self.fs_endpoint_path) 136 rel_path = os.path.relpath(path, self.fs_endpoint_path)
137 rel_path = rel_path.replace('\\', '/') 137 rel_path = rel_path.replace('\\', '/')
138 fac_metadata = self._parseMetadataFromPath(rel_path) 138 fac_metadata = self._parseMetadataFromPath(rel_path)
139 return PageFactory(self, rel_path, fac_metadata) 139 return PageFactory(self, rel_path, fac_metadata)
140
141 def getSourceIterator(self):
142 if self._source_it_cache is None:
143 it = SimplePaginationSourceMixin.getSourceIterator(self)
144 self._source_it_cache = list(it)
145 return self._source_it_cache
140 146
141 def setupPrepareParser(self, parser, app): 147 def setupPrepareParser(self, parser, app):
142 parser.add_argument( 148 parser.add_argument(
143 '-d', '--date', help="The date of the post, " 149 '-d', '--date', help="The date of the post, "
144 "in `year/month/day` format (defaults to today).") 150 "in `year/month/day` format (defaults to today).")