Skip to content

Commit

Permalink
plugins/feeds: Add optional filter_function
Browse files Browse the repository at this point in the history
This optional callable is called for every body and summary that is
added to a feed_entry.
This can be used to remove unwanted elements from the feed (e.g. using
bs4).

Signed-off-by: Chris Fiege <cfi@pengutronix.de>
  • Loading branch information
SmithChart committed Nov 25, 2022
1 parent 5c5e065 commit adcf2d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions doc/content/plugins/feeds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ Usage
# of every feed entry
'published':
lambda content: content['date'].strftime('%Y-%m-%d %H:%M:%S+01:00'),
# This optional callable is called for every body and summary that is added to a feed entry.
# This can be used to remove unwanted elements from the feed (e.g. by using beautifulsoup4).
# The callable must follow this signature and return the filtered html as string:
# |def _filter_function(html_input):
# | # do the filtering
# | return html_output
'html_filter': _callable,
'
},
]
Expand Down
7 changes: 6 additions & 1 deletion flamingo/plugins/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def pre_build(self, context):

if i['content_body']:
exitcode, output = context.pre_render(i)
if 'html_filter' in feed_config:
output = feed_config['html_filter'](output)
fe.content(output, type='html')

if i['authors']:
Expand All @@ -131,7 +133,10 @@ def pre_build(self, context):
})

if i['summary']:
fe.summary(str(i['summary']))
summary = str(i['summary'])
if 'html_filter' in feed_config:
summary = feed_config['html_filter'](summary)
fe.summary(summary)

if feed_config['type'] == 'podcast':
fe.enclosure(fe_podcast_url, str(fe_podcast_size), fe_podcast_type)
Expand Down

0 comments on commit adcf2d1

Please sign in to comment.