diff 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
line wrap: on
line diff
--- a/piecrust/app.py	Fri Feb 20 23:44:23 2015 -0800
+++ b/piecrust/app.py	Sun Feb 22 22:01:58 2015 -0800
@@ -108,9 +108,7 @@
                 'default_template_engine': DEFAULT_TEMPLATE_ENGINE,
                 'enable_gzip': True,
                 'pretty_urls': False,
-                'slugify': 'transliterate|lowercase',
-                'timezone': False,
-                'locale': False,
+                'trailing_slash': False,
                 'date_format': DEFAULT_DATE_FORMAT,
                 'auto_formats': collections.OrderedDict([
                     ('html', ''),
@@ -121,7 +119,6 @@
                 'plugins_sources': [DEFAULT_PLUGIN_SOURCE],
                 'themes_sources': [DEFAULT_THEME_SOURCE],
                 'cache_time': 28800,
-                'display_errors': True,
                 'enable_debug_info': True,
                 'show_debug_info': False,
                 'use_default_content': True
@@ -149,10 +146,22 @@
         if sitec['default_auto_format'] not in sitec['auto_formats']:
             raise ConfigurationError("Default auto-format '%s' is not declared." % sitec['default_auto_format'])
 
-        # Cache pagination suffix regex.
-        pgn_suffix = re.escape(sitec['pagination_suffix'])
-        pgn_suffix = pgn_suffix.replace("\\%num\\%", "(?P<num>\\d+)") + '$'
-        cachec['pagination_suffix_re'] = pgn_suffix
+        # Cache pagination suffix regex and format.
+        pgn_suffix = sitec['pagination_suffix']
+        if len(pgn_suffix) == 0 or pgn_suffix[0] != '/':
+            raise ConfigurationError("The 'site/pagination_suffix' setting "
+                                     "must start with a slash.")
+        if '%num%' not in pgn_suffix:
+            raise ConfigurationError("The 'site/pagination_suffix' setting "
+                                     "must contain the '%num%' placeholder.")
+
+        pgn_suffix_fmt = pgn_suffix.replace('%num%', '%(num)d')
+        cachec['pagination_suffix_format'] = pgn_suffix_fmt
+
+        pgn_suffix_re = re.escape(pgn_suffix)
+        pgn_suffix_re = (pgn_suffix_re.replace("\\%num\\%", "(?P<num>\\d+)") +
+                         '$')
+        cachec['pagination_suffix_re'] = pgn_suffix_re
 
         # Make sure plugins and theme sources are lists.
         if not isinstance(sitec['plugins_sources'], list):