sergeybruhin / xml-sitemap
Laravel XML Sitemap 包
1.0.2
2023-01-07 18:56 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-04 19:48:43 UTC
README
一个简单的基本包,帮助你生成 XML 站点地图。
安装
您可以通过 composer 安装此包
composer require sergeybruhin/xml-sitemap
使用 Laravel 命令或您想要的任何位置组合和存储 Sitemaps
<?php namespace App\Console\Commands; use App\Models\Page; use Illuminate\Console\Command; use SergeyBruhin\XmlSitemap\Dto\XmlSitemapImage; use SergeyBruhin\XmlSitemap\Dto\XmlSitemapSitemap; use SergeyBruhin\XmlSitemap\Dto\XmlSitemapUrl; use SergeyBruhin\XmlSitemap\Facades\XmlSitemap; class GenerateSitemapCommand extends Command { protected $signature = 'generate:sitemap'; protected $description = 'Generate sitemap'; public function __construct() { parent::__construct(); } public function handle(): int { $sitemapIndex = XmlSitemap::createIndex(); $sitemapIndex->addSitemap($this->createPagesSitemap()); XmlSitemap::storeIndex($sitemapIndex); foreach ($sitemapIndex->sitemaps as $sitemap) { XmlSitemap::storeSitemap($sitemap); } return 1; } private function createPagesSitemap(): XmlSitemapSitemap { $sitemap = XmlSitemap::createSitemap('pages_sitemap.xml'); Page::each(function (Page $page) use ($sitemap) { $url = new XmlSitemapUrl(route('page', $page->slug), 0.8); $url->setLastModificationDate($page->updated_at); $url->setFrequency(XmlSitemapUrl::WEEKLY); $url->addAlternate(route('page', $page->slug) . '/en', 'en'); $url->addImage((new XmlSitemapImage('https://some/image/url.png'))); $sitemap->addUrl($url); }); return $sitemap; } }
通过调度器定期运行命令
protected function schedule(Schedule $schedule): void { $schedule->command('generate:sitemap')->hourly(); }
测试(尚未 💁♂️)
composer test
变更日志
请参阅变更日志以获取有关最近更改的更多信息。
贡献
请参阅贡献指南以获取详细信息。
安全
如果您发现任何与安全相关的问题,请通过sundaycreative@gmail.com发送电子邮件,而不是使用问题跟踪器。
鸣谢
许可证
MIT 许可证(MIT)。有关更多信息,请参阅许可证文件。