Adding External News Feed to Site

Howdy everyone,

I’m new to hugo and really loving it so far. So, this may also be my lack of web dev experience showing through here but here it goes.

I’d like to add a news section to my hugo site that pulls articles from various external sources of my choosing and have it update as new articles come in. Again, I really think this is due to my lack of knowledge in this realm but I’m curious if you all can assist in providing me some insights on how to accomplish this. Thanks in advance.

Hugo is able to fetch remote resources, see

You can find more when googling with keywords hugo remote.

To update those sources/data, you can simply set up a schedulable build job.

Very interesting, thank you very much!

Okay, so further question,

How do I go about incorporating this into a “news page”. Do I need to create something in assets and then call the “asset” from my news.md or news.html or can I input the get.resource directly into the page itself? Does that make sense?

Or do I need to create a .json in the data folder and call that?

and one more, is it possible to get.resource to an rss feed? Does that even make sense?

You just need to use those functions in the whatever templates you want.

is it possible to get.resource to an rss feed?

Yes, you’ll need to transform.Unmarshal the data.

For example.

{{ with resources.GetRemote "https://hugomods.com/en/index.xml" | transform.Unmarshal }}
  <ul>
    {{ range .channel.item }}
    <li>
      <a href="{{ .link }}">{{ .title }}</a>
    </li>
    {{ end }}
  </ul>
{{ end }}
4 Likes

Okay thank you that makes sense. Can you please explain how to utilize this in practice. So does this belong in a .json in assets? And then how do I go about translating that to my news.md page?

So does this belong in a .json in assets?

No, it’s just a template function.

And then how do I go about translating that to my news.md page?

It depends on the theme’s implementation, find out the template used by the news.md page, and then put the code snippet to the template see how it work.

You can also create a shortcode for this, so that you can use it in the content.

// layouts/shortcodes/rss.html
THE CODE SNIPPET ABOVE.

And then invoke it in your content file.

---
title: News
---

{{< rss >}}
2 Likes

Thank you soooo much for your assistance, this was incredibly helpful.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.