mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Add custom configuration for summary ending text
This commit is contained in:
parent
6ab890ddb7
commit
12d51fa8a0
4 changed files with 10 additions and 5 deletions
|
|
@ -146,6 +146,11 @@ Setting name (default value) What doe
|
|||
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.
|
||||
`SUMMARY_END_TEXT` (``' ...'``) When creating a short summary of an article, this will
|
||||
be the final displayed text string of the summary.
|
||||
This only applies if your content does not otherwise
|
||||
specify a summary and ``SUMMARY_MAX_LENGTH`` is not set
|
||||
to ``None``.
|
||||
`EXTRA_TEMPLATES_PATHS` (``[]``) A list of paths you want Jinja2 to search for templates.
|
||||
Can be used to separate templates from the theme.
|
||||
Example: projects, resume, profile ...
|
||||
|
|
|
|||
|
|
@ -270,7 +270,8 @@ class Content(object):
|
|||
return self.content
|
||||
|
||||
return truncate_html_words(self.content,
|
||||
self.settings['SUMMARY_MAX_LENGTH'])
|
||||
self.settings['SUMMARY_MAX_LENGTH'],
|
||||
self.settings['SUMMARY_END_TEXT'])
|
||||
|
||||
def _set_summary(self, summary):
|
||||
"""Dummy function"""
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ DEFAULT_CONFIG = {
|
|||
'ARTICLE_PERMALINK_STRUCTURE': '',
|
||||
'TYPOGRIFY': False,
|
||||
'SUMMARY_MAX_LENGTH': 50,
|
||||
'SUMMARY_END_TEXT': ' ...',
|
||||
'PLUGIN_PATH': '',
|
||||
'PLUGINS': [],
|
||||
'PYGMENTS_RST_OPTIONS': {},
|
||||
|
|
|
|||
|
|
@ -360,7 +360,7 @@ def path_to_url(path):
|
|||
return '/'.join(split_all(path))
|
||||
|
||||
|
||||
def truncate_html_words(s, num, end_text='...'):
|
||||
def truncate_html_words(s, num, end_text=' ...'):
|
||||
"""Truncates HTML to a certain number of words.
|
||||
|
||||
(not counting tags and comments). Closes opened tags if they were correctly
|
||||
|
|
@ -420,9 +420,7 @@ def truncate_html_words(s, num, end_text='...'):
|
|||
if words <= length:
|
||||
# Don't try to close tags if we don't need to truncate
|
||||
return s
|
||||
out = s[:end_text_pos]
|
||||
if end_text:
|
||||
out += ' ' + end_text
|
||||
out = s[:end_text_pos] + end_text
|
||||
# Close any tags still open
|
||||
for tag in open_tags:
|
||||
out += '</%s>' % tag
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue