lapshev/sitemap
Composer 安装命令:
composer require lapshev/sitemap
包简介
Sitemap generator library
README 文档
README
Install
composer require lapshev/sitemap
Usage
- Create generator object
- Create provider object
- Add provider to generator
- Generate
Specify filename while adding provider, content of this file is the result of merge multiply providers with same filename
use Lapshev\Sitemap; use Lapshev\Sitemap\Providers; $sitemap = new Sitemap\Generator('http://example.com'); $simpleProvider = new Providers\Simple([ ['/', new \DateTime(), 'daily', 0.5], ['/news/', new \DateTime(), 'monthly', 1] ]); $sitemap->addProvider('example', $simpleProvider); // will output to example.xml and add this file sitemap.xml $sitemap->generate($_SERVER['DOCUMENT_ROOT']);
For more advantage usage your should create your own provider that implements iProvider interface.
See example bellow:
namespace MySite\Sitemap\Providers; use Lapshev\Sitemap\BaseProvider; use Lapshev\Sitemap\Entire; use Lapshev\Sitemap\iProvider; class DataBase extends BaseProvider implements iProvider { private $dbResult; private $tableName; public function __construct($params = []) { parent::__construct($params); $this->tableName = $params['tableName']; } // will be called before fetching public function prepareData() { $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = new \mysqli($servername, $username, $password, $dbname); $sql = "SELECT id, pageUrl, lastMod FROM {$this->tableName}"; $this->dbResult = $conn->query($sql); } public function getNextEntire() { while($row = $this->dbResult->fetch_assoc()) { return new Entire($row['pageUrl'], $row['lastMod'], 'daily', 0.7); } return null; } }
Features
Check response
$sitemap = new Sitemap\Generator('http://example.com', ['checkResponse' => true]);
Will check every url in the set and output wrong ones
More examples
use Lapshev\Sitemap\Generator; use Lapshev\Sitemap\Providers\Simple; use newsite\SiteMap\Providers\Elements; use newsite\SiteMap\Providers\Files; use newsite\SiteMap\Providers\Sections; use newsite\SiteMap\Providers\Banners; use Bitrix\Main\Type\DateTime; require 'common.php'; $params = [ 'check_response' => in_array('checkResponse', $argv) ]; $arScheme = [ 'catalog' => [ new Sections(['iBlockID' => CATALOG_SEO_MENU, 'indexID' => 1, 'priority' => 0.5]), ], 'menu' => [ new Sections(['iBlockID' => CATALOG_LOGIC_MENU, 'indexID' => 1, 'priority' => 0.5]), ], 'goods' => [ new Elements(['iBlockID' => CATALOG_PRODUCT_IBLOCK, 'indexID' => 1, 'priority' => 0.5]), ], 'news' => [ new Simple([ ['/news/', new DateTime(), 'hourly', 1] ]), new Elements(['iBlockID' => 25, 'priority' => 0.8, 'changeFreq' => 'monthly']), ], 'articles' => [ new Simple([ ['/helpful/', new DateTime(), 'hourly', 0.4] ]), new Elements(['iBlockID' => 29, 'priority' => 0.4]), ], 'info' => [ new Simple([ ['/', new DateTime(), 'hourly', 1] ]), new Files(['priority' => 0.4]) ], 'sale' => [ new Banners(['type' => 'actionCatalogList', 'priority' => 1, 'changeFreq' => 'daily']), ] ]; $siteMap = new Generator('http://example.com', $params); foreach($arScheme as $fileName => $providers) { foreach($providers as $provider){ $siteMap->addProvider($fileName, $provider); } } $siteMap->generate($_SERVER['DOCUMENT_ROOT']);
lapshev/sitemap 适用场景与选型建议
lapshev/sitemap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 lapshev/sitemap 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lapshev/sitemap 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-27