Mercurial > piecrust2
comparison piecrust/appconfigdefaults.py @ 852:4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
* Everything is a `ContentSource`, including assets directories.
* Most content sources are subclasses of the base file-system source.
* A source is processed by a "pipeline", and there are 2 built-in pipelines,
one for assets and one for pages. The asset pipeline is vaguely functional,
but the page pipeline is completely broken right now.
* Rewrite the baking process as just running appropriate pipelines on each
content item. This should allow for better parallelization.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 17 May 2017 00:11:48 -0700 |
parents | fd694f1297c7 |
children | 86994e076be4 |
comparison
equal
deleted
inserted
replaced
851:2c7e57d80bba | 852:4850f8c21b6e |
---|---|
2 from piecrust import ( | 2 from piecrust import ( |
3 DEFAULT_FORMAT, DEFAULT_TEMPLATE_ENGINE, DEFAULT_POSTS_FS, | 3 DEFAULT_FORMAT, DEFAULT_TEMPLATE_ENGINE, DEFAULT_POSTS_FS, |
4 DEFAULT_DATE_FORMAT, DEFAULT_THEME_SOURCE) | 4 DEFAULT_DATE_FORMAT, DEFAULT_THEME_SOURCE) |
5 from piecrust.configuration import ( | 5 from piecrust.configuration import ( |
6 get_dict_values, try_get_dict_values) | 6 get_dict_values, try_get_dict_values) |
7 from piecrust.sources.base import REALM_THEME | 7 |
8 | 8 |
9 | 9 # Default configuration for all websites. |
10 # | |
10 default_configuration = collections.OrderedDict({ | 11 default_configuration = collections.OrderedDict({ |
11 'site': collections.OrderedDict({ | 12 'site': collections.OrderedDict({ |
12 'title': "Untitled PieCrust website", | 13 'title': "Untitled PieCrust website", |
13 'root': '/', | 14 'root': '/', |
14 'default_format': DEFAULT_FORMAT, | 15 'default_format': DEFAULT_FORMAT, |
15 'default_template_engine': DEFAULT_TEMPLATE_ENGINE, | 16 'default_template_engine': DEFAULT_TEMPLATE_ENGINE, |
16 'enable_gzip': True, | |
17 'pretty_urls': False, | 17 'pretty_urls': False, |
18 'trailing_slash': False, | 18 'trailing_slash': False, |
19 'date_format': DEFAULT_DATE_FORMAT, | 19 'date_format': DEFAULT_DATE_FORMAT, |
20 'auto_formats': collections.OrderedDict([ | 20 'auto_formats': collections.OrderedDict([ |
21 ('html', ''), | 21 ('html', ''), |
22 ('md', 'markdown'), | 22 ('md', 'markdown'), |
23 ('textile', 'textile')]), | 23 ('textile', 'textile')]), |
24 'default_auto_format': 'md', | 24 'default_auto_format': 'md', |
25 'default_pagination_source': None, | 25 'default_pagination_source': None, |
26 'pagination_suffix': '/%num%', | 26 'pagination_suffix': '/%num%', |
27 'asset_url_format': '%uri%', | |
27 'slugify_mode': 'encode', | 28 'slugify_mode': 'encode', |
28 'themes_sources': [DEFAULT_THEME_SOURCE], | 29 'themes_sources': [DEFAULT_THEME_SOURCE], |
29 'cache_time': 28800, | |
30 'enable_debug_info': True, | |
31 'show_debug_info': False, | |
32 'use_default_content': True, | 30 'use_default_content': True, |
33 'use_default_theme_content': True, | 31 'use_default_theme_content': True, |
34 'theme_site': False | 32 'theme_site': False |
35 }), | 33 }), |
36 'baker': collections.OrderedDict({ | 34 'baker': collections.OrderedDict({ |
37 'no_bake_setting': 'draft', | 35 'no_bake_setting': 'draft', |
38 'workers': None, | 36 'workers': None, |
39 'batch_size': None | 37 'batch_size': None |
38 }), | |
39 'server': collections.OrderedDict({ | |
40 'enable_gzip': True, | |
41 'cache_time': 28800, | |
42 'enable_debug_info': True, | |
43 'show_debug_info': False | |
40 }) | 44 }) |
41 }) | 45 }) |
42 | 46 |
43 | 47 |
48 # Default content model for themes. | |
49 # | |
44 default_theme_content_model_base = collections.OrderedDict({ | 50 default_theme_content_model_base = collections.OrderedDict({ |
45 'site': collections.OrderedDict({ | 51 'site': collections.OrderedDict({ |
46 'sources': collections.OrderedDict({ | 52 'sources': collections.OrderedDict({ |
47 'theme_pages': { | 53 'theme_pages': { |
48 'type': 'default', | |
49 'ignore_missing_dir': True, | |
50 'fs_endpoint': 'pages', | 54 'fs_endpoint': 'pages', |
55 'ignore_missing_dir': True, | |
51 'data_endpoint': 'site.pages', | 56 'data_endpoint': 'site.pages', |
52 'default_layout': 'default', | |
53 'item_name': 'page', | 57 'item_name': 'page', |
54 'realm': REALM_THEME | 58 }, |
59 'theme_assets': { | |
60 'fs_endpoint': 'assets', | |
61 'ignore_missing_dir': True, | |
62 'type': 'fs', | |
63 'pipeline': 'asset' | |
55 } | 64 } |
56 }), | 65 }), |
57 'routes': [ | 66 'routes': [ |
58 { | 67 { |
59 'url': '/%slug%', | 68 'url': '/%slug%', |
60 'source': 'theme_pages', | 69 'source': 'theme_pages', |
61 'func': 'pcurl' | 70 'func': 'pcurl' |
62 } | 71 } |
63 ], | 72 ] |
64 'theme_tag_page': 'theme_pages:_tag.%ext%', | |
65 'theme_category_page': 'theme_pages:_category.%ext%', | |
66 'theme_month_page': 'theme_pages:_month.%ext%', | |
67 'theme_year_page': 'theme_pages:_year.%ext%' | |
68 }) | 73 }) |
69 }) | 74 }) |
70 | 75 |
71 | 76 |
77 # Additional theme configuration when previewing a theme by itself, | |
78 # so it can show some "sample/preview" content. | |
79 # | |
80 default_theme_preview_content_model = collections.OrderedDict({ | |
81 'site': collections.OrderedDict({ | |
82 'sources': collections.OrderedDict({ | |
83 'theme_preview_pages': { | |
84 'fs_endpoint': 'preview/pages', | |
85 'ignore_missing_dir': True, | |
86 'data_endpoint': 'site.pages', | |
87 'item_name': 'page', | |
88 }, | |
89 'theme_preview_posts': { | |
90 'fs_endpoint': 'preview/posts', | |
91 'ignore_missing_dir': True, | |
92 'data_endpoint': 'blog.posts', | |
93 'item_name': 'post' | |
94 } | |
95 }), | |
96 'routes': [ | |
97 { | |
98 'url': '/posts/%year%/%month%/%slug%', | |
99 'source': 'theme_preview_posts' | |
100 }, | |
101 { | |
102 'url': '/%slug%', | |
103 'source': 'theme_preview_pages', | |
104 'func': 'pcurl' | |
105 } | |
106 ] | |
107 }) | |
108 }) | |
109 | |
110 | |
111 # Default content model for websites. | |
112 # | |
72 default_content_model_base = collections.OrderedDict({ | 113 default_content_model_base = collections.OrderedDict({ |
73 'site': collections.OrderedDict({ | 114 'site': collections.OrderedDict({ |
74 'posts_fs': DEFAULT_POSTS_FS, | 115 'posts_fs': DEFAULT_POSTS_FS, |
75 'default_page_layout': 'default', | 116 'default_page_layout': 'default', |
76 'default_post_layout': 'post', | 117 'default_post_layout': 'post', |
77 'post_url': '/%year%/%month%/%day%/%slug%', | 118 'post_url': '/%year%/%month%/%day%/%slug%', |
78 'year_url': '/archives/%year%', | 119 'year_url': '/archives/%year%', |
79 'tag_url': '/tag/%tag%', | 120 'tag_url': '/tag/%tag%', |
121 'tag_feed_url': '/tag/%tag%.xml', | |
80 'category_url': '/%category%', | 122 'category_url': '/%category%', |
81 'posts_per_page': 5 | 123 'category_feed_url': '/%category%.xml', |
124 'posts_per_page': 5, | |
125 'sources': { | |
126 'assets': { | |
127 'fs_endpoint': 'assets', | |
128 'ignore_missing_dir': True, | |
129 'type': 'fs', | |
130 'pipeline': 'asset' | |
131 } | |
132 } | |
82 }) | 133 }) |
83 }) | 134 }) |
84 | 135 |
85 | 136 |
86 def get_default_content_model(site_values, values): | 137 def get_default_content_model(site_values, values): |
172 posts_per_page = blog_values['posts_per_page'] | 223 posts_per_page = blog_values['posts_per_page'] |
173 date_format = blog_values['date_format'] | 224 date_format = blog_values['date_format'] |
174 default_layout = blog_values['default_post_layout'] | 225 default_layout = blog_values['default_post_layout'] |
175 post_url = '/' + url_prefix + blog_values['post_url'].lstrip('/') | 226 post_url = '/' + url_prefix + blog_values['post_url'].lstrip('/') |
176 year_url = '/' + url_prefix + blog_values['year_url'].lstrip('/') | 227 year_url = '/' + url_prefix + blog_values['year_url'].lstrip('/') |
177 | 228 year_archive_tpl = '%s_year.html' % page_prefix |
178 year_archive = 'pages:%s_year.%%ext%%' % page_prefix | |
179 if not theme_site: | |
180 theme_year_page = try_get_dict_values( | |
181 (site_values, 'site/theme_year_page'), | |
182 (values, 'site/theme_year_page')) | |
183 if theme_year_page: | |
184 year_archive += ';' + theme_year_page | |
185 | 229 |
186 cfg = collections.OrderedDict({ | 230 cfg = collections.OrderedDict({ |
187 'site': collections.OrderedDict({ | 231 'site': collections.OrderedDict({ |
188 'sources': collections.OrderedDict({ | 232 'sources': collections.OrderedDict({ |
189 blog_name: collections.OrderedDict({ | 233 blog_name: collections.OrderedDict({ |
194 'ignore_missing_dir': True, | 238 'ignore_missing_dir': True, |
195 'data_type': 'blog', | 239 'data_type': 'blog', |
196 'items_per_page': posts_per_page, | 240 'items_per_page': posts_per_page, |
197 'date_format': date_format, | 241 'date_format': date_format, |
198 'default_layout': default_layout | 242 'default_layout': default_layout |
199 }) | 243 }), |
200 }), | 244 '%s_archives' % blog_name: collections.OrderedDict({ |
201 'generators': collections.OrderedDict({ | |
202 ('%s_archives' % blog_name): collections.OrderedDict({ | |
203 'type': 'blog_archives', | 245 'type': 'blog_archives', |
204 'source': blog_name, | 246 'source': blog_name, |
205 'page': year_archive | 247 'template': year_archive_tpl |
206 }) | 248 }) |
207 }), | 249 }), |
208 'routes': [ | 250 'routes': [ |
209 { | 251 { |
210 'url': post_url, | 252 'url': post_url, |
211 'source': blog_name, | 253 'source': blog_name, |
212 'func': ('%sposturl' % tpl_func_prefix) | 254 'func': ('%sposturl' % tpl_func_prefix) |
213 }, | 255 }, |
214 { | 256 { |
215 'url': year_url, | 257 'url': year_url, |
216 'generator': ('%s_archives' % blog_name), | 258 'source': ('%s_archives' % blog_name), |
217 'func': ('%syearurl' % tpl_func_prefix) | 259 'func': ('%syearurl' % tpl_func_prefix) |
218 } | 260 } |
219 ] | 261 ] |
220 }) | 262 }) |
221 }) | 263 }) |
222 | 264 |
223 # Add a generator and a route for each taxonomy. | 265 # Add a source and a route for each taxonomy. |
224 taxonomies_cfg = try_get_dict_values( | 266 taxonomies_cfg = try_get_dict_values( |
225 (site_values, 'site/taxonomies'), | 267 (site_values, 'site/taxonomies'), |
226 (values, 'site/taxonomies'), | 268 (values, 'site/taxonomies'), |
227 default={}).copy() | 269 default={}).copy() |
228 for tax_name, tax_cfg in taxonomies_cfg.items(): | 270 for tax_name, tax_cfg in taxonomies_cfg.items(): |
229 term = tax_cfg.get('term', tax_name) | 271 term = tax_cfg.get('term', tax_name) |
230 | 272 |
231 # Generator. | 273 # Source. |
232 page_ref = 'pages:%s_%s.%%ext%%' % (page_prefix, term) | 274 term_tpl = '%s_%s.html' % (page_prefix, term) |
233 if not theme_site: | 275 tax_src_name = '%s_%s' % (blog_name, tax_name) |
234 theme_page_ref = try_get_dict_values( | 276 tax_src = collections.OrderedDict({ |
235 (site_values, 'site/theme_%s_page' % term), | |
236 (values, 'site/theme_%s_page' % term)) | |
237 if theme_page_ref: | |
238 page_ref += ';' + theme_page_ref | |
239 tax_gen_name = '%s_%s' % (blog_name, tax_name) | |
240 tax_gen = collections.OrderedDict({ | |
241 'type': 'taxonomy', | 277 'type': 'taxonomy', |
242 'source': blog_name, | 278 'source': blog_name, |
243 'taxonomy': tax_name, | 279 'taxonomy': tax_name, |
244 'page': page_ref | 280 'template': term_tpl |
245 }) | 281 }) |
246 cfg['site']['generators'][tax_gen_name] = tax_gen | 282 cfg['site']['sources'][tax_src_name] = tax_src |
247 | 283 |
248 # Route. | 284 # Route. |
249 tax_url_cfg_name = '%s_url' % term | 285 tax_url_cfg_name = '%s_url' % term |
250 tax_url = try_get_dict_values( | 286 tax_url = try_get_dict_values( |
251 (blog_cfg, tax_url_cfg_name), | 287 (blog_cfg, tax_url_cfg_name), |
257 (site_values, 'site/taxonomies/%s/func_name' % tax_name), | 293 (site_values, 'site/taxonomies/%s/func_name' % tax_name), |
258 (values, 'site/taxonomies/%s/func_name' % tax_name), | 294 (values, 'site/taxonomies/%s/func_name' % tax_name), |
259 default=('%s%surl' % (tpl_func_prefix, term))) | 295 default=('%s%surl' % (tpl_func_prefix, term))) |
260 tax_route = collections.OrderedDict({ | 296 tax_route = collections.OrderedDict({ |
261 'url': tax_url, | 297 'url': tax_url, |
262 'generator': tax_gen_name, | 298 'pass': 2, |
263 'taxonomy': tax_name, | 299 'source': tax_src_name, |
264 'func': tax_func_name | 300 'func': tax_func_name |
265 }) | 301 }) |
266 cfg['site']['routes'].append(tax_route) | 302 cfg['site']['routes'].append(tax_route) |
267 | 303 |
268 return cfg | 304 return cfg |