Download the PHP package jantaodev/sitemap-bundle without Composer
On this page you can find all versions of the php package jantaodev/sitemap-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sitemap-bundle
JantaoDevSitemapBundle
This Symfony bundle provides sitemap XML generation.
Features:
- advanced robots.txt configuration
- several hosts support
- optional sitemap GZip compression
- sitemap constraints (10 MBytes/50 000 items per file) support
- route parameters iteration
Requirements:
- PHP 7.2
- Symfony 5
- Doctrine 2
1. Installation
Run composer require jantaodev/sitemap-bundle
.
Register the bundle in the app/AppKernel.php
file (optional):
Add host name in app/config/parameters.yml
or in app/config/config.yml
Now you can use the bundle.
2. Basic usage
There are several ways to add route to sitemap.
2.1. Annotation, yaml, XML (for static routes without parameters)
Annotation simple example:
Yaml simple example:
XML simple example:
Annotation full example:
Yaml full example:
XML full example:
There are three parameters:
- priority (real number from 0 to 1)
- changeFreq (one of values: always, never, hourly, daily, weekly, monthly, yearly)
- lastMod (see http://php.net/manual/en/datetime.formats.php)
It`s not necessary to specify all parameters.
2.2. Bundle configuration in app/config/config.yml
Simple example for static route:
Full example for static route:
Full example for dynamic route with parameters:
Iterate data for route parameters with array iterator:
Iterate data for route parameters with array iterator (example 2):
Iterate data for route parameters with Doctrine iterator:
3. Execute sitemap generation
There are two ways to execute sitemap generation:
1) via console
2) via service
4. Advanced configuration
Full bundle configuration:
Parameters description:
Parameter | Description |
---|---|
hosts | For one host configuration see chapter 1, For several hosts see chapter 4.2 |
gzip | Enable sitemap GZip compression |
scheme | Host scheme mode (http, https, https_only*) |
robots | See chapter 4.1 |
sitemap | See chapters 2.2 and 4.2 |
- https_only means that site is available only over https
4.1. Robots.txt configuration
Full robots.txt configuration:
Parameters description:
Parameter | Description |
---|---|
allow | Allow entries array, key is a path, value is a user-agent (null means "*") |
disallow | Disallow entries array |
crawl_delay | Crawl delay parameter |
clean_param | Clean param entries array, key is a path, value is an array of parameters |
For more details about robots.txt parameters see this or this.
4.2. Several hosts support
Several hosts support allows you to generate different sitemaps to several hosts.
So, enable several hosts support, list your hosts in bundle configuration:
Enable robots.txt switching controller in router (add following lines to app/config/routing.yml
):
By default all ruotes will be added to each host sitemaps.
But in sitemap section in bundle configuration you can specify host.
Example:
In this example homepage will be added to all sitemaps, but about page will be add only to "foo.com" sitemap.
Example 2 (different slugs):
5. Add custom event listener
To add a URL using your own logic, you can use event listener or event subscriber.
Example AppBundle/EventListener/SomeListener.php
:
Example AppBundle/Resources/config/services.yml
:
6. Notes
TODO:
- cover EventListener classes with tests
- add report on command
7. License
This bundle is under MIT license
All versions of sitemap-bundle with dependencies
symfony/framework-bundle Version ^5.0
symfony/yaml Version *
doctrine/orm Version ^2.7
doctrine/doctrine-bundle Version ^2.0
ext-json Version *