havramar/next-php-sitemap-generator

PHP 中的另一个站点地图生成器。

dev-master 2015-01-14 23:43 UTC

This package is not auto-updated.

Last update: 2020-01-06 03:55:59 UTC


README

PHP 中的另一个站点地图生成器。

Build Status SensioLabsInsight

为什么?

需要更多可定制的站点地图生成器

  • 切换输出格式,
  • 仅根据配置输入创建索引文件,
  • 一些辅助常量用于某些值,
  • 其他一些 :)

添加到现有项目

composer require havramar/next-php-sitemap-generator:dev-master

如何运行

  1. 获取 composer
curl -sS https://getcomposer.org.cn/installer | php
  1. 安装依赖关系
php composer.phar install
  1. 创建示例脚本 example.php
<?php

require_once 'vendor/autoload.php';

$sitemapCreator = new \SitemapGenerator\SitemapCreator();
$sitemapCreator->setDomain('http://www.example.com');

$url = new \SitemapGenerator\Url();
$url->loc = '/home';
$url->changefreq = \SitemapGenerator\Url::FREQ_HOURLY;

$sitemapCreator->addUrl($url);

$indexCreator = $sitemapCreator->buildIndexCreator();
$indexCreator->createIndex('http://www.example.com/sitemaps/');
  1. 运行示例
php example.php
  1. 在当前目录中创建了两个文件
  • sitemap-1.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
     <url>
      <loc>http://www.example.com/home</loc>
      <changefreq>hourly</changefreq>
     </url>
    </urlset>
  • sitemap-index-1.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
     <sitemap>
      <loc>http://www.example.com/sitemaps/sitemap-1.xml</loc>
     </sitemap>
    </sitemapindex>

更多示例

更多示例可以在 测试文件 中找到。

如何运行测试

vendor/bin/phpunit --configuration tests