comparison piecrust/app.py @ 256:da5e6e00fb41

bake/serve: Make previewed and baked URLs consistent. The preview server now handles the `pretty_urls` setting correctly instead of forcing it. The `trailing_slash` and `pagination_suffix` setting are also doing the same between the 2 systems.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 22 Feb 2015 22:01:58 -0800
parents 016d42c23ba9
children e6ae65212c32
comparison
equal deleted inserted replaced
250:311447fe3dd0 256:da5e6e00fb41
106 'root': '/', 106 'root': '/',
107 'default_format': DEFAULT_FORMAT, 107 'default_format': DEFAULT_FORMAT,
108 'default_template_engine': DEFAULT_TEMPLATE_ENGINE, 108 'default_template_engine': DEFAULT_TEMPLATE_ENGINE,
109 'enable_gzip': True, 109 'enable_gzip': True,
110 'pretty_urls': False, 110 'pretty_urls': False,
111 'slugify': 'transliterate|lowercase', 111 'trailing_slash': False,
112 'timezone': False,
113 'locale': False,
114 'date_format': DEFAULT_DATE_FORMAT, 112 'date_format': DEFAULT_DATE_FORMAT,
115 'auto_formats': collections.OrderedDict([ 113 'auto_formats': collections.OrderedDict([
116 ('html', ''), 114 ('html', ''),
117 ('md', 'markdown'), 115 ('md', 'markdown'),
118 ('textile', 'textile')]), 116 ('textile', 'textile')]),
119 'default_auto_format': 'md', 117 'default_auto_format': 'md',
120 'pagination_suffix': '/%num%', 118 'pagination_suffix': '/%num%',
121 'plugins_sources': [DEFAULT_PLUGIN_SOURCE], 119 'plugins_sources': [DEFAULT_PLUGIN_SOURCE],
122 'themes_sources': [DEFAULT_THEME_SOURCE], 120 'themes_sources': [DEFAULT_THEME_SOURCE],
123 'cache_time': 28800, 121 'cache_time': 28800,
124 'display_errors': True,
125 'enable_debug_info': True, 122 'enable_debug_info': True,
126 'show_debug_info': False, 123 'show_debug_info': False,
127 'use_default_content': True 124 'use_default_content': True
128 }) 125 })
129 sitec = values.get('site') 126 sitec = values.get('site')
147 '|'.join( 144 '|'.join(
148 [re.escape(i) for i in list(sitec['auto_formats'].keys())])) 145 [re.escape(i) for i in list(sitec['auto_formats'].keys())]))
149 if sitec['default_auto_format'] not in sitec['auto_formats']: 146 if sitec['default_auto_format'] not in sitec['auto_formats']:
150 raise ConfigurationError("Default auto-format '%s' is not declared." % sitec['default_auto_format']) 147 raise ConfigurationError("Default auto-format '%s' is not declared." % sitec['default_auto_format'])
151 148
152 # Cache pagination suffix regex. 149 # Cache pagination suffix regex and format.
153 pgn_suffix = re.escape(sitec['pagination_suffix']) 150 pgn_suffix = sitec['pagination_suffix']
154 pgn_suffix = pgn_suffix.replace("\\%num\\%", "(?P<num>\\d+)") + '$' 151 if len(pgn_suffix) == 0 or pgn_suffix[0] != '/':
155 cachec['pagination_suffix_re'] = pgn_suffix 152 raise ConfigurationError("The 'site/pagination_suffix' setting "
153 "must start with a slash.")
154 if '%num%' not in pgn_suffix:
155 raise ConfigurationError("The 'site/pagination_suffix' setting "
156 "must contain the '%num%' placeholder.")
157
158 pgn_suffix_fmt = pgn_suffix.replace('%num%', '%(num)d')
159 cachec['pagination_suffix_format'] = pgn_suffix_fmt
160
161 pgn_suffix_re = re.escape(pgn_suffix)
162 pgn_suffix_re = (pgn_suffix_re.replace("\\%num\\%", "(?P<num>\\d+)") +
163 '$')
164 cachec['pagination_suffix_re'] = pgn_suffix_re
156 165
157 # Make sure plugins and theme sources are lists. 166 # Make sure plugins and theme sources are lists.
158 if not isinstance(sitec['plugins_sources'], list): 167 if not isinstance(sitec['plugins_sources'], list):
159 sitec['plugins_sources'] = [sitec['plugins_sources']] 168 sitec['plugins_sources'] = [sitec['plugins_sources']]
160 if not isinstance(sitec['themes_sources'], list): 169 if not isinstance(sitec['themes_sources'], list):