Open szhorvat opened 7 years ago
Can you clarify a bit? I am pretty new to pelican. What are the summary pages? Are they the index pages served at SITE_URL/index.html or something different?
I would think what Avaris is suggesting is taking
@memoized
def get_summary(self, siteurl):
"""Returns the summary of an article.
This is based on the summary metadata if set, otherwise truncate the
content.
"""
if hasattr(self, '_summary'):
return self._update_content(self._summary, siteurl)
if self.settings['SUMMARY_MAX_LENGTH'] is None:
return self.content
return truncate_html_words(self.content,
self.settings['SUMMARY_MAX_LENGTH'])
and creating something like this:
def get_summary_new(self, siteurl):
"""Returns a new summary of an article.
"""
if self.settings['SUMMARY_MAX_LENGTH'] is None:
return self.content
return truncate_html_words(self.content,
self.settings['SUMMARY_MAX_LENGTH'])
What did you try?
Summaries are what you see at the bottom of the page here: https://blog.getpelican.com/category/news.html When they are auto-generated, they are just excerpts from the beginning of each article.
This is what I did based on Avaris's suggestion:
(This includes your changes as well.)
This just replaces the call to article.summary
with what that call would usually do—sans the memoization. It is a hack because if .summary
gets called by something else (e.g. another plugin) before render_math would call it, it would still trigger memoization. I.e. any modifications to ._summary
won't take effect if .summary
or .get_summary()
have been already called at least once.
Math does not always render in article summaries. In particular, when I use the setting
RELATIVE_URLS=False
, math won't render in summaries.This is the line that inserts the script necessary to show math in summaries:
https://github.com/barrysteyn/pelican_plugin-render_math/blob/master/render_math.py#L336
I asked about this in #pelican on freenode, and I got the following response from Avaris:
As a quick fix he suggested replicating this method:
https://github.com/getpelican/pelican/blob/master/pelican/contents.py#L293
in place of this:
https://github.com/barrysteyn/pelican_plugin-render_math/blob/master/render_math.py#L324
I did this and it works. But this is still just a hack. If another plugin calls
get_summary
before render_math, the memoization will still kick and the modification toarticle._summary
will be ignored.Thus I won't send a pull request until further comment by @barrysteyn