thestarraccoon/sitemap-generation-library

用于生成 JSON、XML 和 CSV 格式 sitemap 的库

1.1.4 2024-06-16 20:33 UTC

This package is auto-updated.

Last update: 2024-09-16 22:00:28 UTC


README

用于生成 JSON、XML、CSV 格式 sitemap 的库

目录

技术

  • PHP

要求

使用此库需要 PHP 7.4 或更高版本。

使用

通过 composer 安装库

$ composer require thestarraccoon/sitemap-generation-library

传递页面数组、格式和保存文件的路径。示例

$pages = [
    [
        'loc' => 'https://example.com/home',
        'lastmod' => '2024-06-10',
        'changefreq' => 'daily',
        'priority' => '1.0'
    ],
    [
        'loc' => 'https://example.com/about-us',
        'lastmod' => '2024-06-09',
        'changefreq' => 'monthly',
        'priority' => '0.8'
    ],
    [
        'loc' => 'https://example.com/contact',
        'lastmod' => '2024-06-08',
        'changefreq' => 'yearly',
        'priority' => '0.5'
    ],
    [
        'loc' => 'https://example.com/services',
        'lastmod' => '2024-06-07',
        'changefreq' => 'weekly',
        'priority' => '0.9'
    ],
    [
        'loc' => 'https://example.com/products',
        'lastmod' => '2024-06-06',
        'changefreq' => 'daily',
        'priority' => '0.7'
    ],
    [
        'loc' => 'https://example.com/blog',
        'lastmod' => '2024-06-05',
        'changefreq' => 'weekly',
        'priority' => '0.6'
    ],
    [
        'loc' => 'https://example.com/blog/post-1',
        'lastmod' => '2024-06-04',
        'changefreq' => 'monthly',
        'priority' => '0.7'
    ],
    [
        'loc' => 'https://example.com/blog/post-2',
        'lastmod' => '2024-06-03',
        'changefreq' => 'monthly',
        'priority' => '0.6'
    ],
    [
        'loc' => 'https://example.com/blog/post-3',
        'lastmod' => '2024-06-02',
        'changefreq' => 'daily',
        'priority' => '0.8'
    ],
    [
        'loc' => 'https://example.com/privacy-policy',
        'lastmod' => '2024-06-01',
        'changefreq' => 'yearly',
        'priority' => '0.4'
    ]
];

$fileType = 'xml';
$pathToFile = '/generates/sitemap.xml';

$main = new SitemapGenerateInit($pages, $fileType, $pathToFile);
$main->initSitemapGenerate();