Skip to content

Commit

Permalink
plugins/feeds: render summary and make URLs in it absolute
Browse files Browse the repository at this point in the history
Unrendered summaries contain directives such as:

  {{ link('content/blog-post.html', 'foo') }}

These do not belong in the final HTML output. A function for summary
rendering can be provided by a custom summary plugin.
Use that if available and make rendered URLs absolute afterwards.

See [1] for an example summary plugin. But note that it contains
theme-related information.

[1] https://github.com/pengutronix/flamingo-ptx-blog-engine/blob/master/flamingo_ptx_blog_engine/summary.py

Signed-off-by: Bastian Krause <[email protected]>
  • Loading branch information
Bastian-Krause committed Aug 17, 2024
1 parent 16cefe1 commit a474abd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion flamingo/plugins/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def make_urls_absolute(html, base_url):

class Feeds:
def pre_build(self, context):
env = context.templating_engine.env
render_summary = env.globals.get('render_summary')
FEEDS_DOMAIN = getattr(context.settings, 'FEEDS_DOMAIN', '/')
FEEDS = getattr(context.settings, 'FEEDS', [])

Expand Down Expand Up @@ -169,7 +171,13 @@ def pre_build(self, context):
# https://github.com/pengutronix/flamingo-ptx-blog-engine/blob/master/flamingo_ptx_blog_engine/summary.py
# for an example
if i['summary']:
summary = str(i['summary'])
if render_summary:
summary = render_summary(i)
else:
summary = str(i['summary'])

summary = make_urls_absolute(summary, fe_link['href'])

if 'html_filter' in feed_config:
summary = feed_config['html_filter'](summary)
fe.summary(summary, type='html')
Expand Down

0 comments on commit a474abd

Please sign in to comment.