roelofjan-elsinga/sitemap-generator
Composer 安装命令:
composer require roelofjan-elsinga/sitemap-generator
包简介
This package helps you to very easily generate a sitemap for your website
README 文档
README
This package helps you to very easily generate a sitemap for your website.
Installation
You can include this package through Composer using:
composer require roelofjan-elsinga/sitemap-generator
Usage
use SitemapGenerator\SitemapGenerator; $generator = new SitemapGenerator(); $generator->add('https://test-url.com/'); $xml_string = (string)$generator; // OR $xml_string = $generator->toXML(); print $xml_string;
If you don't want to provide the domain name every single time, you can do any of the following steps:
$generator = new SitemapGenerator('https://test-url.com'); // or $generator = new SitemapGenerator(); $generator->setDomain('https://test-url.com'); // or $generator = SiteMapGenerator::boot('https://test-url.com');
Now that you have set the domain name, you can simply do this:
$generator->add('/');
This will result in:
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>https://test-url.com/</loc> <priority>1</priority> <lastmod>2019-03-26</lastmod> <changefreq>weekly</changefreq> </url> </urlset>
Available methods:
boot(): This provides a named constructor for the SitemapGenerator classremove(string $url): This will remove the given URL from the sitemaplinks(): This will given you the added URL's as an array
No duplication
The add() method will filter out any duplicate links,
so adding a link twice will not result in an additional link in the sitemap.
Customization
You can customize the priority, lastmod, and changefreq values by providing
the add() method with additional information:
public function add( string $url, $priority = 1, string $last_modified = null, string $change_frequency = 'weekly' ): SitemapGenerator
This means you can do something like this:
$generator->add('https://test-url.com/blog', 0.9, date('Y-m-d'), 'monthly'); // Or if you've set the domain earlier, this is even simpler: $generator = SitemapGenerator::boot()->setDomain('https://test-url.com'); $generator->add('/blog', 0.9, date('Y-m-d'), 'monthly');
Valid values
priority: A number between 0 and 1, 1 being the most important page, 0 being the least important.
last_modified: any date in the "Y-m-d" format
change_frequency: yearly, monthly, weekly, daily, etc.
roelofjan-elsinga/sitemap-generator 适用场景与选型建议
roelofjan-elsinga/sitemap-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.64k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 03 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 roelofjan-elsinga/sitemap-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 roelofjan-elsinga/sitemap-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 24.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-26