Mercurial > piecrust2
comparison piecrust/sources/default.py @ 989:8adc27285d93
bake: Big pass on bake performance.
- Reduce the amount of data passed between processes.
- Make inter-process data simple objects to make it easier to test with
alternatives to pickle.
- Make sources have the basic requirement to be able to find a content item
from an item spec (path).
- Make Hoedown the default Markdown formatter.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 19 Nov 2017 14:29:17 -0800 |
parents | 23052bf8a62b |
children | 4cc020ff2537 |
comparison
equal
deleted
inserted
replaced
988:f83ae0a5d793 | 989:8adc27285d93 |
---|---|
25 | 25 |
26 self.auto_formats = app.config.get('site/auto_formats') | 26 self.auto_formats = app.config.get('site/auto_formats') |
27 self.default_auto_format = app.config.get('site/default_auto_format') | 27 self.default_auto_format = app.config.get('site/default_auto_format') |
28 self.supported_extensions = list(self.auto_formats) | 28 self.supported_extensions = list(self.auto_formats) |
29 | 29 |
30 def _createItemMetadata(self, path): | |
31 return self._doCreateItemMetadata(path) | |
32 | |
33 def _finalizeContent(self, parent_group, items, groups): | 30 def _finalizeContent(self, parent_group, items, groups): |
34 SimpleAssetsSubDirMixin._removeAssetGroups(self, groups) | 31 SimpleAssetsSubDirMixin._removeAssetGroups(self, groups) |
35 | 32 |
36 def _doCreateItemMetadata(self, path): | 33 def _createItemMetadata(self, path): |
37 slug = self._makeSlug(path) | 34 slug = self._makeSlug(path) |
38 metadata = { | 35 metadata = { |
39 'route_params': { | 36 'route_params': { |
40 'slug': slug | 37 'slug': slug |
41 } | 38 } |
67 | 64 |
68 def getSupportedRouteParameters(self): | 65 def getSupportedRouteParameters(self): |
69 return [ | 66 return [ |
70 RouteParameter('slug', RouteParameter.TYPE_PATH)] | 67 RouteParameter('slug', RouteParameter.TYPE_PATH)] |
71 | 68 |
72 def findContent(self, route_params): | 69 def findContentFromRoute(self, route_params): |
73 uri_path = route_params.get('slug', '') | 70 uri_path = route_params.get('slug', '') |
74 if not uri_path: | 71 if not uri_path: |
75 uri_path = '_index' | 72 uri_path = '_index' |
76 path = os.path.join(self.fs_endpoint_path, uri_path) | 73 path = os.path.join(self.fs_endpoint_path, uri_path) |
77 _, ext = os.path.splitext(path) | 74 _, ext = os.path.splitext(path) |
82 for e in self.supported_extensions] | 79 for e in self.supported_extensions] |
83 else: | 80 else: |
84 paths_to_check = [path] | 81 paths_to_check = [path] |
85 for path in paths_to_check: | 82 for path in paths_to_check: |
86 if os.path.isfile(path): | 83 if os.path.isfile(path): |
87 metadata = self._doCreateItemMetadata(path) | 84 metadata = self._createItemMetadata(path) |
88 return ContentItem(path, metadata) | 85 return ContentItem(path, metadata) |
89 return None | 86 return None |
90 | |
91 def findContentFromPath(self, path): | |
92 metadata = self._doCreateItemMetadata(path) | |
93 return ContentItem(path, metadata) | |
94 | 87 |
95 def setupPrepareParser(self, parser, app): | 88 def setupPrepareParser(self, parser, app): |
96 parser.add_argument('slug', help='The slug for the new page.') | 89 parser.add_argument('slug', help='The slug for the new page.') |
97 | 90 |
98 def createContent(self, args): | 91 def createContent(self, args): |
102 path = os.path.join(self.fs_endpoint_path, slug) | 95 path = os.path.join(self.fs_endpoint_path, slug) |
103 _, ext = os.path.splitext(path) | 96 _, ext = os.path.splitext(path) |
104 if ext == '': | 97 if ext == '': |
105 path = '%s.%s' % (path, self.default_auto_format) | 98 path = '%s.%s' % (path, self.default_auto_format) |
106 | 99 |
107 metadata = self._doCreateItemMetadata(path) | 100 metadata = self._createItemMetadata(path) |
108 config = metadata.setdefault('config', {}) | 101 config = metadata.setdefault('config', {}) |
109 config.update({'title': uri_to_title( | 102 config.update({'title': uri_to_title( |
110 os.path.basename(metadata['slug']))}) | 103 os.path.basename(metadata['slug']))}) |
111 return ContentItem(path, metadata) | 104 return ContentItem(path, metadata) |
112 | 105 |