Skip to content

Commit 95f8243

Browse files
committed
✨ added ->sitemap() support
1 parent 7b21f41 commit 95f8243

File tree

13 files changed

+1086
-470
lines changed

13 files changed

+1086
-470
lines changed

README.md

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Kirby 3 Feed
1+
# Kirby 3 Feed and Sitemap
22

33
![Release](https://flat.badgen.net/packagist/v/bnomei/kirby3-feed?color=ae81ff)
44
![Downloads](https://flat.badgen.net/packagist/dt/bnomei/kirby3-feed?color=272822)
@@ -7,7 +7,7 @@
77
[![Maintainability](https://flat.badgen.net/codeclimate/maintainability/bnomei/kirby3-feed)](https://codeclimate.com/github/bnomei/kirby3-feed)
88
[![Twitter](https://flat.badgen.net/badge/twitter/bnomei?color=66d9ef)](https://twitter.com/bnomei)
99

10-
Generate a RSS/JSON-Feed from a Pages-Collection.
10+
Generate a RSS/JSON/Sitemap-Feed from a Pages-Collection.
1111

1212
## Commercial Usage
1313

@@ -16,13 +16,21 @@ This plugin is free but if you use it in a commercial project please consider to
1616
- [buy me ☕](https://buymeacoff.ee/bnomei) or
1717
- [buy a Kirby license using this affiliate link](https://a.paddle.com/v2/click/1129/35731?link=1170)
1818

19+
20+
## Similar Plugins
21+
22+
- [kirby3-xmlsitemap](https://github.com/omz13/kirby3-xmlsitemap)
23+
- [kirby3-feeds](https://github.com/omz13/kirby3-feeds)
24+
25+
> both have not seen any updates since April 2019
26+
1927
## Installation
2028

2129
- unzip [master.zip](https://github.com/bnomei/kirby3-feed/archive/master.zip) as folder `site/plugins/kirby3-feed` or
2230
- `git submodule add https://github.com/bnomei/kirby3-feed.git site/plugins/kirby3-feed` or
2331
- `composer require bnomei/kirby3-feed`
2432

25-
## Usage
33+
## Usage Feed
2634

2735
You can use this in a template for a dedicated feed page, in a template controller or a route.
2836

@@ -75,8 +83,8 @@ return [
7583
$feed = page('blog')->children()->listed()->flip()->limit(10)->feed($options);
7684
return $feed;
7785
}
78-
]
79-
]
86+
],
87+
],
8088
];
8189
```
8290

@@ -109,6 +117,55 @@ $feed = page('blog')->children()->listed()->sortBy(function ($page) {
109117
}, 'desc')->limit(10)->feed($options);
110118
```
111119

120+
## Usage Sitemap
121+
122+
**options array defaults**
123+
124+
If you use these defaults you need to provide the fields `date (type: date)` and `text (type: text)`.
125+
126+
```php
127+
[
128+
'urlfield' => 'url',
129+
'titlefield' => 'title',
130+
'textfield' => 'text',
131+
'modified' => time(),
132+
'snippet' => 'feed/sitemap'
133+
'mime' => null,
134+
'sort' => true,
135+
]
136+
```
137+
138+
**virtual page in site/config.php**
139+
140+
```php
141+
return [
142+
'routes' => [
143+
// ... other routes,
144+
[
145+
'pattern' => 'sitemap.xml',
146+
'method' => 'GET',
147+
'action' => function () {
148+
$options = [
149+
'images' => false,
150+
'videos' => false,
151+
];
152+
$feed = site()->index()->listed()->limit(50000)->sitemap($options);
153+
return $feed;
154+
}
155+
],
156+
],
157+
];
158+
```
159+
160+
**example for excluding pages from sitemap**
161+
162+
see [Kirby Docs -Filtering compendium](https://getkirby.com/docs/cookbook/content/filtering)
163+
164+
```php
165+
$feed = site()->index()->listed()->filterBy('template', '!=', 'excludeme')->limit(50000)->sitemap($options);
166+
```
167+
168+
112169
## Settings
113170

114171
| bnomei.feed. | Default | Description |

classes/Feed.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ private function modifiedHashFromKeys(): string
115115
public function optionsFromDefault(?Pages $pages = null, $options = []): array
116116
{
117117
$defaults = [
118+
// json/rss
118119
'url' => site()->url(),
119120
'feedurl' => site()->url() . '/feed/',
120121
'title' => 'Feed',
@@ -128,6 +129,18 @@ public function optionsFromDefault(?Pages $pages = null, $options = []): array
128129
'snippet' => 'feed/rss',
129130
'mime' => null,
130131
'sort' => true,
132+
// sitemap
133+
'images' => false,
134+
'imagesfield' => 'images',
135+
'imagetitlefield' => 'title',
136+
'imagecaptionfield' => 'caption',
137+
'imagelicensefield' => 'license',
138+
'videos' => false,
139+
'videosfield' => 'videos',
140+
'videotitlefield' => 'title',
141+
'videothumbnailfield' => 'thumbnail',
142+
'videodescriptionfield' => 'description',
143+
'videourlfield' => 'url',
131144
];
132145
$options = array_merge($defaults, $options);
133146

@@ -160,6 +173,9 @@ public function response(): Response
160173

161174
if ($mime !== null) {
162175
return new Response($this->string, $mime);
176+
}
177+
elseif ($snippet === 'feed/sitemap' && Feed::isXml($this->string)) {
178+
return new Response($this->string, 'xml');
163179
} elseif ($snippet === 'feed/json' || Feed::isJson($this->string)) {
164180
return new Response($this->string, 'json');
165181
} elseif ($snippet === 'feed/rss' || Feed::isXml($this->string)) {

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "bnomei/kirby3-feed",
33
"type": "kirby-plugin",
4-
"version": "1.3.10",
5-
"description": "Generate a RSS/JSON-Feed from a Pages-Collection",
4+
"version": "1.4.0",
5+
"description": "Generate a RSS/JSON/Sitemap-Feed from a Pages-Collection",
66
"license": "MIT",
77
"authors": [
88
{
@@ -17,7 +17,8 @@
1717
"rss-feed",
1818
"rss",
1919
"feed",
20-
"json"
20+
"json",
21+
"sitemap"
2122
],
2223
"autoload": {
2324
"psr-4": {
@@ -62,7 +63,6 @@
6263
"suggest": {
6364
"bnomei/kirby3-htmlhead": "Best-practice HTML Head Element extendable with snippets.",
6465
"bnomei/kirby3-security-headers": "CPS headers to make the the web a saver place. Sensible defaults with zero configuration.",
65-
"bnomei/kirby3-robots-txt": "Automatic robots.txt. Detects xmlsitemap.",
66-
"omz13/kirby3-xmlsitemap": "Adds a xml sitemap"
66+
"bnomei/kirby3-robots-txt": "Automatic robots.txt. Detects xmlsitemap."
6767
}
6868
}

0 commit comments

Comments
 (0)