Skip to content

Commit 9002cb0

Browse files
authored
Update README.md
1 parent 635a13b commit 9002cb0

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22
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.
33
https://github.com/getkirby
44

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.
66
https://lukedorny.com
77

8+
## JSON Feed
89
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.
910

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:
12+
```PHP
13+
<link rel="alternate" type="application/feed+json" title="<?= $site->title()->esc() ?>" h
14+
ref="<?= $site->rssfeed()->toPage()->url() ?>" />
15+
```
16+
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:
17+
```PHP
18+
<link rel="alternate" type="application/feed+json" title="<?= $site->title()->esc() ?>"
19+
href="<?= page('feed')->url() ?>" />
20+
```
21+
1022
## Setup
1123
I created a few files to make this work:
1224
- `/site/templates/feed.json.php`
@@ -27,11 +39,11 @@ This setup assumes several content folders of pages to round up for the Feed.
2739
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.
2840
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.
2941
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.
3143
10. Then it adds the `cover` to the beginning of that new `$content_html`.
3244
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.)
3547
14. Then it assembles the `$items` using the various objects we've created as well as fields from each page.
3648
15. Returns the `$items` for use.
3749
16. You'll see all of the data come together in the template.

0 commit comments

Comments
 (0)