Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/m-adamski/symfony-sitemap-bundle
Bundle for Symfony which creates a dynamic sitemap in XML format
https://github.com/m-adamski/symfony-sitemap-bundle
php sitemap-bundle symfony symfony-bundle
Last synced: 26 days ago
JSON representation
Bundle for Symfony which creates a dynamic sitemap in XML format
- Host: GitHub
- URL: https://github.com/m-adamski/symfony-sitemap-bundle
- Owner: m-adamski
- License: mit
- Created: 2021-01-04T12:57:35.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-06-18T13:02:18.000Z (over 3 years ago)
- Last Synced: 2024-04-21T13:43:07.239Z (7 months ago)
- Topics: php, sitemap-bundle, symfony, symfony-bundle
- Language: PHP
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sitemap Bundle for Symfony
Bundle which creates a dynamic sitemap in XML format.
## Installation
This bundle can be installed by Composer:
```shell
composer require m-adamski/symfony-sitemap-bundle
```## How to use it?
Bundle provides the Sitemap Controller, and a configured routes file that you just need to import into your local
configuration. You can do that by adding sitemap section into ``config/routes.yaml`` file:```yaml
sitemap:
resource: '@SitemapBundle/Resources/config/routes.yaml'
```The next step is to mark the routes to be added to the sitemap file. The bundle supports several configurations:
```yaml
index:
path: /
methods: [ GET ]
controller: App\Controller\DefaultController::index
defaults:
_sitemap: 1.00
``````yaml
index:
path: /
methods: [ GET ]
controller: App\Controller\DefaultController::index
defaults:
_sitemap: true
``````yaml
index:
path: /
methods: [ GET ]
controller: App\Controller\DefaultController::index
defaults:
_sitemap:
priority: 1.00
change_frequency: 'monthly'
last_modification: '2021-01-01 12:00:00'
```What about dynamically generated routes? Sometimes the URLs we want to include in the sitemap are dynamically generated
with one or more parameters. In this case, it is possible to use the ``generator`` parameter:```yaml
city:
path: /city/{cityName}
methods: [ GET ]
controller: App\Controller\DefaultController::city
defaults:
_sitemap:
generator: App\Model\SitemapGenerator::generateCity
``````php
"New York"],
["cityName" => "Oslo"],
["cityName" => "Warsaw"]
];
}
}
```Important: The SitemapGenerator object must be marked as public in DI.
```yaml
App\Model\SitemapGenerator:
public: true
```As the result there should be generated three additional items in sitemap file:
```xml
http://localhost/city/New%20York
http://localhost/city/Oslo
http://localhost/city/Warsaw
```
Bundle also supports the internationalized routing:
```yaml
home:
path:
pl: /pl
en: /en
methods: [ GET ]
controller: App\Controller\DefaultController::staticPage
defaults:
_sitemap: true
```Generated Sitemap XML:
```xml
http://localhost/pl
http://localhost/en
```
## License
MIT