Переглянути джерело

Render Math: Workaround for processing summaries

Replace deprecated _get_summary by summary property
Clear memoization cache when setting modified summary
lhofmann 7 роки тому
батько
коміт
80a47651cb
1 змінених файлів з 7 додано та 1 видалено
  1. 7 1
      render_math/math.py

+ 7 - 1
render_math/math.py

@@ -187,7 +187,7 @@ def process_summary(article):
     """Ensures summaries are not cut off. Also inserts
     """Ensures summaries are not cut off. Also inserts
     mathjax script so that math will be rendered"""
     mathjax script so that math will be rendered"""
 
 
-    summary = article._get_summary()
+    summary = article.summary
     summary_parsed = BeautifulSoup(summary, 'html.parser')
     summary_parsed = BeautifulSoup(summary, 'html.parser')
     math = summary_parsed.find_all(class_='math')
     math = summary_parsed.find_all(class_='math')
 
 
@@ -199,6 +199,12 @@ def process_summary(article):
             math[-1].string = "%s ..." % full_text
             math[-1].string = "%s ..." % full_text
             summary = summary_parsed.decode()
             summary = summary_parsed.decode()
 
 
+        # clear memoization cache
+        import functools
+        if isinstance(article.get_summary, functools.partial):
+            memoize_instance = article.get_summary.func.__self__
+            memoize_instance.cache.clear()
+
         article._summary = "%s<script type='text/javascript'>%s</script>" % (summary, process_summary.mathjax_script)
         article._summary = "%s<script type='text/javascript'>%s</script>" % (summary, process_summary.mathjax_script)
 
 
 def configure_typogrify(pelicanobj, mathjax_settings):
 def configure_typogrify(pelicanobj, mathjax_settings):