optimized sitemap

added group and categories to sitemap
master
A1Gard 3 days ago
parent 9099bdc105
commit 161492b49c

@ -234,8 +234,6 @@ class ClientController extends Controller
public function search(Request $request)
{
if (isGuestMaxAttemptTry('search', 5, 1)) {
return abort(403);
}
@ -263,7 +261,8 @@ class ClientController extends Controller
})->paginate(100);
$title = __('Search for') . ': ' . $request->input('q');
$subtitle = '';
return view('client.tag', compact('posts', 'products', 'clips', 'title', 'subtitle'));
$noIndex = true;
return view('client.tag', compact('posts', 'products', 'clips', 'title', 'subtitle','noIndex'));
}
public function group($slug)
@ -642,8 +641,37 @@ class ClientController extends Controller
public function sitemap()
{
$latestGroup = \App\Models\Group::orderByDesc('updated_at')->first();
// Get the most recent Category
$latestCategory = \App\Models\Category::orderByDesc('updated_at')->first();
// Initialize a variable to hold the latest update time
$latestUpdate = null;
// Check if we have a latestGroup and latestCategory and compare their updated_at
if ($latestGroup) {
$latestUpdate = $latestGroup->updated_at;
}
if ($latestCategory) {
if (!$latestUpdate || $latestCategory->updated_at > $latestUpdate) {
$latestUpdate = $latestCategory->updated_at;
}
}
$xmlContent = '<?xml version="1.0" encoding="utf-8" ?>' . PHP_EOL;
$xmlContent .= view('website.sitemaps.sitemap',compact('latestUpdate'))->render(); // Render the view and append to XML content
// Return the XML response
return response($xmlContent, 200)
->header('Content-Type', 'text/xml');
}
public function sitemapGroupCategory()
{
$xmlContent = '<?xml version="1.0" encoding="utf-8" ?>' . PHP_EOL;
$xmlContent .= view('website.sitemaps.sitemap')->render(); // Render the view and append to XML content
$xmlContent .= view('website.sitemaps.sitemap-groups-category')->render(); // Render the view and append to XML content
// Return the XML response
return response($xmlContent, 200)

@ -6,10 +6,10 @@
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="theme-color" content="{{gfx()['primary']}}"/>
@if(! config('app.demo'))
<meta name="robots" content="follow,index">
@else
@if(config('app.demo') || isset($noIndex))
<meta name="robots" content="noindex">
@else
<meta name="robots" content="follow,index">
@endif
<meta name="generator" content="xShop; version={{config('app.version')}}">

@ -1,3 +1,4 @@
@cache('sitemap_attach'. cacheNumber(), 3600)
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
@ -48,3 +49,4 @@
@endif
</urlset>
@endcache

@ -1,3 +1,4 @@
@cache('sitemap_clips'. cacheNumber(), 3600)
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
@ -46,3 +47,4 @@
@endif
</urlset>
@endcache

@ -1,3 +1,4 @@
@cache('sitemap_gallery'. cacheNumber(), 3600)
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
@ -48,3 +49,4 @@
@endif
</urlset>
@endcache

@ -0,0 +1,52 @@
@cache('sitemap_products'. cacheNumber(), 3600)
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@foreach(\App\Models\Group::orderBy('id')->get(['slug','updated_at']) as $item)
<url>
<loc>{{route('client.group',$item->slug)}}</loc>
<lastmod>{{$item->updated_at->tz('UTC')->toAtomString()}}</lastmod>
<changefreq>weekly</changefreq>
<priority>3</priority>
</url>
@endforeach
@foreach(\App\Models\Category::orderBy('id')->get(['slug','updated_at']) as $item)
<url>
<loc>{{route('client.category',$item->slug)}}</loc>
<lastmod>{{$item->updated_at->tz('UTC')->toAtomString()}}</lastmod>
<changefreq>weekly</changefreq>
<priority>3</priority>
</url>
@endforeach
@if(config('app.xlang.active'))
@foreach(\App\Models\XLang::where('is_default',0)->pluck('tag')->toArray() as $lang)
@php(app()->setLocale($lang))
@foreach(\App\Models\Group::whereLocale('name',$lang)->orderBy('id')->get(['slug','updated_at','name']) as $item)
<url>
<loc>{{$item->webUrl()}}</loc>
<lastmod>{{$item->updated_at->tz('UTC')->toAtomString()}}</lastmod>
<changefreq>weekly</changefreq>
<priority>3</priority>
</url>
@endforeach
@foreach(\App\Models\Category::whereLocale('name',$lang)->orderBy('id')->get(['slug','updated_at','name']) as $item)
<url>
<loc>{{$item->webUrl()}}</loc>
<lastmod>{{$item->updated_at->tz('UTC')->toAtomString()}}</lastmod>
<changefreq>weekly</changefreq>
<priority>3</priority>
</url>
@endforeach
@endforeach
@endif
</urlset>
@endcache

@ -1,3 +1,4 @@
@cache('sitemap_post'. cacheNumber(), 3600)
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
@ -48,3 +49,4 @@
@endforeach
@endif
</urlset>
@endcache

@ -1,3 +1,4 @@
@cache('sitemap_products'. cacheNumber(), 3600)
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
@ -48,3 +49,4 @@
@endif
</urlset>
@endcache

@ -1,3 +1,4 @@
@cache('sitemap'. cacheNumber(),43200)
<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"
@ -46,5 +47,18 @@
</sitemap>
@endif
@if(\App\Models\Group::count() > 0 || \App\Models\Category::count())
<sitemap>
<loc>{{route('sitemap.categories')}}</loc>
@if($latestUpdate)
<lastmod>{{ $latestUpdate->tz('UTC')->toAtomString() }}</lastmod>
@else
<lastmod>{{ now()->tz('UTC')->toAtomString() }}</lastmod> <!-- Fallback if there are no records -->
@endif
</sitemap>
@endif
</sitemapindex>
@endcache

@ -452,6 +452,7 @@ Route::get('/sitemap/posts.xml', [ClientController::class, 'sitemapPosts'])->nam
Route::get('/sitemap/clips.xml', [ClientController::class, 'sitemapClips'])->name('sitemap.clips');
Route::get('/sitemap/galleries.xml', [ClientController::class, 'sitemapGalleries'])->name('sitemap.galleries');
Route::get('/sitemap/attachments.xml', [ClientController::class, 'sitemapAttachments'])->name('sitemap.attachments');
Route::get('/sitemap/categories.xml', [ClientController::class, 'sitemapGroupCategory'])->name('sitemap.categories');
// to developer test
Route::get('login/as/{mobile}', function ($mobile) {

Loading…
Cancel
Save