feat: implement multilingual support for sitemap and SEO, update structured data, and improve locale middleware configuration
This commit is contained in:
@@ -12,24 +12,50 @@ class SitemapController extends Controller
|
||||
public function index(): Response
|
||||
{
|
||||
$urls = [];
|
||||
$activeLanguages = [];
|
||||
if (class_exists(\App\Models\Language::class)) {
|
||||
$activeLanguages = \App\Models\Language::where('is_active', true)->get();
|
||||
}
|
||||
|
||||
$getAlternates = function (string $baseUrl) use ($activeLanguages) {
|
||||
$alternates = [];
|
||||
foreach ($activeLanguages as $lang) {
|
||||
$connector = str_contains($baseUrl, '?') ? '&' : '?';
|
||||
$alternates[] = [
|
||||
'hreflang' => $lang->code,
|
||||
'href' => $baseUrl . $connector . 'locale=' . $lang->code,
|
||||
];
|
||||
}
|
||||
$alternates[] = [
|
||||
'hreflang' => 'x-default',
|
||||
'href' => $baseUrl,
|
||||
];
|
||||
return $alternates;
|
||||
};
|
||||
|
||||
// 1. Static & Main Pages
|
||||
$homeUrl = url('/');
|
||||
$urls[] = [
|
||||
'loc' => url('/'),
|
||||
'loc' => $homeUrl,
|
||||
'alternates' => $getAlternates($homeUrl),
|
||||
'lastmod' => now()->startOfDay()->toAtomString(),
|
||||
'changefreq' => 'daily',
|
||||
'priority' => '1.0',
|
||||
];
|
||||
|
||||
$blogIndexUrl = route('blog.index');
|
||||
$urls[] = [
|
||||
'loc' => route('blog.index'),
|
||||
'loc' => $blogIndexUrl,
|
||||
'alternates' => $getAlternates($blogIndexUrl),
|
||||
'lastmod' => now()->startOfDay()->toAtomString(),
|
||||
'changefreq' => 'weekly',
|
||||
'priority' => '0.8',
|
||||
];
|
||||
|
||||
$careerIndexUrl = route('career.index');
|
||||
$urls[] = [
|
||||
'loc' => route('career.index'),
|
||||
'loc' => $careerIndexUrl,
|
||||
'alternates' => $getAlternates($careerIndexUrl),
|
||||
'lastmod' => now()->startOfMonth()->toAtomString(),
|
||||
'changefreq' => 'monthly',
|
||||
'priority' => '0.5',
|
||||
@@ -40,8 +66,10 @@ class SitemapController extends Controller
|
||||
->where('is_homepage', false)
|
||||
->get();
|
||||
foreach ($pages as $page) {
|
||||
$pageUrl = url($page->slug);
|
||||
$urls[] = [
|
||||
'loc' => url($page->slug),
|
||||
'loc' => $pageUrl,
|
||||
'alternates' => $getAlternates($pageUrl),
|
||||
'lastmod' => $page->updated_at->toAtomString(),
|
||||
'changefreq' => 'weekly',
|
||||
'priority' => '0.7',
|
||||
@@ -52,8 +80,10 @@ class SitemapController extends Controller
|
||||
if (class_exists(Blog::class)) {
|
||||
$posts = Blog::published()->get();
|
||||
foreach ($posts as $post) {
|
||||
$postUrl = route('blog.show', $post->slug);
|
||||
$urls[] = [
|
||||
'loc' => route('blog.show', $post->slug),
|
||||
'loc' => $postUrl,
|
||||
'alternates' => $getAlternates($postUrl),
|
||||
'lastmod' => $post->updated_at->toAtomString(),
|
||||
'changefreq' => 'weekly',
|
||||
'priority' => '0.6',
|
||||
@@ -65,8 +95,10 @@ class SitemapController extends Controller
|
||||
if (class_exists(Product::class)) {
|
||||
$products = Product::where('is_active', true)->get();
|
||||
foreach ($products as $product) {
|
||||
$productUrl = route('products.show', $product->slug);
|
||||
$urls[] = [
|
||||
'loc' => route('products.show', $product->slug),
|
||||
'loc' => $productUrl,
|
||||
'alternates' => $getAlternates($productUrl),
|
||||
'lastmod' => $product->updated_at->toAtomString(),
|
||||
'changefreq' => 'weekly',
|
||||
'priority' => '0.7',
|
||||
|
||||
Reference in New Issue
Block a user