From 891868eccd24222722d09275412db347a79efd74 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 18 Oct 2023 19:54:57 +0300 Subject: [PATCH] implement sitemap --- src/Controller/TorrentController.php | 35 ++++++++++++++++++++++ templates/default/torrent/sitemap.xml.twig | 15 ++++++++++ 2 files changed, 50 insertions(+) create mode 100644 templates/default/torrent/sitemap.xml.twig diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index c6a9213..51b3794 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -1884,6 +1884,41 @@ class TorrentController extends AbstractController return new Response(); // @TODO } + #[Route( + '/sitemap.xml', + methods: + [ + 'GET' + ] + )] + public function sitemap( + TorrentService $torrentService + ): Response + { + $locale = $this->getParameter('app.locale'); + $locales = explode('|', $this->getParameter('app.locales')); + + $response = new Response(); + $response->headers->set('Content-Type', 'text/xml'); + + return $this->render( + 'default/torrent/sitemap.xml.twig', + [ + 'locale' => $locale, + 'locales' => $locales, + 'torrents' => $torrentService->findTorrents( + [], // without keywords filter + $locales, // all sensitive levels + null, // all sensitive levels + true, // approved only + 1000, // @TODO limit + 0 // offset + ) + ], + $response + ); + } + private function initUser( Request $request, UserService $userService, diff --git a/templates/default/torrent/sitemap.xml.twig b/templates/default/torrent/sitemap.xml.twig new file mode 100644 index 0000000..99d77e5 --- /dev/null +++ b/templates/default/torrent/sitemap.xml.twig @@ -0,0 +1,15 @@ + + + {% for torrent in torrents %} + + {{ torrent.added | date('Y-m-d') }} + {% for code in locales %} + {% if code == locale %} + {{ url('torrent_info', { '_locale': code , torrentId : torrent.id }) }} + {% else %} + + {% endif %} + {% endfor %} + + {% endfor %} +