66 lines
2.6 KiB
PHP
66 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\CmsPage;
|
|
use App\Models\SiteSetting;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
final class SeoController extends Controller
|
|
{
|
|
public function sitemap(): Response
|
|
{
|
|
$static = collect([
|
|
['route' => 'home', 'priority' => '1.0', 'frequency' => 'weekly'],
|
|
['route' => 'features', 'priority' => '0.9', 'frequency' => 'monthly'],
|
|
['route' => 'buy', 'priority' => '0.9', 'frequency' => 'monthly'],
|
|
['route' => 'release', 'priority' => '0.8', 'frequency' => 'weekly'],
|
|
['route' => 'support', 'priority' => '0.6', 'frequency' => 'monthly'],
|
|
['route' => 'privacy', 'priority' => '0.3', 'frequency' => 'yearly'],
|
|
['route' => 'terms', 'priority' => '0.3', 'frequency' => 'yearly'],
|
|
['route' => 'refund', 'priority' => '0.3', 'frequency' => 'yearly'],
|
|
['route' => 'cookies', 'priority' => '0.3', 'frequency' => 'yearly'],
|
|
])->filter(fn (array $item) => Route::has($item['route']))->values();
|
|
|
|
$pages = CmsPage::query()
|
|
->where('is_published', true)
|
|
->where('include_in_sitemap', true)
|
|
->where('robots_index', true)
|
|
->where(fn ($query) => $query->whereNull('published_at')->orWhere('published_at', '<=', now()))
|
|
->orderBy('slug')
|
|
->get();
|
|
|
|
return response()
|
|
->view('seo.sitemap', compact('static', 'pages'))
|
|
->header('Content-Type', 'application/xml; charset=UTF-8')
|
|
->header('Cache-Control', 'public, max-age=3600');
|
|
}
|
|
|
|
public function indexNowKey(string $key): Response
|
|
{
|
|
$configured = trim((string) config('indexnow.key'));
|
|
|
|
abort_unless(config('indexnow.enabled') && $configured !== '' && hash_equals($configured, $key), 404);
|
|
|
|
return response($configured, 200, [
|
|
'Content-Type' => 'text/plain; charset=UTF-8',
|
|
'Cache-Control' => 'public, max-age=86400',
|
|
]);
|
|
}
|
|
|
|
public function robots(): Response
|
|
{
|
|
$indexable = app()->environment('production') && SiteSetting::booleanFor('seo_robots_enabled', true);
|
|
|
|
$body = $indexable
|
|
? "User-agent: *\nAllow: /\nDisallow: /admin/\nDisallow: /portal/\nDisallow: /login\nDisallow: /register\n\nSitemap: ".route('sitemap')."\n"
|
|
: "User-agent: *\nDisallow: /\n";
|
|
|
|
return response($body, 200, [
|
|
'Content-Type' => 'text/plain; charset=UTF-8',
|
|
'Cache-Control' => 'public, max-age=3600',
|
|
]);
|
|
}
|
|
}
|