2017 © Pedro Peláez
 

library sitemap

Generate sitemap.xml with respect to robots.txt disallow rules, according specification https://www.sitemaps.org and without dependencies from any framework or cms.

image

webarchitect609/sitemap

Generate sitemap.xml with respect to robots.txt disallow rules, according specification https://www.sitemaps.org and without dependencies from any framework or cms.

  • Monday, July 16, 2018
  • by webarchitect609
  • Repository
  • 1 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Sitemap generation and deploy tool

Be careful: this version can be unstable and all interfaces can be changed in near future., (*1)

Features

  • Respect of Sitemaps XML format and it's limits;
  • Sitemapindex is always supported;
  • Automatic setup 'lastmod' for sitemap in sitemapindex with the most fresh 'lastmod' from it's urls;
  • Automatic adding hostname for urls;
  • Respect of robots.txt Disallow rules for '*' agent to help you avoid undesired urls in your sitemap;
  • Write to a temporary folder and deploy to final destination to avoid damaging old copy in a case of troubles;
  • No dependencies from any framework;

How to use

1 Install via composer, (*2)

composer require webarchitect609/sitemap, (*3)

2 Create writer instance, (*4)

$sitemapWriter = new \WebArch\Sitemap\SitemapWriter('http://example.org', '/var/www/example.org/htdocs');, (*5)

3 For simple usage just start to add urls directly to writer, (*6)

use WebArch\Sitemap\Enum\ChangeFreq;
use WebArch\Sitemap\Model\Url;

$url1 = (new Url('/index.php'))->withChangefreq(ChangeFreq::CHANGE_FREQ_DAILY)
                               ->withPriority(0.9)
                               ->withLastmod(
                                   DateTimeImmutable::createFromFormat(
                                       'Y-m-d H:i:s',
                                       '2018-07-13 10:37:48'
                                   )
                               );

$url2 = (new Url('/news/index.php'))->withChangefreq(ChangeFreq::CHANGE_FREQ_HOURLY);

$sitemapWriter->addUrl($url1)
              ->addUrl($url2);

4 For more complicated case you can create as many sitemaps as you need and give them to writer:, (*7)

$newsSitemap = new \WebArch\Sitemap\Model\Sitemap('/sitemap_news.xml');

$newsSitemap->addUrl(
                (new Url('/news/detail/1/'))
            )
            ->addUrl(
                (new Url('/news/detail/2/'))
            )
            ->addUrl(
                (new Url('/news/detail/3/'))
            );

$sitemapWriter->addSitemap($newsSitemap);

5 Additional options can be applied to respect sitemap limitations, (*8)

/**
 * Limit maximum urls count. When it's overflowed an `\WebArch\Sitemap\Exception\UrlCountLimitException` would be issued.
 * It's ON by default.
 */
$newsSitemap->getUrlSet()->withMaxUrlCount(50000);

/**
 * Limit maximum file size
 * It's OFF by default.
 * WARNING: it WILL slow down everything: after adding new url estimated size calculations would be executed.
 * (Hope to get rid of this in the future)
 */
$newsSitemap->getUrlSet()->withMaxXmlSizeBytes(10*1024*1024);

6 And then just let it work, (*9)

$sitemapWriter->write();

After this everything will be written to sys_get_temp_dir(). If there were no errors new version of sitemapindex + all sitemaps will be deployed to it's final destination at $sitemapWriter->getBaseDir() and file permissions will be changed in a way to let everybody read them., (*10)

Running Unit-tests

composer test, (*11)

The Versions

16/07 2018

dev-master

9999999-dev

Generate sitemap.xml with respect to robots.txt disallow rules, according specification https://www.sitemaps.org and without dependencies from any framework or cms.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Gripinskiy

16/07 2018

v0.0.2

0.0.2.0

Generate sitemap.xml with respect to robots.txt disallow rules, according specification https://www.sitemaps.org and without dependencies from any framework or cms.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Gripinskiy

13/07 2018

v0.0.1

0.0.1.0

Generate sitemap.xml with respect to robots.txt disallow rules, according specification https://www.sitemaps.org and without dependencies from any framework or cms.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Gripinskiy