Pick up the author value on a post from the 'item' and not the 'channel'

If I use the RSS widget with a feed.xml as follows

<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<script/>
<channel>
<title>My Feed</title>
... missed out for clarity
<item>
<title>A post</title>
<author>Fred Bloggs</author>
... missed out for clarity
</item>
<title>Another post</title>
<author>John Smith</author>
... missed out for clarity
</item>... more posts with different authors

The RSS widget shows the author as My Feed for all posts in the feed, not Fred Bloggs or John Smith as appropriate for each post.

Note: If configure the widget to not show the author the name ‘My Feed’ is hidden as expected.

  • Is this behaviour by design?
  • Have I missed something in configuration?
  • Is it possible to set the author to be author of a post not, in effect, the owner of the whole feed
1 Like

Hi there @BMAlerts :wave:

Unfortunately, our app doesn’t display the name of the post author. However, our dev team came up with a custom solution to make it possible:

const originalFetch = window.fetch;

const updatedResponse = (data) => {
  const response = { ...data };
  response.channel.item = response.channel.item.map((item) => ({
    ...item,
    title: `${item.author} | ${item.title}`
  }));
  return response;
};

const updatedFetch = async (url, options) => {
  const currentURL = new URL(url);
  const isRSS = currentURL.toString().includes('storage.elfsight.com/api/rss');

  if (isRSS) {
    const originalResponse = await originalFetch(url, options);
    const data = await originalResponse.json();

    const modifiedResponse = new Response(
      JSON.stringify(updatedResponse(data)),
      {
        status: originalResponse.status,
        statusText: originalResponse.statusText,
        headers: originalResponse.headers
      }
    );

    return modifiedResponse;
  }

  return originalFetch(url, options);
};

window.fetch = updatedFetch;

Just add it to the Custom JS field on the Settings tab of your widget’s settings and let me know if it helped :slightly_smiling_face:

Note: Custom JS operates only upon widget installation, not in preview mode

1 Like

Perfect, works like a dream, thanks for the quick answer

Can I suggest it might be worth some note in the RSS Widget Post layout/help page to explain the Author is not the item author but the channel name, and maybe point to this code snippet.

Thanks again

1 Like

Great! Your idea sounds reasonable, and I’ve passed it to the dev team :wink:

Thank you so much for your feedback!