egvolkvolk / smg
网站地图生成器
dev-main
2024-05-16 15:45 UTC
Requires
- php: > 8
- ext-dom: *
- composer/installers: *
This package is auto-updated.
Last update: 2024-09-16 16:29:02 UTC
README
你好,这是初始化和使用库创建网站地图的教程
初始化
- 打开你的终端
- 如果需要,安装composer php composer install
- 安装库 SitemapGenerator php composer require egvolkvolk/smg
- 稍后,库会创建所需的文件,如 vendor,egvolkvolk 等...
使用
- 创建新的php文件,例如 index.php
- 添加require require 'vendor\egvolkvolk\smg\src\SitemapGenerator.php';
- 添加站点数据
- data - 站点页面列表及其参数
- loc - 页面地址
- lastmod - 修改日期
- priortity - 解析优先级
- changefreq - 更新频率
- datatype - 生成文件类型。可以是数组
- directory - 保存文件的路径
- data - 站点页面列表及其参数
- 添加此代码
$sitemapGenerator = new SitemapGenerator();
foreach ($dataTypes as $dataType) {
$sitemapGenerator->convertToDataType($data, $dataType, $directory);
}
我的可执行php文件
<?php
use src\SitemapGenerator;
require 'vendor\egvolkvolk\smg\src\SitemapGenerator.php';
$data = [
[
'loc' => 'https://pyrobyte.ru/',
'lastmod' => '2024-05-05',
'priority' => '0.9',
'changefreq' => 'weekly',
],
[
'loc' => 'https://pyrobyte.ru/cases',
'lastmod' => '2024-04-03',
'priority' => '0.5',
'changefreq' => 'monthly',
],
[
'loc' => 'https://pyrobyte.ru/career',
'lastmod' => '2024-02-24',
'priority' => '0.3',
'changefreq' => 'yearly',
],
[
'loc' => 'https://pyrobyte.ru/blog',
'lastmod' => '2024-05-07',
'priority' => '0.7',
'changefreq' => 'daily',
],
];
$directory = './upload';
$dataTypes = [
'xml',
'csv',
'json',
];
$sitemapGenerator = new SitemapGenerator();
foreach ($dataTypes as $dataType) {
$sitemapGenerator->convertToDataType($data, $dataType, $directory);
}
库的结果
CSV
loc;lastmod;priority;changefreq
https://pyrobyte.ru/;2024-05-05;0.9;weekly
https://pyrobyte.ru/cases;2024-04-03;0.5;monthly
https://pyrobyte.ru/career;2024-02-24;0.3;yearly
https://pyrobyte.ru/blog;2024-05-07;0.7;daily
JSON
[
{
"loc": "https://pyrobyte.ru/",
"lastmod": "2024-05-05",
"priority": "0.9",
"changefreq": "weekly"
},
{
"loc": "https://pyrobyte.ru/cases",
"lastmod": "2024-04-03",
"priority": "0.5",
"changefreq": "monthly"
},
{
"loc": "https://pyrobyte.ru/career",
"lastmod": "2024-02-24",
"priority": "0.3",
"changefreq": "yearly"
},
{
"loc": "https://pyrobyte.ru/blog",
"lastmod": "2024-05-07",
"priority": "0.7",
"changefreq": "daily"
}
]
XML
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://pyrobyte.ru/</loc>
<lastmod>2024-05-05</lastmod>
<priority>0.9</priority>
<changefreq>weekly</changefreq>
</url>
<url>
<loc>https://pyrobyte.ru/cases</loc>
<lastmod>2024-04-03</lastmod>
<priority>0.5</priority>
<changefreq>monthly</changefreq>
</url>
<url>
<loc>https://pyrobyte.ru/career</loc>
<lastmod>2024-02-24</lastmod>
<priority>0.3</priority>
<changefreq>yearly</changefreq>
</url>
<url>
<loc>https://pyrobyte.ru/blog</loc>
<lastmod>2024-05-07</lastmod>
<priority>0.7</priority>
<changefreq>daily</changefreq>
</url>
</urlset>