mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
commit
d3ada540bf
4 changed files with 40 additions and 9 deletions
|
|
@ -91,6 +91,12 @@ Setting name (default value) What doe
|
||||||
index pages for collections of content e.g. tags and
|
index pages for collections of content e.g. tags and
|
||||||
category index pages.
|
category index pages.
|
||||||
`PAGINATED_DIRECT_TEMPLATES` (``('index',)``) Provides the direct templates that should be paginated.
|
`PAGINATED_DIRECT_TEMPLATES` (``('index',)``) Provides the direct templates that should be paginated.
|
||||||
|
`SUMMARY_MAX_LENGTH` (``50``) When creating a short summary of an article, this will
|
||||||
|
be the default length in words of the text created.
|
||||||
|
This only applies if your content does not otherwise
|
||||||
|
specify a summary. Setting to None will cause the summary
|
||||||
|
to be a copy of the original content.
|
||||||
|
|
||||||
===================================================================== =====================================================================
|
===================================================================== =====================================================================
|
||||||
|
|
||||||
.. [#] Default is the system locale.
|
.. [#] Default is the system locale.
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,9 @@ class Page(object):
|
||||||
if hasattr(self, '_summary'):
|
if hasattr(self, '_summary'):
|
||||||
return self._summary
|
return self._summary
|
||||||
else:
|
else:
|
||||||
return truncate_html_words(self.content, 50)
|
if self.settings['SUMMARY_MAX_LENGTH']:
|
||||||
|
return truncate_html_words(self.content, self.settings['SUMMARY_MAX_LENGTH'])
|
||||||
|
return self.content
|
||||||
|
|
||||||
def _set_summary(self, summary):
|
def _set_summary(self, summary):
|
||||||
"""Dummy function"""
|
"""Dummy function"""
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ _DEFAULT_CONFIG = {'PATH': '.',
|
||||||
'ARTICLE_PERMALINK_STRUCTURE': '',
|
'ARTICLE_PERMALINK_STRUCTURE': '',
|
||||||
'TYPOGRIFY': False,
|
'TYPOGRIFY': False,
|
||||||
'LESS_GENERATOR': False,
|
'LESS_GENERATOR': False,
|
||||||
|
'SUMMARY_MAX_LENGTH': 50,
|
||||||
'WEBASSETS': False,
|
'WEBASSETS': False,
|
||||||
'PLUGINS': [],
|
'PLUGINS': [],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from .support import unittest
|
||||||
|
|
||||||
from pelican.contents import Page
|
from pelican.contents import Page
|
||||||
from pelican.settings import _DEFAULT_CONFIG
|
from pelican.settings import _DEFAULT_CONFIG
|
||||||
|
from pelican.utils import truncate_html_words
|
||||||
|
|
||||||
from jinja2.utils import generate_lorem_ipsum
|
from jinja2.utils import generate_lorem_ipsum
|
||||||
|
|
||||||
|
|
@ -48,6 +49,20 @@ class TestPage(unittest.TestCase):
|
||||||
page = Page(**self.page_kwargs)
|
page = Page(**self.page_kwargs)
|
||||||
self.assertEqual(page.summary, TEST_SUMMARY)
|
self.assertEqual(page.summary, TEST_SUMMARY)
|
||||||
|
|
||||||
|
def test_summary_max_length(self):
|
||||||
|
"""If a :SUMMARY_MAX_LENGTH: is set, and there is no other summary, generated summary
|
||||||
|
should not exceed the given length."""
|
||||||
|
page_kwargs = self._copy_page_kwargs()
|
||||||
|
settings = _DEFAULT_CONFIG.copy()
|
||||||
|
page_kwargs['settings'] = settings
|
||||||
|
del page_kwargs['metadata']['summary']
|
||||||
|
settings['SUMMARY_MAX_LENGTH'] = None
|
||||||
|
page = Page(**page_kwargs)
|
||||||
|
self.assertEqual(page.summary, TEST_CONTENT)
|
||||||
|
settings['SUMMARY_MAX_LENGTH'] = 10
|
||||||
|
page = Page(**page_kwargs)
|
||||||
|
self.assertEqual(page.summary, truncate_html_words(TEST_CONTENT, 10))
|
||||||
|
|
||||||
def test_slug(self):
|
def test_slug(self):
|
||||||
"""If a title is given, it should be used to generate the slug."""
|
"""If a title is given, it should be used to generate the slug."""
|
||||||
page = Page(**self.page_kwargs)
|
page = Page(**self.page_kwargs)
|
||||||
|
|
@ -83,14 +98,9 @@ class TestPage(unittest.TestCase):
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sys import platform
|
from sys import platform
|
||||||
dt = datetime(2015, 9, 13)
|
dt = datetime(2015, 9, 13)
|
||||||
# make a deep copy of page_kawgs
|
|
||||||
page_kwargs = dict([(key, self.page_kwargs[key]) for key in
|
page_kwargs = self._copy_page_kwargs()
|
||||||
self.page_kwargs])
|
|
||||||
for key in page_kwargs:
|
|
||||||
if not isinstance(page_kwargs[key], dict):
|
|
||||||
break
|
|
||||||
page_kwargs[key] = dict([(subkey, page_kwargs[key][subkey])
|
|
||||||
for subkey in page_kwargs[key]])
|
|
||||||
# set its date to dt
|
# set its date to dt
|
||||||
page_kwargs['metadata']['date'] = dt
|
page_kwargs['metadata']['date'] = dt
|
||||||
page = Page(**page_kwargs)
|
page = Page(**page_kwargs)
|
||||||
|
|
@ -124,3 +134,15 @@ class TestPage(unittest.TestCase):
|
||||||
# Until we find some other method to test this functionality, we
|
# Until we find some other method to test this functionality, we
|
||||||
# will simply skip this test.
|
# will simply skip this test.
|
||||||
unittest.skip("There is no locale %s in this system." % locale)
|
unittest.skip("There is no locale %s in this system." % locale)
|
||||||
|
|
||||||
|
def _copy_page_kwargs(self):
|
||||||
|
# make a deep copy of page_kwargs
|
||||||
|
page_kwargs = dict([(key, self.page_kwargs[key]) for key in
|
||||||
|
self.page_kwargs])
|
||||||
|
for key in page_kwargs:
|
||||||
|
if not isinstance(page_kwargs[key], dict):
|
||||||
|
break
|
||||||
|
page_kwargs[key] = dict([(subkey, page_kwargs[key][subkey])
|
||||||
|
for subkey in page_kwargs[key]])
|
||||||
|
|
||||||
|
return page_kwargs
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue