mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
tweak paginator to accomodate {slug}.html patterns
This commit is contained in:
parent
461f535d04
commit
a78950bce7
5 changed files with 33 additions and 30 deletions
|
|
@ -8,6 +8,8 @@ Next release
|
|||
* Replace Fabric by Invoke and ``fabfile.py`` template by ``tasks.py``.
|
||||
* Replace ``SLUG_SUBSTITUTIONS`` (and friends) by ``SLUG_REGEX_SUBSTITUTIONS``
|
||||
for more finegrained control
|
||||
* ``'{base_name}'`` value in ``PAGINATION_PATTERNS`` setting no longer strips
|
||||
``'bar'`` from ``'foo/bar.html'`` (unless ``'bar' == 'index'``).
|
||||
|
||||
3.7.1 (2017-01-10)
|
||||
==================
|
||||
|
|
|
|||
|
|
@ -994,7 +994,10 @@ You can use the following settings to configure the pagination.
|
|||
The templates to use pagination with, and the number of articles to include
|
||||
on a page. If this value is ``None``, it defaults to ``DEFAULT_PAGINATION``.
|
||||
|
||||
.. data:: PAGINATION_PATTERNS
|
||||
.. data:: PAGINATION_PATTERNS = (
|
||||
(1, '{name}{extension}', '{name}{extension}'),
|
||||
(2, '{name}{number}{extension}', '{name}{number}{extension}'),
|
||||
)
|
||||
|
||||
A set of patterns that are used to determine advanced pagination output.
|
||||
|
||||
|
|
@ -1002,25 +1005,28 @@ You can use the following settings to configure the pagination.
|
|||
Using Pagination Patterns
|
||||
-------------------------
|
||||
|
||||
The ``PAGINATION_PATTERNS`` setting can be used to configure where
|
||||
subsequent pages are created. The setting is a sequence of three
|
||||
element tuples, where each tuple consists of::
|
||||
By default, pages subsequent to ``.../foo.html`` are created as
|
||||
``.../foo2.html``, etc. The ``PAGINATION_PATTERNS`` setting can be used to
|
||||
change this. It takes a sequence of triples, where each triple consists of::
|
||||
|
||||
(minimum page, URL setting, SAVE_AS setting,)
|
||||
(minimum_page, page_url, page_save_as,)
|
||||
|
||||
For example, if you wanted the first page to just be ``/``, and the
|
||||
second (and subsequent) pages to be ``/page/2/``, you would set
|
||||
``PAGINATION_PATTERNS`` as follows::
|
||||
For ``page_url`` and ``page_save_as``, you may use a number of variables.
|
||||
``{url}`` and ``{save_as}`` correspond respectively to the ``*_URL`` and
|
||||
``*_SAVE_AS`` values of the corresponding page type (e.g. ``ARTICLE_SAVE_AS``).
|
||||
If ``{save_as} == foo/bar.html``, then ``{name} == foo/bar`` and
|
||||
``{extension} == .html``. ``{base_name}`` equals ``{name}`` except that it
|
||||
strips trailing ``/index`` if present. ``{number}`` equals the page number.
|
||||
|
||||
For example, if you want to leave the first page unchanged, but place
|
||||
subsequent pages at ``.../page/2/`` etc, you could set ``PAGINATION_PATTERNS``
|
||||
as follows::
|
||||
|
||||
PAGINATION_PATTERNS = (
|
||||
(1, '{base_name}/', '{base_name}/index.html'),
|
||||
(1, '{url}', '{save_as}`,
|
||||
(2, '{base_name}/page/{number}/', '{base_name}/page/{number}/index.html'),
|
||||
)
|
||||
|
||||
This would cause the first page to be written to
|
||||
``{base_name}/index.html``, and subsequent ones would be written into
|
||||
``page/{number}`` directories.
|
||||
|
||||
|
||||
Translations
|
||||
============
|
||||
|
|
|
|||
|
|
@ -66,7 +66,10 @@ class Paginator(object):
|
|||
|
||||
class Page(object):
|
||||
def __init__(self, name, url, object_list, number, paginator, settings):
|
||||
self.full_name = name
|
||||
self.name, self.extension = os.path.splitext(name)
|
||||
dn, fn = os.path.split(name)
|
||||
self.base_name = dn if fn in ('index.htm', 'index.html') else self.name
|
||||
self.base_url = url
|
||||
self.object_list = object_list
|
||||
self.number = number
|
||||
|
|
@ -134,25 +137,16 @@ class Page(object):
|
|||
|
||||
# URL or SAVE_AS is a string, format it with a controlled context
|
||||
context = {
|
||||
'name': self.name.replace(os.sep, '/'),
|
||||
'save_as': self.full_name,
|
||||
'url': self.base_url,
|
||||
'object_list': self.object_list,
|
||||
'number': self.number,
|
||||
'paginator': self.paginator,
|
||||
'settings': self.settings,
|
||||
'base_name': os.path.dirname(self.name),
|
||||
'number_sep': '/',
|
||||
'name': self.name,
|
||||
'base_name': self.base_name,
|
||||
'extension': self.extension,
|
||||
'number': self.number,
|
||||
}
|
||||
|
||||
if self.number == 1:
|
||||
# no page numbers on the first page
|
||||
context['number'] = ''
|
||||
context['number_sep'] = ''
|
||||
|
||||
ret = prop_value.format(**context)
|
||||
if ret[0] == '/':
|
||||
ret = ret[1:]
|
||||
ret = ret.lstrip('/')
|
||||
return ret
|
||||
|
||||
url = property(functools.partial(_from_settings, key='URL'))
|
||||
|
|
|
|||
|
|
@ -97,7 +97,8 @@ DEFAULT_CONFIG = {
|
|||
'AUTHOR_URL': 'author/{slug}.html',
|
||||
'AUTHOR_SAVE_AS': posix_join('author', '{slug}.html'),
|
||||
'PAGINATION_PATTERNS': [
|
||||
(0, '{name}{number}{extension}', '{name}{number}{extension}'),
|
||||
(1, '{name}{extension}', '{name}{extension}'),
|
||||
(2, '{name}{number}{extension}', '{name}{number}{extension}'),
|
||||
],
|
||||
'YEAR_ARCHIVE_URL': '',
|
||||
'YEAR_ARCHIVE_SAVE_AS': '',
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class TestPage(unittest.TestCase):
|
|||
object_list, settings, 1)
|
||||
page1 = paginator.page(1)
|
||||
self.assertEqual(page1.save_as, 'blog/index.html')
|
||||
self.assertEqual(page1.url, '//blog.my.site/')
|
||||
self.assertEqual(page1.url, 'blog.my.site/')
|
||||
page2 = paginator.page(2)
|
||||
self.assertEqual(page2.save_as, 'blog/2/index.html')
|
||||
self.assertEqual(page2.url, '//blog.my.site/2/')
|
||||
self.assertEqual(page2.url, 'blog.my.site/2/')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue