diff piecrust/uriutil.py @ 33:62c7a97c8340

Get the un-paginated URL of a page early and pass that around.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 19 Aug 2014 15:36:28 -0700
parents 30a42341cfa8
children b7ab1b503510
line wrap: on
line diff
--- a/piecrust/uriutil.py	Tue Aug 19 14:30:19 2014 -0700
+++ b/piecrust/uriutil.py	Tue Aug 19 15:36:28 2014 -0700
@@ -1,4 +1,5 @@
 import re
+import os.path
 import string
 import logging
 import functools
@@ -78,3 +79,19 @@
     uri = uri[len(site_root):]
     return uri.lstrip('/')
 
+
+def get_first_sub_uri(app, uri):
+    pretty_urls = app.config.get('site/pretty_urls')
+    if not pretty_urls:
+        uri, ext = os.path.splitext(uri)
+
+    pgn_suffix_re = app.config.get('__cache/pagination_suffix_re')
+    m = re.search(pgn_suffix_re, uri)
+    if m:
+        uri = uri[:m.start()]
+
+    if not pretty_urls:
+        uri += ext
+
+    return uri
+