forked from github/pelican
Fix Issue #1165 allows extensions to be set by certain settings
PAGINATION_PATTERNS was hard coded so that all files had a ".html" extension. This fixes that and add a test to ensure that the pagination code is not changing the filename incorrectly.
This commit is contained in:
parent
d9bbdf7f07
commit
990ddb5a5e
4 changed files with 54 additions and 4 deletions
|
|
@ -69,7 +69,7 @@ class Paginator(object):
|
|||
|
||||
class Page(object):
|
||||
def __init__(self, name, object_list, number, paginator, settings):
|
||||
self.name = name
|
||||
self.name, self.extension = os.path.splitext(name)
|
||||
self.object_list = object_list
|
||||
self.number = number
|
||||
self.paginator = paginator
|
||||
|
|
@ -143,6 +143,7 @@ class Page(object):
|
|||
'settings': self.settings,
|
||||
'base_name': os.path.dirname(self.name),
|
||||
'number_sep': '/',
|
||||
'extension': self.extension,
|
||||
}
|
||||
|
||||
if self.number == 1:
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ DEFAULT_CONFIG = {
|
|||
'AUTHOR_URL': 'author/{slug}.html',
|
||||
'AUTHOR_SAVE_AS': os.path.join('author', '{slug}.html'),
|
||||
'PAGINATION_PATTERNS': [
|
||||
(0, '{name}{number}.html', '{name}{number}.html'),
|
||||
(0, '{name}{number}{extension}', '{name}{number}{extension}'),
|
||||
],
|
||||
'YEAR_ARCHIVE_SAVE_AS': False,
|
||||
'MONTH_ARCHIVE_SAVE_AS': False,
|
||||
|
|
|
|||
50
pelican/tests/test_paginator.py
Normal file
50
pelican/tests/test_paginator.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
import six
|
||||
|
||||
from pelican.tests.support import unittest, get_settings
|
||||
|
||||
from pelican.paginator import Paginator
|
||||
from pelican.contents import Article
|
||||
from pelican.settings import DEFAULT_CONFIG
|
||||
from jinja2.utils import generate_lorem_ipsum
|
||||
|
||||
# generate one paragraph, enclosed with <p>
|
||||
TEST_CONTENT = str(generate_lorem_ipsum(n=1))
|
||||
TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False)
|
||||
|
||||
class TestPage(unittest.TestCase):
|
||||
def setUp(self):
|
||||
super(TestPage, self).setUp()
|
||||
self.page_kwargs = {
|
||||
'content': TEST_CONTENT,
|
||||
'context': {
|
||||
'localsiteurl': '',
|
||||
},
|
||||
'metadata': {
|
||||
'summary': TEST_SUMMARY,
|
||||
'title': 'foo bar',
|
||||
'author': 'Blogger',
|
||||
},
|
||||
'source_path': '/path/to/file/foo.ext'
|
||||
}
|
||||
|
||||
def test_save_as_preservation(self):
|
||||
settings = get_settings()
|
||||
# fix up pagination rules
|
||||
from pelican.paginator import PaginationRule
|
||||
pagination_rules = [
|
||||
PaginationRule(*r) for r in settings.get(
|
||||
'PAGINATION_PATTERNS',
|
||||
DEFAULT_CONFIG['PAGINATION_PATTERNS'],
|
||||
)
|
||||
]
|
||||
settings['PAGINATION_PATTERNS'] = sorted(
|
||||
pagination_rules,
|
||||
key=lambda r: r[0],
|
||||
)
|
||||
|
||||
object_list = [Article(**self.page_kwargs), Article(**self.page_kwargs)]
|
||||
paginator = Paginator('foobar.foo', object_list, settings)
|
||||
page = paginator.page(1)
|
||||
self.assertEqual(page.save_as, 'foobar.foo')
|
||||
|
|
@ -179,10 +179,9 @@ class Writer(object):
|
|||
|
||||
# pagination
|
||||
if paginated:
|
||||
name_root = os.path.splitext(name)[0]
|
||||
|
||||
# pagination needed, init paginators
|
||||
paginators = {key: Paginator(name_root, val, self.settings)
|
||||
paginators = {key: Paginator(name, val, self.settings)
|
||||
for key, val in paginated.items()}
|
||||
|
||||
# generated pages, and write
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue