Module generates sitemap according to the sitemap protocol.
composer require turbine-kreuzberg/spryker-sitemap
To use the provided console commands you will need to register TurbineKreuzberg namespace in your config_default.php.
$config[KernelConstants::CORE_NAMESPACES] = [
// add TurbineKreuzberg as a core namespace
'TurbineKreuzberg',
];In ConsoleDependencyProvider you need to add Sitemap consoles that you want to use.
use Shared\Zed\Sitemap\Communication\Console\SitemapConsole;use Shared\Zed\Sitemap\Communication\Console\SitemapIndexConsole;
protected function getConsoleCommands(Container $container): array
{
$commands = [
// ...
new SitemapIndexConsole(),
new SitemapConsole(),
];If everything is working properly you should see sitemap section in your
sitemap
sitemap:generate Generate sitemap(s).
sitemap:index:generate Generate sitemap index (do not forget to generate sitemaps first).
You do not need to register index console if you have only one plugin and you are generating a single sitemap.
To generate sitemaps for all of your registered plugins you need to run:
vendor/bin/console sitemap:generateif you want to generate sitemap for a single sitemap plugin instead of all of them you can use sitemap:generate with a plugin name. Typical use case is when you have different update frequencies for different sitemaps.
vendor/bin/console sitemap:generate name-of-your-pluginTo generate sitemap index you need to run:
vendor/bin/console sitemap:index:generateGeneration of index will assume that all the sitemaps for registered plugins are generated. For now there is no validation.
In order for console commands to do anything you will need to register at least one sitemap plugin in SitemapDependencyProvider. Plugins need to implement
\TurbineKreuzberg\Zed\Sitemap\Dependency\Plugin\SitemapPluginInterface
Sitemap generation can be resource intensive and that is why we can use generators to reduce the memory usage. ORMs should be avoided for bulk operations and Propel provides access to underline PDO and we can utilize PDOStatement::fetch to iterate through database records to save the memory.
In the documentation folder you can find a fully implemented CategorySitemapPlugin that will call url module to retrieve all the URLs for categories. You can find all the necessary changed in the project corresponding folders.
Sitemap module comes with some configuration that you need to be aware of.
| Configuration | Description |
|---|---|
| PUBLIC_HOSTNAME | Hostname of your site (i.e. www.example.com) |
| INDEX_FILENAME | defaults to sitemap_index.xml |
| IS_SSL_ENABLED | to put https or http in urls (defaults to true) |
| SITEMAP_FOLDER_PATH | folder in which sitemaps are to be generated (defaults to /tmp) |
Sitemap standard comes with some limitations that we need to consider. Probably most crucial is that you can have 50k links in one sitemap. If you have more than that you need to create sitemap index and multiple sitemaps. When you create your plugins you need to take that into account.
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://www.example.com/sitemap1.xml.gz</loc>
</sitemap>
<sitemap>
<loc>https://www.example.com/sitemap2.xml.gz</loc>
</sitemap>
</sitemapindex>vendor/bin/phpcs --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml ./src
vendor/bin/phpcbf --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml ./src
vendor/bin/phpstan
vendor/bin/codecept build
vendor/bin/codecept run