1
0

Feed rendering

This commit is contained in:
Richard Dern 2024-04-26 21:55:05 +02:00
parent 2f7e612b1e
commit 40ac35d228
3 changed files with 63 additions and 0 deletions

View File

@ -268,6 +268,10 @@ private function repairCover()
*/
private function normalizeBundlePath(string $path): string
{
if ($path === './' || $path === '' || $path === '.') {
return '/';
}
$parts = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY);
$count = count($parts);

View File

@ -6,6 +6,20 @@
class ListRenderer extends BaseRenderer
{
/**
* Renders a complete HTML view of the bundle
*/
public function render()
{
$baseRender = parent::render();
if ($this->bundle->getPath() === '/') {
$baseRender['/index.xml'] = $this->renderFeed();
}
return $baseRender;
}
/**
* Return a boolean value indicating if this creator in particular can
* create bundles for specified section
@ -16,4 +30,23 @@ public static function handles(Bundle $bundle): bool
// can handle the path
return false;
}
private function renderFeed()
{
$bundles = $this->getSubBundles();
$lastBundles = array_map(
function ($item) {
$bundle = new Bundle($item, $this->bundle->getDisk());
$bundle->load();
return $bundle;
},
array_slice($bundles, 0, 10)
);
return (string) view('feed', [
'bundles' => $lastBundles,
'lastBuildDate' => now()->toRssString(),
]);
}
}

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<channel>
<title>{{ config('app.name') }}</title>
<link>{{ config('app.url') }}</link>
<description>{{ config('app.description') }}</description>
<pubDate>{{ $lastBuildDate }}</pubDate>
@foreach ($bundles as $bundle)
<item>
<title>[{{ $bundle->getSection()->getArticleTitle() }}] {{ $bundle->getArticleTitle() }}</title>
<link>{{ $bundle->getPath() }}</link>
<pubDate>{{ Carbon\Carbon::parse($bundle->metadata()->get('date'))->toRssString() }}</pubDate>
<guid>{{ $bundle->getPath() }}</guid>
<content:encoded>
<![CDATA[
@if(!empty($bundle->metadata()->get('cover')))
{!! $bundle->attachments(\App\Classes\AttachmentsManager::Images)->getComponentByRef($bundle->metadata()->get('cover'), 'article')->render() !!}
@endif
{!! $bundle->markdown()->render() !!}
]]>
</content:encoded>
</item>
@endforeach
</channel>
</rss>