Browse Source

implement rss feeds

master
ghost 9 months ago
parent
commit
19718ab4e1
  1. 28
      src/Controller/MainController.php
  2. 5
      templates/default/main/index.html.twig
  3. 17
      templates/default/main/index.rss.twig
  4. 5
      templates/default/main/namespace.html.twig
  5. 17
      templates/default/main/namespace.rss.twig

28
src/Controller/MainController.php

@ -28,13 +28,20 @@ class MainController extends AbstractController @@ -28,13 +28,20 @@ class MainController extends AbstractController
]
)]
public function index(
?Request $request
?Request $request,
?Response $response
): Response
{
$index = new \Kvazar\Index\Manticore();
if ($rss = ('rss' == $request->get('feed')))
{
$response = new Response();
$response->headers->set('Content-Type', 'text/xml');
}
return $this->render(
'default/main/index.html.twig',
$rss ? 'default/main/index.rss.twig' : 'default/main/index.html.twig',
[
'request' => $request,
'records' => $index->get(
@ -46,7 +53,8 @@ class MainController extends AbstractController @@ -46,7 +53,8 @@ class MainController extends AbstractController
$request->get('part') > 1 ? (int) $request->get('part') * $this->getParameter('app.main.index.limit') : 0,
$this->getParameter('app.main.index.limit')
)
]
],
$response
);
}
@ -68,13 +76,20 @@ class MainController extends AbstractController @@ -68,13 +76,20 @@ class MainController extends AbstractController
]
)]
public function namespace(
?Request $request
?Request $request,
?Response $response
): Response
{
$index = new \Kvazar\Index\Manticore();
if ($rss = ('rss' == $request->get('feed')))
{
$response = new Response();
$response->headers->set('Content-Type', 'text/xml');
}
return $this->render(
'default/main/namespace.html.twig',
$rss ? 'default/main/namespace.rss.twig' : 'default/main/namespace.html.twig',
[
'request' => $request,
'records' => $index->get(
@ -93,7 +108,8 @@ class MainController extends AbstractController @@ -93,7 +108,8 @@ class MainController extends AbstractController
'title' => $this->_title(
$request->get('namespace')
)
]
],
$response
);
}

5
templates/default/main/index.html.twig

@ -60,4 +60,9 @@ @@ -60,4 +60,9 @@
}
) }}">{{ 'newer' | trans }}</a>
</div>
<div class="t-center px-16">
<div class="pb-16 f-s-12">
<a href="{{ path('main_index',{'feed':'rss'}) }}">{{ 'RSS' | trans }}</a>
</div>
</div>
{% endblock %}

17
templates/default/main/index.rss.twig

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<atom:link href="{{ url('main_index') }}" rel="self" type="application/rss+xml"></atom:link>
<title>{{ app.name }}</title>
<link>{{ url('main_index') }}</link>
{% for record in records %}
<item>
<title>{{ record.key }}</title>
<author>{{ record.namespace }}</author>
<pubDate>{{ record.time | date('D, d M Y h:i:s O') }}</pubDate>
<guid>{{ url('main_transaction',{'transaction':record.transaction}) }}</guid>
<link>{{ url('main_transaction',{'transaction':record.transaction}) }}</link>
</item>
{% endfor %}
</channel>
</rss>

5
templates/default/main/namespace.html.twig

@ -63,4 +63,9 @@ @@ -63,4 +63,9 @@
}
) }}">{{ 'newer' | trans }}</a>
</div>
<div class="t-center px-16">
<div class="pb-16 f-s-12">
<a href="{{ path('main_namespace',{'namespace':request.get('namespace'),'feed':'rss'}) }}">{{ 'RSS' | trans }}</a>
</div>
</div>
{% endblock %}

17
templates/default/main/namespace.rss.twig

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<atom:link href="{{ url('main_namespace',{'namespace':request.get('namespace')}) }}" rel="self" type="application/rss+xml"></atom:link>
<title>{{ app.name }}</title>
<link>{{ url('main_namespace',{'namespace':request.get('namespace')}) }}</link>
{% for record in records %}
<item>
<title>{{ record.key }}</title>
<author>{{ record.namespace }}</author>
<pubDate>{{ record.time | date('D, d M Y h:i:s O') }}</pubDate>
<guid>{{ url('main_transaction',{'transaction':record.transaction}) }}</guid>
<link>{{ url('main_transaction',{'transaction':record.transaction}) }}</link>
</item>
{% endfor %}
</channel>
</rss>
Loading…
Cancel
Save