4

Simple RSS, Atom and JSON feed for your blog

 1 year ago
source link: https://pawelgrzybek.com/simple-rss-atom-and-json-feed-for-your-blog/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Simple RSS, Atom and JSON feed for your blog

Published: 2023.05.29 · 4 minutes read

After reading “Date and Time with a Static Site Generator” by Jim Nielsen, I realised I used an incorrect date format on my RSS feed. Unfortunately, not only date was invalid, but the whole feed was a mishmash of different specifications. All fixed now!

I spent a few hours digging into the specifications of RSS, Atom and JSON feeds, and as a result, I have a simple copy/paste example that you can adapt for your blog. I also created a simple tool that allows you to generate a feed in all three formats and compare them.

Multiple formats#

There are three dominant feed specifications: RSS, Atom and JSON Feed. It is a common practice to serve multiple formats as I do on my blog (RSS and JSON Feed). Thanks to HTTP Archive dataset, we can determine the breakdown of feed formats on the web.

  • 58% of the HTTP Archive sample use any feed type
  • 50% of the HTTP Archive sample use RSS
  • 8% of the HTTP Archive sample use Atom
  • <1% of the HTTP Archive sample uses JSON Feed

Thank you, Rick Viscomi, for helping me set up HTTP Archive dataset on the GCP BigQuery and crafting some magical SQL queries.

RSS 2.0 — blog feed example#

RSS (Really Simple Syndication) is the oldest feed format, with its first version released in 1999. The latest version, 2.0, was released in 2009. Despite its limitations, it is still the most popular feed format.

<link type="application/rss+xml" rel="alternate" href="https://example.com/rss.xml" title="Example - RSS Feed" />
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Example website title</title>
        <link>https://example.com</link>
        <description>Example website description.</description>
        <atom:link href="https://example.com/rss.xml" rel="self" type="application/rss+xml" />
        <item>
            <title>Post one</title>
            <link>https://example.com/posts-one</link>
            <description>Post one content.</description>
            <guid isPermaLink="true">https://example.com/posts-one</guid>
            <pubDate>Mon, 22 May 2023 13:00:00 -0600</pubDate>
        </item>
        <item>
            <title>Post two</title>
            <link>https://example.com/posts-two</link>
            <description>Post two content.</description>
            <guid isPermaLink="true">https://example.com/posts-two</guid>
            <pubDate>Mon, 15 May 2023 13:00:00 -0600</pubDate>
        </item>
    </channel>
</rss>

Atom — blog feed example#

Atom was developed as an alternative to RSS to address problems concerning date formats, internationalisation, and modularity. It became popular due to its adoption by many Google products.

<link type="application/atom+xml" rel="alternate" href="https://example.com/atom.xml" title="Example - Atom Feed" />
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <id>http://example.com/</id>
    <title>Example website title</title>
    <updated>2023-05-22T13:00:00.000Z</updated>
    <author>
        <name>John Doe</name>
    </author>
    <link href="https://example.com/atom.xml" rel="self" type="application/rss+xml" />
    <subtitle>Example website description.</subtitle>
    <entry>
        <id>https://example.com/posts-one</id>
        <title>Post one</title>
        <link href="https://example.com/posts-one"/>
        <updated>2023-05-22T13:00:00.000Z</updated>
        <summary type="html">https://example.com/posts-one</summary>
        <content type="html">Post one content.</content>
    </entry>
    <entry>
        <id>https://example.com/posts-two</id>
        <title>Post two</title>
        <link href="https://example.com/posts-two"/>
        <updated>2023-05-15T13:00:00.000Z</updated>
        <summary type="html">https://example.com/posts-two</summary>
        <content type="html">Post two content.</content>
    </entry>
</feed>

JSON Feed — blog feed example#

JSON Feed is the newest format, released in 2017 and last time updated in August 2020. It is based on JSON compared to XML-based RSS and Atom. Due to its simplicity, it is gaining quick adoption by client applications.

<link type="application/feed+json" rel="alternate" href="https://example.com/feed.json" title="Example - JSON Feed" />
{
  "version": "https://jsonfeed.org/version/1.1",
  "title": "Example website title",
  "home_page_url": "https://example.com",
  "feed_url": "https://example.com/feed.json",
  "description": "Example website description.",
  "items": [
    {
      "id": "https://example.com/posts-one",
      "url": "https://example.com/posts-one",
      "title": "Post one content.",
      "content_text": "Post one content.",
      "date_published": "2023-05-22T13:00:00.000Z"
    },
    {
      "id": "https://example.com/posts-two",
      "url": "https://example.com/posts-two",
      "title": "Post two content.",
      "content_text": "Post two content.",
      "date_published": "2023-05-15T13:00:00.000Z"
    }
  ]
}

I built a thing#

Looking at the blobs of text doesn’t help us understand the differences between the formats. So I built the feed-generator.app to help you with that. It’s a simple tool that allows you to generate a feed in all three formats and compare them. At this point, it serves as a simple use case for generating a feed for a blog, but I plan to add more fields and make it more universal in the future.

Screenshot presenting my new little web app that helps to generate RSS, Atom and JSON feeds for a blog

I used this little web app as an opportunity to learn the basics of SolidJS. The documentation for this framework is fantastic, and I highly recommend Solid JS Crash Course Tutorial by The Net Ninja on YouTube.

Helpful resources#

Did you like it? Please share it with your friends or get me a beer coffee. Thanks!

Comments#

  • Matias Kinnunen
    2023.05.29, 10:57, #3391ee9d

    Interesting to know that RSS is so much more popular than Atom.


    It is a common practice to serve multiple formats as I do on my blog (RSS and JSON Feed).

    Atom was developed as an alternative to RSS to address problems concerning date formats, internationalisation, and modularity.

    Given that Atom is apparently the better format, did you ever consider choosing it over RSS?


    Btw, your two <link rel="alternate" /> elements (one for RSS, one for JSON) have the same title attribute, so it's not possible to distinguish between the two feeds based only on the titles.

    • Pawel Grzybek
      Pawel Grzybek
      2023.05.29, 11:51, #b96e4a62

      Given that Atom is apparently the better format, did you ever consider choosing it over RSS?

      Nah. My motivation is to support the most bleeding edge JSON, and the best supported RSS. Atom is in between so I am also in between 🤷‍♂️

      I will change titles for my RSS links. Good point Matias! Thank you!

Leave a comment#

Name:
Website (optional):
GitHub (optional):
Comment:

👆 you can use Markdown here

Save my data for the next time I comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK