You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-4Lines changed: 16 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,23 @@
2
2
Working on updating my site and converting what I had worked on for an XML RSS feed into a more current JSON feed within a Kirby CMS controller file.
3
3
https://github.com/getkirby
4
4
5
-
my redesigned site will launch soon in 2024 and will feature the json formatted feed.
5
+
my redesigned site will launch soon in 2024 and will feature the JSON formatted feed.
6
6
https://lukedorny.com
7
7
8
+
## JSON Feed
8
9
Since you're here you should browse the available elements in the [jsonfeed.org](https://www.jsonfeed.org/version/1.1/) made by Manton Reese and Brent Simmons. Maybe there are a few elements you could add to this that I haven't. It looks much more flexible than the XML feed format.
9
10
11
+
Remember, we are now serving `application/feed+json` and the JSON feed format is `'version' => 'https://jsonfeed.org/version/1.1'`, also, the URL for the feed link in your header should use this PHP code:
Of course, if you'd just like to link to your feed page directly, bypassing my silly panel page chooser for the feed, your header should use this more normal PHP code:
@@ -27,11 +39,11 @@ This setup assumes several content folders of pages to round up for the Feed.
27
39
6. Next the controller file. This grabs the sections we want to include, sorts them, and grabs post images that use the typical Kirby `cover` image method but falls back to the first image available in each post.
28
40
7. Then the controller creates the $items array for the feed. This is an array of all of your site pages that will be included.
29
41
8. Then it takes the `cover` image and wraps it in a `figure`, adds `alt` text, a `figcaption` that allows links using the `->kirbytext()` powers, etc.
30
-
9. In the new `$content_html` object it first adds in the page's text content and strips out extra new lines code.
42
+
9. In the new `$content_html` object it first adds in the page's text content and strips out extra new lines of code.
31
43
10. Then it adds the `cover` to the beginning of that new `$content_html`.
32
44
11. You can add in other field data you may have for your pages, here I have added `$materials` at the end, for a project I'm doing that I'll soon launch on the site.
33
-
12. It also adds in the `rssblip` at the end too, which has four `----` in the textarea to give it a divider from the item's content
34
-
13. I actually added in the title of each item's parent to differentiate it from other posts, too (i.e.: "Articles: ", "Updates: ", etc.)
45
+
12. It also adds in the `rssblip` at the end, which has four `----` in the textarea to give it a divider from the item's content below it
46
+
13. I added the title of each item's parent to differentiate it from other posts, too (i.e.: "Articles: ", "Updates: ", etc.)
35
47
14. Then it assembles the `$items` using the various objects we've created as well as fields from each page.
36
48
15. Returns the `$items` for use.
37
49
16. You'll see all of the data come together in the template.
0 commit comments