hydephp / publications

Upcoming Publications Feature - HydePHP Extension
MIT License
0 stars 0 forks source link

Allow publication pages to be used in the RSS feed generator #10

Closed caendesilva closed 1 year ago

caendesilva commented 1 year ago

Feature request by @rgasch is to add a way to include publication pages in the RSS feed

caendesilva commented 1 year ago

The way the feed generator works, is that the generate method of the RssFeedGenerator class is hard coded to get MarkdownPost::getLatestPosts().

This class is in turn called by the GenerateRssFeed build task. I think the easiest and most modular way to solve this issue is two part. On our end, we should add a feature to replace build tasks (if a user build task has the same class base name as a built in one, we only call the user's)

Then in userland, the user can create a custom GenerateRssFeed build task, which calls a custom RssFeedGenerator class.

caendesilva commented 1 year ago

When https://github.com/hydephp/develop/pull/1152 is merged, you will be able to do this by creating two new files:

<?php

namespace App\Actions;

use App\Services\RssFeedGenerator;
use Hyde\Framework\Actions\PostBuildTasks\GenerateRssFeed as BaseGenerateRssFeed;
use Hyde\Hyde;

class GenerateRssFeed extends BaseGenerateRssFeed
{
    public function handle(): void
    {
        file_put_contents(
            Hyde::sitePath(RssFeedGenerator::getFilename()),
            RssFeedGenerator::make()
        );
    }
}
<?php

namespace App\Services;

use Hyde\Framework\Features\XmlGenerators\RssFeedGenerator as BaseRssFeedGenerator;
use Hyde\Hyde;

class RssFeedGenerator extends BaseRssFeedGenerator
{
    public function generate(): static
    {
        // Update this

        MarkdownPost::getLatestPosts()->each(function (MarkdownPost $post): void {
            $this->addItem($post);
        });

        return $this;
    }
}

Then register it in config/hyde.php

'build_tasks' => [
    \App\Actions\GenerateRssFeed::class
]

I confirmed this works on my end in https://github.com/hydephp/develop/pull/1152

@rgasch does do you think this API will work for you? The custom build task will replace the framework one automatically, which allows you to create a custom feed generator.

caendesilva commented 1 year ago

Closing as fixed by https://github.com/hydephp/develop/pull/1152