惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
博客园 - 司徒正美
Martin Fowler
Martin Fowler
T
Tailwind CSS Blog
B
Blog RSS Feed
Vercel News
Vercel News
博客园 - 聂微东
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements
GbyAI
GbyAI
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
B
Blog

Matthias Ott

Hello Again, World This, Still Not for Everyone The Shape of Friction WeissKlang L1 – Punching Above Its Weight Continvoucly Morged Value Webspace Invaders To Affinity and Beyond The Mystery of Storytelling Amateurs! Echoes of Connection Linear() Is Not (That) Linear View Transitions: The Smooth Parts Adding AVIF and WebP Support to My Craft CMS Site Challenge Acoustic Room Treatment and Building Sound Panels, Part 1: Planning Play On Overshoot The HTML Output Element Listening Closely Compressed Fluid Typography The Lifeblood of the Web What Could Go Wrong? That’s My Rank Making Space CSS :is() :where() the Magic Happens Visual Regression Testing for External URLs With Playwright Jane Goodall’s Famous Last Words European Tech Alternatives 🇪🇺 Independent Type Foundry Advent Calendar – Day 24: NaN Independent Type Foundry Advent Calendar – Day 23: Typotheque
Adding JSON Feed to My Craft CMS Site
Matthias Ott · 2017-06-12 · via Matthias Ott

Despite the proclaimed death of RSS I know a lot of people who still love to read their feeds on a daily basis. So feeds are definitely here to stay and providing your readers with different ways of consuming your content is also an important part of a website, especially if you consider yourself (and your site) part of the open web.

Recently, Manton Reece and Brent Simmons announced an interesting new feed format called JSON Feed. As its name implies, JSON Feed is similar to RSS or Atom, but it uses JSON as the format for syndication. This has some advantages over XML, for example that it is far easier to read and write. Manton and Brent also have the hope that the lightness, simplicity, and flexibility of JSON Feed will encourage people to develop for the open web. And JSON Feed indeed is not complicated at all. For an overview of the structure, have a look at the spec. There is a JSON Feed Viewer, made by Maxime Vaillancourt, that showcases some feeds and is also great for testing your own feed, once it’s ready. Besides that, popular feed readers like Inoreader or Feedbin already added support for JSON Feed.

So I decided to give it a go and implement JSON Feed on my own site, too. Just to get an idea of what’s possible, I first looked at some sites that already provide a JSON feed, e.g. the sites of John Gruber (who also talked with the co-authors of JSON Feed on his The Talk Show podcast) and Jeremy Keith.

After that, I evaluated different ways to easily provide the feed with Craft CMS, the content management system I use for my website. For one, you could simply output a frontend template under a route, for example “/articles/feed.json”. But I decided to use a more flexible solution: The Element API plugin. Element API is a powerful plugin vor Craft that makes it really easy to create a JSON API for your entries. You simply define an array of API endpoints in a single PHP file within your craft/config folder and the plugin will do the rest automatically for you. There is also a basic example of how you can set up a JSON Feed with Element API, which is a good starting point.

With Element API, setting up a JSON Feed for my articles section turned out to be really easy. The only part that needed more care was to find the best way to pull out matrix blocks. I now simply loop through the blocks and add the individual data to the response string. If you also need to parse markdown, the parseMarkdown() function of the StringHelper class is really useful.

So you can now subscribe to my JSON feed for the articles section or have a look at it in the JSON Feed Viewer. If you have any feedback or encounter any problems, please let me know. Within the next days, I will also add feeds for the notes and links sections.

~

17 Webmentions

1 Repost

9 Likes

ⓘ Webmentions are a way to notify other websites when you link to them, and to receive notifications when others link to you. Learn more about Webmentions.