Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math doesn't always render in summaries #40

Open
szhorvat opened this issue Jan 13, 2017 · 2 comments
Open

Math doesn't always render in summaries #40

szhorvat opened this issue Jan 13, 2017 · 2 comments

Comments

@szhorvat
Copy link

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:

Avaris: problem is the summary being memoized and there is no easy way to 'get' auto-generated summaries without triggering that
Avaris: whenever you access .summary or in this case ._get_summary(), it's recorded so that it won't have to regenerated over and over if you request it again
Avaris: that's an optimization for site generation but that creates the problem of not being able to manipulate summaries from a plugin

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 to article._summary will be ignored.

Thus I won't send a pull request until further comment by @barrysteyn

@szhorvat szhorvat mentioned this issue Jan 13, 2017
@jerryasher
Copy link

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?

@szhorvat
Copy link
Author

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:

szhorvat@e0f48b3

(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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants