Feed rendering
This commit is contained in:
parent
2f7e612b1e
commit
40ac35d228
|
@ -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);
|
||||
|
||||
|
|
|
@ -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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
26
resources/views/feed.blade.php
Normal file
26
resources/views/feed.blade.php
Normal 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>
|
Loading…
Reference in New Issue
Block a user