blog
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\Job;
|
||||
use App\Models\JobCategory;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
@@ -92,6 +93,9 @@ class SitemapService
|
||||
// Add jobs sitemap
|
||||
$this->addSitemapToIndex($xml, route('sitemap.jobs'), now());
|
||||
|
||||
// Add blog sitemap
|
||||
$this->addSitemapToIndex($xml, route('sitemap.blog'), now());
|
||||
|
||||
return $xml->asXML();
|
||||
}
|
||||
|
||||
@@ -105,6 +109,31 @@ class SitemapService
|
||||
$sitemapElement->addChild('lastmod', $lastmod->format('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate blog sitemap
|
||||
*/
|
||||
public function generateBlogSitemap(): string
|
||||
{
|
||||
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>');
|
||||
|
||||
$this->addUrl($xml, route('blog.index'), now(), 'daily', '0.8');
|
||||
|
||||
Article::published()
|
||||
->orderByDesc('published_at')
|
||||
->get(['slug', 'published_at', 'updated_at'])
|
||||
->each(function (Article $article) use ($xml) {
|
||||
$this->addUrl(
|
||||
$xml,
|
||||
route('blog.show', $article),
|
||||
$article->updated_at,
|
||||
'monthly',
|
||||
'0.7'
|
||||
);
|
||||
});
|
||||
|
||||
return $xml->asXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate main sitemap (static pages and categories)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user