idsqm/php-sitemap
最新稳定版本:v0.1
Composer 安装命令:
composer require idsqm/php-sitemap
包简介
Simple sitemap generator
README 文档
README
Description
A library for generating and exporting Sitemaps in xml, json, and csv formats. It is possible to register your own formats
Usage example
Generation sitemap.xml
<?php use Carbon\Carbon; use Idsqm\Sitemap\SimpleFilesystemWriter; use Idsqm\Sitemap\SitemapGenerator; $generator = new SitemapGenerator( 'https://test.com/', [ ['loc' => 'page/one', 'lastmod' => date('Y-m-d'), 'changefreq' => 'daily', 'priority' => 0.5], ['loc' => 'page/two', 'lastmod' => Carbon::today(), 'changefreq' => 'monthly', 'priority' => 0.6], ['loc' => 'another-section'], ], 'xml', '/var/www/public/sitemap.xml', new SimpleFilesystemWriter(), ); $generator->export();
Example of registering a sitemap exporter in a different format:
<?php use Idsqm\Sitemap\Sitemap; use Idsqm\Sitemap\SitemapExporter; use Idsqm\Sitemap\SitemapExporterFactory; SitemapExporterFactory::register('new-format', fn() => new class implements SitemapExporter { public function execute(Sitemap $sitemap): string { $result = ''; foreach ($sitemap->getSitemapRecords() as $sitemapRecord) { $result .= $sitemapRecord->getLoc(); } return $result; } }); // Using a new exporter $generator = new SitemapGenerator( 'https://test.com/', [ ['loc' => 'page/one'] ], 'new-format', '/var/www/public/sitemap.format', new SimpleFilesystemWriter(), ); $generator->export();
Run tests
./vendor/bin/phpunit
Linter
The phpstan static code analyzer is used
Make the script executable:
chmod +x utils/linter/linter.sh
Run linter
./utils/linter/linter.sh
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-07