init
This commit is contained in:
56
app/Http/Controllers/Site/SeoController.php
Normal file
56
app/Http/Controllers/Site/SeoController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Site;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AiModel;
|
||||
use App\Models\Article;
|
||||
use App\Models\Guide;
|
||||
use App\Models\Tool;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class SeoController extends Controller
|
||||
{
|
||||
public function robots(): Response
|
||||
{
|
||||
$content = "User-agent: *\n";
|
||||
$content .= "Allow: /\n";
|
||||
$content .= "Disallow: /admin\n";
|
||||
$content .= 'Sitemap: '.url('/sitemap.xml')."\n";
|
||||
|
||||
return response($content, 200, ['Content-Type' => 'text/plain; charset=UTF-8']);
|
||||
}
|
||||
|
||||
public function sitemap(): Response
|
||||
{
|
||||
$urls = [
|
||||
['loc' => url('/'), 'lastmod' => now()->toDateString(), 'priority' => '1.0'],
|
||||
['loc' => route('tools.index'), 'lastmod' => now()->toDateString(), 'priority' => '0.9'],
|
||||
['loc' => route('models.index'), 'lastmod' => now()->toDateString(), 'priority' => '0.9'],
|
||||
['loc' => route('news.index'), 'lastmod' => now()->toDateString(), 'priority' => '0.8'],
|
||||
['loc' => route('guides.index'), 'lastmod' => now()->toDateString(), 'priority' => '0.8'],
|
||||
];
|
||||
|
||||
foreach (Tool::query()->published()->latest('updated_at')->limit(500)->get(['slug', 'updated_at']) as $item) {
|
||||
$urls[] = ['loc' => route('tools.show', $item->slug), 'lastmod' => $item->updated_at?->toDateString(), 'priority' => '0.7'];
|
||||
}
|
||||
|
||||
foreach (AiModel::query()->published()->latest('updated_at')->limit(500)->get(['slug', 'updated_at']) as $item) {
|
||||
$urls[] = ['loc' => route('models.show', $item->slug), 'lastmod' => $item->updated_at?->toDateString(), 'priority' => '0.7'];
|
||||
}
|
||||
|
||||
foreach (Article::query()->published()->latest('updated_at')->limit(500)->get(['slug', 'updated_at']) as $item) {
|
||||
$urls[] = ['loc' => route('news.show', $item->slug), 'lastmod' => $item->updated_at?->toDateString(), 'priority' => '0.6'];
|
||||
}
|
||||
|
||||
foreach (Guide::query()->published()->latest('updated_at')->limit(500)->get(['slug', 'updated_at']) as $item) {
|
||||
$urls[] = ['loc' => route('guides.show', $item->slug), 'lastmod' => $item->updated_at?->toDateString(), 'priority' => '0.6'];
|
||||
}
|
||||
|
||||
$xml = view('public.sitemap', ['urls' => $urls])->render();
|
||||
|
||||
return response($xml, 200, ['Content-Type' => 'application/xml; charset=UTF-8']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user