krakero/podcastfeed

为 Laravel 生成播客 RSS 源

v1.0 2023-10-19 23:19 UTC

This package is auto-updated.

Last update: 2024-09-12 02:00:25 UTC


README

注意: 此软件包是从现有的软件包 Torann 分支出来的。

Laravel 播客生成器

为 Laravel 生成播客 RSS 源。

安装

从命令行运行

composer require krakero/podcastfeed

设置

一旦安装,您需要将服务提供者注册到应用程序中。打开 config/app.php 并找到 providers 键。

'providers' => [
    ...

    Krakero\PodcastFeed\PodcastFeedServiceProvider::class,

    ...
]

此软件包还包括一个外观,它提供了一种简单的方法来调用类。打开 config/app.php 并找到 aliases

'aliases' => [
    ...

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

    ...
];

发布配置

在项目根目录下从命令行运行此操作

$ php artisan vendor:publish --provider="Krakero\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',
    '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

  • 第一个版本