bnomei / kirby3-feed
从页面集合生成RSS/JSON/Sitemap-Feed
1.7.0
2024-08-19 08:18 UTC
Requires
- php: >=8.1
- getkirby/composer-installer: ^1.2
Requires (Dev)
- getkirby/cms: ^4.0
- php-coveralls/php-coveralls: ^2.4
- phpunit/phpunit: ^9.5
Suggests
- bnomei/kirby3-htmlhead: Best-practice HTML Head Element extendable with snippets.
- bnomei/kirby3-robots-txt: Automatic robots.txt. Detects xmlsitemap.
- bnomei/kirby3-security-headers: CPS headers to make the the web a saver place. Sensible defaults with zero configuration.
This package is auto-updated.
Last update: 2024-09-19 08:26:37 UTC
README
从页面集合生成RSS/JSON/Sitemap-Feed。
商业使用
支持开源!
此插件是免费的,但如果您在商业项目中使用它,请考虑赞助我或捐款。
如果我的工作帮助您赚了一些钱,我认为我可能也应该得到一点回报,对吧?
友善。分享一点。谢谢。
- Bruno
类似插件
两者自2019年4月以来均未更新
安装
- 解压master.zip为文件夹
site/plugins/kirby3-feed
或 git submodule add https://github.com/bnomei/kirby3-feed.git site/plugins/kirby3-feed
或composer require bnomei/kirby3-feed
Feed使用
您可以在模板中用于专用Feed页面、模板控制器或路由中使用此功能。
<?php $options = [ 'title' => 'Latest articles', 'description' => 'Read the latest news about our company', 'link' => 'blog' ]; echo page('blog')->children()->listed()->flip()->limit(10)->feed($options);
options数组默认值
如果您使用这些默认值,您需要提供字段date (类型:日期)
和text (类型:文本)
。
[ 'url' => site()->url(), 'feedurl' => site()->url() . '/feed/', 'title' => 'Feed', 'description' => '', 'link' => site()->url(), 'urlfield' => 'url', 'titlefield' => 'title', 'datefield' => 'date', 'textfield' => 'text', 'modified' => time(), 'snippet' => 'feed/rss', // 'feed/json', 'feed/atom' 'dateformat' => 'r', 'mime' => null, 'sort' => true, ]
虚拟页面在site/config/config.php中
return [ 'routes' => [ [ 'pattern' => 'feed', 'method' => 'GET', 'action' => function () { $options = [ 'title' => 'Latest articles', 'description' => 'Read the latest news about our company', 'link' => 'blog' ]; $feed = page('blog')->children()->listed()->flip()->limit(10)->feed($options); return $feed; } ], ], ];
HTML头元素
rss xml
<link rel="alternate" type="application/rss+xml" title="Latest articles" href="<?= site()->url() ?>/feed"/>
和/或rss json
<link rel="alternate" type="application/json" title="Latest articles" href="<?= site()->url() ?>/feed"/>
提示:拥有多个feed链接仍然是有效的HTML。因此,如果您想同时拥有rss和json并正确设置路由,可以同时使用两者。
排序
插件将按日期/修改顺序对页面应用默认排序(最新先)。
- 如果您不希望这样,您必须将
datefield
设置设置为另一个字段名或页面方法名。 - 如果您想禁用插件中的排序并添加自己的排序,可以将选项
sort
设置为false
。
按日期和限制预排序时的陷阱
使用sortBy('date', 'desc')
将不会产生预期结果!在K3中,按日期排序需要一个回调。
$feed = page('blog')->children()->listed()->sortBy(function ($page) { return $page->date()->toDate(); }, 'desc')->limit(10)->feed($options);
Sitemap使用
options数组默认值
如果您使用这些默认值,您需要提供字段date (类型:日期)
和text (类型:文本)
。
[ 'dateformat' => 'c', 'xsl' => true, 'urlfield' => 'url', 'modified' => time(), 'snippet' => 'feed/sitemap', 'mime' => null, 'sort' => true, 'images' => false, 'imagesfield' => 'images', 'imagetitlefield' => 'title', 'imagecaptionfield' => 'caption', 'imagelicensefield' => 'license', 'videos' => false, 'videosfield' => 'videos', 'videotitlefield' => 'title', 'videothumbnailfield' => 'thumbnail', 'videodescriptionfield' => 'description', 'videourlfield' => 'url', ]
虚拟页面在site/config.php中
return [ 'routes' => [ // ... other routes, [ 'pattern' => 'sitemap.xml', 'method' => 'GET', 'action' => function () { $options = [ 'images' => false, 'videos' => false, ]; $feed = site()->index()->listed()->limit(50000)->sitemap($options); return $feed; } ], // (optional) Add stylesheet for human readable version of the xml file. // With that stylesheet visiting the xml in a browser will per-generate the images. // The images will NOT be pre-generated if the xml file is downloaded (by google). [ 'pattern' => 'sitemap.xsl', 'method' => 'GET', 'action' => function () { snippet('feed/sitemapxsl'); die; } ], ], ];
排除页面从Sitemap的示例
$feed = site()->index()->listed() ->filterBy('template', '!=', 'excludeme') ->limit(50000)->sitemap($options);
设置
如果任何页面对象被修改,插件将自动使缓存无效。
缓存
如果将全局调试选项设置为true
,则插件将自动刷新其自己的缓存而不写入缓存。
免责声明
此插件提供“原样”且没有任何保证。请自行承担风险,并在将插件用于生产环境之前自行测试。
许可证
不建议在任何宣传种族主义、性别歧视、恐同症、动物虐待、暴力或其他任何形式仇恨言论的项目中使用此插件。
致谢
基于K2版本的