mitydigital / statamic-feedamic

An Atom and RSS feed for Statamic 3, 4 and 5
https://docs.mity.com.au/feedamic
8 stars 9 forks source link

Summary cannot handle Bard elements #4

Closed le-martre closed 4 months ago

le-martre commented 2 years ago

Hello !

Just figure I'd mention it here but Bard elements make the "summary" function bug out because it's accessing the Bard value (an array) as a string.

I had to add some custom code at FeedEntry.php:66 to get it working, here is what I did (dirty but works) :

// Hack to handle Bard elements
if(is_array($summary)) {
  $new_summary = '';

  foreach($summary as $section) {
    if(!empty($section['type']) && $section['type'] === 'text') {
      $new_summary = $section['text'];
      break;
    }
  }

  $summary = $new_summary;
}

Figured it might help other people, cheers ! And thanks for the great package

martyf commented 2 years ago

Thanks for reporting this @MartinVandersteen - in a recent project I needed to process a bard field (totally different purpose) and have something similar, but also that works for custom sets.

Has me thinking though whether its worth trying to find a way to also make this extensible so that it can run a bare-bones text process (like you've provided), and one that can also be extended app-by-app that can process explicitly defined sets within the Bard config.

Maybe that's a bigger one than to tackle now but could be useful to give other devs the option to easily hook in to the summary creation with their own Bard sets.

I'll at least get this issue resolved with this text-only approach, but did you have any thoughts, ideas, considerations, concerns about being able to extend the behaviour too? Is this something that would be useful?

martyf commented 2 years ago

Righto so I have just published a new version that adds the logic in.

The bigger one for discussion is about how to process custom sets.

If it were just a single set, with a number of fields, it could have either a process class that dictates what content fields to get (and how to process them), but gets trickier then if you have a bard block within a set. And starts going down the more slippery slope towards the idea of literally rendering all the content in a dummy file (including set markup) and using that.

This bigger one I'd definitely like to discuss more to ensure whatever gets done works well, and gives other devs enough flexibility.

tdwesten commented 5 months ago

With #25, it will be possible to write your own FeedEntry model and implement it.

martyf commented 4 months ago

This is correct - with 2.4.0 you can write your own FeedEntry model (and thanks to @tdwesten for the initial FeedEntry model PR).

Your own model must implement the FeedamicEntry interface.

Given Bard sets are so specific to your site (and can vary from my site or another site), there has previously not been a way to handle this generically for everyone. But with your own FeedEntry model, you can write your own logic to output your site's Bard sets.

You'll need to refer to the docs: https://docs.mity.com.au/feedamic/interface