youkoulayley/podcastfeed

为Laravel 5中的播客生成RSS订阅源。

v0.4.2 2021-02-23 19:13 UTC

README

为Laravel 5中的播客生成RSS订阅源。

安装

在命令行中运行

$ composer require torann/podcastfeed

设置

安装完成后,您需要将服务提供者注册到应用中。打开 config/app.php 文件,找到 providers 键。

'providers' => [
    ...

    Youkoulayley\PodcastFeed\PodcastFeedServiceProvider::class,

    ...
]

此包还包含一个外观,它提供了一个方便的方式来调用类。打开 config/app.php 文件,找到 aliases

'aliases' => [
    ...

    'PodcastFeed' => Youkoulayley\PodcastFeed\Facades\PodcastFeed::class,

    ...
];

发布配置

在项目根目录下,从命令行运行以下命令

$ php artisan vendor:publish --provider="Youkoulayley\PodcastFeed\PodcastFeedServiceProvider"

配置文件将被发布到 config/podcast-feed.php

方法

setHeader 可以在配置文件中设置或手动使用 setHeader 方法来设置订阅源的头信息

PodcastFeed::setHeader([
    'title'       => 'All About Everything',
    'subtitle'    => 'A show about everything',
    'description' => 'Great site description',
    'link'        => 'http://www.example.com/podcasts/everything/index.html',
    'image'       => 'http://example.com/podcasts/everything/AllAboutEverything.jpg',
    'author'      => 'John Doe',
    'email'       => 'john.doe@example.com',
    'explicit'    => 'clean',
    'category'    => 'Technology',
    'language'    => 'en-us',
    'copyright'   => '2016 John Doe & Family',
]);

addMedia 向订阅源添加媒体内容。

foreach($this->podcastRepository->getPublished() as $podcast)
{
    PodcastFeed::addMedia([
        'title'       => $podcast->title,
        'description' => $podcast->title,
        'publish_at'  => $podcast->publish_at,
        'guid'        => route('podcast.show', $podcast->slug),
        'url'         => $podcast->media->url(),
        'type'        => $podcast->media_content_type,
        'duration'    => $podcast->duration,
        'image'       => $podcast->image->url(),
    ]);
}

toString 将订阅源转换为可展示的字符串。下面的示例是从控制器中提取的。理论上,您可以实现缓存方法,以便不必每次都进行渲染。

public function index()
{
    foreach($this->podcastRepository->getPublished() as $podcast) {
        PodcastFeed::addMedia([
            'title'       => $podcast->title,
            'description' => $podcast->title,
            'publish_at'  => $podcast->publish_at,
            'guid'        => route('podcast.show', $podcast->slug),
            'url'         => $podcast->media->url(),
            'type'        => $podcast->media_content_type,
            'duration'    => $podcast->duration,
            'image'       => $podcast->image->url(),
        ]);
    }

    return Response::make(PodcastFeed::toString())
        ->header('Content-Type', 'text/xml');
}

变更日志

v0.2.1

  • 修复了如 'æ', 'ø' 和 'å' 这样的外文字符

v0.2.0

  • 支持Laravel 5

v0.1.0

  • 首次发布