init
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled

This commit is contained in:
jiangdong.cheng
2026-02-11 17:28:36 +08:00
parent dcb82557c7
commit aa16c9f8c2
162 changed files with 22333 additions and 0 deletions

View 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']);
}
}