smg / sitemap-generator
多种文件格式的网站地图生成库:xml, csv, json
1.0.2
2022-09-04 16:31 UTC
Requires
- ext-json: *
- ext-mbstring: *
This package is not auto-updated.
Last update: 2024-09-30 22:37:05 UTC
README
描述
多种文件格式的网站地图生成库:xml, csv, json
在脚本中初始化库时,会传递一个包含以下参数的网站页面列表数组:页面地址(loc),页面最后修改日期(lastmod),解析优先级(priority),更新频率(changefreq)。同时,初始化时还会传递用于生成地图的文件类型:文件类型(xml,csv,json);以及保存文件的路径。
初始化后,库对象会生成所选类型的网站地图文件。
安装
composer require smg/sitemap-generator
使用示例
require 'vendor/autoload.php';
use Smg\SitemapGenerator\Services\Sitemap;
// Список страниц сайта
$listPages = [
[
'loc' => 'https://site.ru',
'lastmod' => '2020-12-14',
'priority' => 0,
'changefreq' => 'hourly'
],
[
'loc' => 'https://site.ru/about',
'lastmod' => '2020-12-10',
'priority' => 0.5,
'changefreq' => 'daily'
],
];
- XML
$sitemap = new Sitemap($listPages, 'xml', './storage/xml/sitemap.xml');
try { $sitemap->build(); } catch (Exception $ex) { echo $ex->getMessage(); }
- **JSON**
$sitemap = new Sitemap($listPages, 'json', './storage/json/sitemap.json');
try { $sitemap->build(); } catch (Exception $ex) { echo $ex->getMessage(); }
- **CSV**
$sitemap = new Sitemap($listPages, 'csv', './storage/csv/sitemap.csv');
try {
$sitemap->build();
} catch (Exception $ex) {
echo $ex->getMessage();
}
### License
MIT