承接 chrishardie/laravel-feedmaker 相关项目开发

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

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

chrishardie/laravel-feedmaker

Composer 安装命令:

composer require chrishardie/laravel-feedmaker

包简介

Laravel package to enable crawling/parsing HTML pages and generating corresponding RSS feeds

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Laravel package to enable crawling/parsing HTML pages and generating corresponding RSS feeds

Installation

You can install the package via composer:

composer require chrishardie/laravel-feedmaker

You can publish and run the migrations with:

php artisan vendor:publish --provider="ChrisHardie\Feedmaker\FeedmakerServiceProvider" --tag="feedmaker-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="ChrisHardie\Feedmaker\FeedmakerServiceProvider" --tag="feedmaker-config"

This is the contents of the published config file:

return [
    // How often to update feeds from sources, in minutes
    'default_update_frequency' => 60,

    // Feed index web route
    'url' => '/',
];

Add a new disk to your config/filesystems.php file, to define where the generated RSS feeds will be stored:

    'disks' => [
        ...
        'feedmaker' => [
            'driver' => 'local',
            'root' => storage_path('app/feeds'),
            'url' => env('APP_URL').'/feeds',
            'visibility' => 'public',
        ],
        ...
    'links' => [
        ...
        public_path('feeds') => storage_path('app/feeds'),

Then, run artisan storage:link to make sure the storage disk is in place.

To display an index of available feeds, configure the $url variable in the config file and add the following to your routes/web.php file:

Route::feedsindex();

If you want to get notices about issues related to updating the feeds from sources, make sure you define a logging destination. For example, to receive Slack notifications, make sure LOG_SLACK_WEBHOOK_URL is defined in .env and then set your LOG_CHANNEL to include a log stack that includes Slack.

Usage

There are two steps for adding a new source to be included:

  1. Create a new Source model. If you don't have an admin interface, you can do this via tinker:
$ artisan tinker
>>> $s = new ChrisHardie\Feedmaker\Models\Source
>>> $s->class_name = 'YourSource'
>>> $s->source_url = 'https://www.example.com/news'
>>> $s->name = 'Source Name'
>>> $s->home_url = 'https://example.com/'
>>> $s->frequency = 60
>>> $s->save();

This tells the application the basic info about your source including the PHP class that will define how to scrape/crawl it, the URL to crawl, and the human-facing name and main URL.

  1. Create a source class in app/Sources/YourSource/YourSource.php that defines a generateRssItems() method returning a collection of items to include in the RSS feed. Here's an example:
<?php

namespace App\Sources\YourSource;

use ChrisHardie\Feedmaker\Sources\BaseSource;
use ChrisHardie\Feedmaker\Sources\RssItemCollection;
use ChrisHardie\Feedmaker\Models\Source;

class YourSource extends BaseSource
{
    /**
     * @param Source $source
     * @return RssItemCollection
     * @throws \JsonException
     * @throws SourceNotCrawlable
     */
    public function generateRssItems(Source $source) : RssItemCollection
    {
        $items = array();
        $html = HTTP::get($source->source_url);
        ...
        return RssItemCollection::make($items);    
    }
}

If you will be scraping a URL's dom via CSS or XPath selectors, you can use the scraper trait to simplify this. It handles the generateRssItems method for you, and all you have to do is define a parsse() method that returns an RssItemCollection:

<?php

namespace App\Sources\YourSource;

use ChrisHardie\Feedmaker\Sources\BaseSource;
use ChrisHardie\Feedmaker\Sources\RssItemCollection;
use ChrisHardie\Feedmaker\Models\Source;

class YourSource extends BaseSource
{
    use ScraperTrait;

    /**
     * @throws SourceNotCrawlable
     */
    public function parse(Crawler $crawler, Source $source) : RssItemCollection
    {
        $items = array();
        $nodes = $crawler->filter('.news-items');
        foreach ($nodes as $node) {
            ...
        }
        return RssItemCollection::make($items);
    }

The RssItemCollection must contain the following keys for each item:

  • pubDate: Carbon date object
  • title: string
  • url: string
  • description: string

Optionally, it can also contain these keys:

  • guid: a URL that will become the unique/GUID for the RSS item instead of the url

Then, you can force a check of your source and generate a corresponding feed:

$ artisan feeds:update YourSource

View the result at https://yoursite.com/feeds/yoursource.rss

An index of all generated feeds should be available at the URI defined in the config file.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Issues and Pull Requests are welcome.

Credits

License

The MIT License (MIT). Please see License File for more information.

chrishardie/laravel-feedmaker 适用场景与选型建议

chrishardie/laravel-feedmaker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 09 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 chrishardie/laravel-feedmaker 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 37
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-24