承接 bnomei/kirby3-feed 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bnomei/kirby3-feed

Composer 安装命令:

composer require bnomei/kirby3-feed

包简介

Generate a Atom/JSON/RSS-Feed and XML-Sitemap from Pages-Collections

README 文档

README

Kirby 5 PHP 8.2 Release Downloads Coverage Maintainability Discord Buymecoffee

Generate a Atom/JSON/RSS-Feed and XML-Sitemap from Pages-Collection.

Installation

  • unzip master.zip as folder site/plugins/kirby3-feed or
  • git submodule add https://github.com/bnomei/kirby3-feed.git site/plugins/kirby3-feed or
  • composer require bnomei/kirby3-feed

Usage Feed

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

<?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 array defaults

If you use these defaults you need to provide the fields date (type: date) and text (type: text).

[
    'datefield' => 'date',
    'dateformat' => 'r',
    'description' => '',
    'feedurl' => site()->url() . '/feed/',
    'link' => site()->url(),
    'mime' => null,
    'modified' => time(),
    'snippet' => 'feed/rss', // 'feed/json', 'feed/atom'
    'sort' => true,
    'textfield' => 'text',
    'title' => 'Feed',
    'titlefield' => 'title',
    'url' => site()->url(),
    'urlfield' => 'url',
]

virtual page in 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',
                    'feedurl' => site()->url() . '/feed/', // matches pattern above
                ];
                
                // while this would be possible
                // return page('blog')->children()->listed()->flip()->limit(10)->feed($options);
                
                // using a closure allows for better performance on a cache hit
                return feed(fn() => page('blog')->children()->listed()->flip()->limit(10), $options);
            }
        ],
    ],
];

HTML head element

rss xml

<link rel="alternate" type="application/rss+xml" title="Latest articles" href="<?= site()->url() ?>/feed"/>

and/or rss json

<link rel="alternate" type="application/json" title="Latest articles" href="<?= site()->url() ?>/feed"/>

TIP: Having multiple feed links is still valid html. So you can have both rss and json if you want and setup the routes properly.

Sorting

The Plugin applies a default sorting for the pages by date/modified in descending order (newest first).

  • If you do not want this you have to set the datefield setting to another Field name or PageMethod name.
  • If you want to disable sorting by the plugin and add your own you can set the option sort to false.

Pitfalls when presorting by date and limit

Using sortBy('date', 'desc') will not yield expected results! In K3 sorting by date needs a callback.

$feed = page('blog')->children()->listed()->sortBy(function ($page) {
 return $page->date()->toDate();
}, 'desc')->limit(10)->feed($options);

Usage Sitemap

options array defaults

If you use these defaults you need to provide the fields date (type: date) and text (type: text).

[
    'dateformat' => 'c',
    'feedurl' => site()->url().'/sitemap.xml',
    'imagecaptionfield' => 'caption',
    'imagelicensefield' => 'license',
    'images' => false,
    'imagesfield' => 'images',
    'imagetitlefield' => 'title',
    'mime' => null,
    'modified' => time(),
    'snippet' => 'feed/sitemap',
    'sort' => true,
    'urlfield' => 'url',
    'videodescriptionfield' => 'description',
    'videos' => false,
    'videosfield' => 'videos',
    'videothumbnailfield' => 'thumbnail',
    'videotitlefield' => 'title',
    'videourlfield' => 'url',
    'xsl' => true,
]

virtual page in site/config.php

return [
    'routes' => [
        // ... other routes,
        [
            'pattern' => 'sitemap.xml',
            'method' => 'GET',
            'action'  => function () {
                // while this would be possible
                // return site()->index()->listed()->limit(50000)->sitemap();
                
                // using a closure allows for better performance on a cache hit
                return sitemap(fn() => site()->index()->listed()->limit(50000));
            }
        ],
        // (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;
            }
        ],
    ],
];

example for excluding pages from sitemap

see the official Kirby documentation: Filtering compendium

return sitemap(fn() => site()->index()->listed()
    ->filterBy('template', '!=', 'excludeme')
    ->limit(50000)
);

Settings

bnomei.feed. Default Description
expires 60*24*7 expire cache in minutes, or on any change to content

Cache

Warning

If the global debug option is set to true the plugin will automatically flush its own cache. The plugin will automatically in-validate the cache if any of the Page objects in given Pages-Collection were modified with the Panel.

If you need to flush the cache manually, like after automated deployments or transferring files via FTP, you can use the following code:

\Bnomei\Feed::flush();

Or simply delete the cache files/folder at site/cache/{{ HOST }}/plugins/bnomei/feed.

Disclaimer

This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.

License

MIT

It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.

Credits

based on K2 versions of

bnomei/kirby3-feed 适用场景与选型建议

bnomei/kirby3-feed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26.79k 次下载、GitHub Stars 达 72, 最近一次更新时间为 2018 年 09 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「json」 「Sitemap」 「atom」 「feed」 「rss」 「kirby」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bnomei/kirby3-feed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bnomei/kirby3-feed 我们能提供哪些服务?
定制开发 / 二次开发

基于 bnomei/kirby3-feed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 26.79k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 72
  • 点击次数: 23
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

  • Stars: 72
  • Watchers: 5
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-07