Unify FNA homepage, archives, canonical URLs and durable SEO publishing
This commit is contained in:
1 parent
a820755e7e
commit
7c11ca77bc
41 files changed
+808
-493
No files matched your search
@@ -1,37 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Articles;
|
||||
use App\Models\Categories;
|
||||
use App\Services\Seo;
|
||||
use App\Services\ArticlesService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class SitemapController extends Controller
|
||||
{
|
||||
public function index(): Response
|
||||
{
|
||||
// Use the same expiry rule as article metadata, including on SQLite in isolated tests.
|
||||
$cArticles = Articles::where('iStatus', 1)
|
||||
->where('created_at', '<=', now())
|
||||
->whereHas('oCategory', fn ($q) => $q->where('iStatus', 1))
|
||||
->with('oCategory')
|
||||
->orderBy('created_at', 'desc')
|
||||
->get()->reject(fn ($article) => $article->bIsSeoExpired());
|
||||
|
||||
$visible = fn ($q) => $q->where('iStatus', 1)->where('created_at', '<=', now());
|
||||
$cCategories = Categories::whereIn('sSlug', ['client', 'advanced'])
|
||||
->where('iParentId', 0)->where('iStatus', 1)
|
||||
->where(function ($q) use ($visible) {
|
||||
$q->whereHas('aArticles', $visible)->orWhereHas('aChildren', function ($children) use ($visible) {
|
||||
$children->where('iStatus', 1)->whereHas('aArticles', $visible);
|
||||
});
|
||||
})->orderBy('sSlug')->get();
|
||||
|
||||
$sXmlContent = view('sitemap', [
|
||||
'cArticles' => $cArticles,
|
||||
'cCategories' => $cCategories,
|
||||
])->render();
|
||||
|
||||
return response($sXmlContent, 200)->header('Content-Type', 'text/xml');
|
||||
$articles = Articles::publicVisible()->with('oCategory.oParent')->orderByDesc('created_at')->orderByDesc('id')->get();
|
||||
$latest = app(ArticlesService::class)->getLatestFreeNodeSlug();
|
||||
$home = $latest ? $articles->firstWhere('sSlug',$latest) : null;
|
||||
$entries = $home ? [['url'=>Seo::url(),'modified'=>Seo::modified($home)]] : [];
|
||||
foreach (Categories::where('iStatus',1)->with('oParent')->orderBy('id')->get() as $category) {
|
||||
if ($category->iParentId && (!$category->oParent || !$category->oParent->iStatus)) continue;
|
||||
$members = $articles->filter(fn($a)=>$a->iCategoryId === $category->id || ($category->iShowChildren && $a->oCategory->iParentId === $category->id));
|
||||
if ($members->isNotEmpty()) $entries[] = ['url'=>Seo::url(Seo::categoryPath($category)),'modified'=>null];
|
||||
}
|
||||
foreach ($articles->filter(fn($a)=>Seo::indexable($a)) as $a) $entries[] = ['url'=>Seo::articleUrl($a),'modified'=>Seo::modified($a)];
|
||||
return response()->view('sitemap',['entries'=>$entries])->header('Content-Type','application/xml; charset=UTF-8');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user