comparison piecrust/uriutil.py @ 298:b7ab1b503510

data: Fix incorrect next/previous page URLs in pagination data. Consolidate splitting an URL between its first URL and its sub page number. Be careful about the index page's URL not losing its slash.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 11 Mar 2015 23:46:42 -0700
parents 62c7a97c8340
children 422052d2e978
comparison
equal deleted inserted replaced
297:2823ea40cfac 298:b7ab1b503510
78 site_root = app.config.get('site/root') 78 site_root = app.config.get('site/root')
79 uri = uri[len(site_root):] 79 uri = uri[len(site_root):]
80 return uri.lstrip('/') 80 return uri.lstrip('/')
81 81
82 82
83 def get_first_sub_uri(app, uri): 83 def split_sub_uri(app, uri):
84 pretty_urls = app.config.get('site/pretty_urls') 84 pretty_urls = app.config.get('site/pretty_urls')
85 if not pretty_urls: 85 if not pretty_urls:
86 uri, ext = os.path.splitext(uri) 86 uri, ext = os.path.splitext(uri)
87 87
88 page_num = 1
88 pgn_suffix_re = app.config.get('__cache/pagination_suffix_re') 89 pgn_suffix_re = app.config.get('__cache/pagination_suffix_re')
89 m = re.search(pgn_suffix_re, uri) 90 m = re.search(pgn_suffix_re, uri)
90 if m: 91 if m:
91 uri = uri[:m.start()] 92 uri = uri[:m.start()]
93 if uri == '':
94 uri = '/'
95 page_num = int(m.group('num'))
92 96
93 if not pretty_urls: 97 if not pretty_urls:
94 uri += ext 98 uri += ext
95 99
96 return uri 100 return (uri, page_num)
97 101