Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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