]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/SitemapXmlController.php
add index option for tech sites
[alttp.git] / app / Http / Controllers / SitemapXmlController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Models\SitemapUrl;
6 use App\Models\Technique;
7 use App\Models\Tournament;
8 use Illuminate\Http\Request;
9
10 class SitemapXmlController extends Controller
11 {
12
13         public function index() {
14                 $urls = [];
15
16                 foreach (Tournament::all() as $tournament) {
17                         $url = new SitemapUrl();
18                         $url->path = '/tournaments/'.$tournament->id;
19                         $url->lastmod = $tournament->updated_at ? $tournament->updated_at : ($tournament->created_at ? $tournament->created_at : now());
20                         $url->changefreq = $tournament->locked ? 'never' : 'daily';
21                         $url->priority = $tournament->locked ? 0.5 : 1.0;
22                         $urls[] = $url;
23                 }
24
25                 foreach (Technique::where('index', true)->get() as $tech) {
26                         $url = new SitemapUrl();
27                         $url->path = '/tech/'.rawurlencode($tech->name);
28                         $url->lastmod = $tech->updated_at ? $tech->updated_at : ($tech->created_at ? $tech->created_at : now());
29                         $url->changefreq = 'monthly';
30                         $url->priority = $tech->priority;
31                         $urls[] = $url;
32                 }
33
34                 return response()->view('sitemap', [
35                         'urls' => $urls,
36                 ])->header('Content-Type', 'text/xml');
37         }
38
39 }