|
@@ -16,11 +16,13 @@ def initialized(pelican):
|
|
'<!-- PELICAN_BEGIN_SUMMARY -->')
|
|
'<!-- PELICAN_BEGIN_SUMMARY -->')
|
|
DEFAULT_CONFIG.setdefault('SUMMARY_END_MARKER',
|
|
DEFAULT_CONFIG.setdefault('SUMMARY_END_MARKER',
|
|
'<!-- PELICAN_END_SUMMARY -->')
|
|
'<!-- PELICAN_END_SUMMARY -->')
|
|
|
|
+ DEFAULT_CONFIG.setdefault('SUMMARY_USE_FIRST_PARAGRAPH', False)
|
|
if pelican:
|
|
if pelican:
|
|
pelican.settings.setdefault('SUMMARY_BEGIN_MARKER',
|
|
pelican.settings.setdefault('SUMMARY_BEGIN_MARKER',
|
|
'<!-- PELICAN_BEGIN_SUMMARY -->')
|
|
'<!-- PELICAN_BEGIN_SUMMARY -->')
|
|
pelican.settings.setdefault('SUMMARY_END_MARKER',
|
|
pelican.settings.setdefault('SUMMARY_END_MARKER',
|
|
'<!-- PELICAN_END_SUMMARY -->')
|
|
'<!-- PELICAN_END_SUMMARY -->')
|
|
|
|
+ pelican.settings.setdefault('SUMMARY_USE_FIRST_PARAGRAPH', False)
|
|
|
|
|
|
def extract_summary(instance):
|
|
def extract_summary(instance):
|
|
# if summary is already specified, use it
|
|
# if summary is already specified, use it
|
|
@@ -35,6 +37,8 @@ def extract_summary(instance):
|
|
|
|
|
|
begin_marker = instance.settings['SUMMARY_BEGIN_MARKER']
|
|
begin_marker = instance.settings['SUMMARY_BEGIN_MARKER']
|
|
end_marker = instance.settings['SUMMARY_END_MARKER']
|
|
end_marker = instance.settings['SUMMARY_END_MARKER']
|
|
|
|
+ use_first_paragraph = instance.settings['SUMMARY_USE_FIRST_PARAGRAPH']
|
|
|
|
+ remove_markers = True
|
|
|
|
|
|
content = instance._content
|
|
content = instance._content
|
|
begin_summary = -1
|
|
begin_summary = -1
|
|
@@ -44,6 +48,12 @@ def extract_summary(instance):
|
|
if end_marker:
|
|
if end_marker:
|
|
end_summary = content.find(end_marker)
|
|
end_summary = content.find(end_marker)
|
|
|
|
|
|
|
|
+ if begin_summary == -1 and end_summary == -1 and use_first_paragraph:
|
|
|
|
+ begin_marker, end_marker = '<p>', '</p>'
|
|
|
|
+ remove_markers = False
|
|
|
|
+ begin_summary = content.find(begin_marker)
|
|
|
|
+ end_summary = content.find(end_marker)
|
|
|
|
+
|
|
if begin_summary == -1 and end_summary == -1:
|
|
if begin_summary == -1 and end_summary == -1:
|
|
instance.has_summary = False
|
|
instance.has_summary = False
|
|
return
|
|
return
|
|
@@ -59,11 +69,12 @@ def extract_summary(instance):
|
|
|
|
|
|
summary = content[begin_summary:end_summary]
|
|
summary = content[begin_summary:end_summary]
|
|
|
|
|
|
- # remove the markers from the content
|
|
|
|
- if begin_summary:
|
|
|
|
- content = content.replace(begin_marker, '', 1)
|
|
|
|
- if end_summary:
|
|
|
|
- content = content.replace(end_marker, '', 1)
|
|
|
|
|
|
+ if remove_markers:
|
|
|
|
+ # remove the markers from the content
|
|
|
|
+ if begin_summary:
|
|
|
|
+ content = content.replace(begin_marker, '', 1)
|
|
|
|
+ if end_summary:
|
|
|
|
+ content = content.replace(end_marker, '', 1)
|
|
|
|
|
|
instance._content = content
|
|
instance._content = content
|
|
instance._summary = summary
|
|
instance._summary = summary
|