Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sitemap Bundle Laravel Package

dlapps/sitemap-bundle

View on GitHub
Deep Wiki
Context7

Sitemap Bundle

Latest Version on Packagist Software License Build Status Coverage Status Quality Score SensioLabsInsight Total Downloads

The Sitemap bundle enables development teams to quickly add support for generating sitemaps, for their PHP7 packages and projects built on Symfony 3.2+.

The bundle supports a number of customisation parameters, PSR-4 autoloading, is PSR-2 compliant and has been well tested through automated tests, as well as being used in various microservices within the Dreamlabs ecosystem.

Install

Via Composer

$ composer require dreamlabs/sitemap-bundle

Enable the bundle in your AppKernel, present in: app/AppKernel.php.

$bundles = [
    new DL\SitemapBundle\DLSitemapBundle(),
]

Usage

In order to generate a sitemap, you need to generate an instance of sitemap definition DL\SitemapBundle\Definition\Sitemap. This instance can then accept the individual sitemap resources that you would like to add via the Sitemap::addResource() method.

In order to assist with the generation and validation of sitemap resources, the sitemap_resource_builder service is exposed, and can be used as in the example below:

$container->get('sitemap_resource_builder')
    ->withTitle($title)
    ->withAbsoluteLocation($location)
    ->withLastModified($lastModified) # \DateTime
    ->withChangeFrequency(ChangeFrequencyEnum::WEEKLY)
    ->withPriority(0.5)
    ->build();

The builder will automatically validate a new resource that is added to the Sitemap, and ensure that:

  • All fields have been provided.
  • The priority is a float between 0 and 1.
  • The change frequency is a valid value.
  • An absolute URL has been provided for the location.

The builder also exposes a ->withRelativeLocation($location) method, which can be used alongside the location_prefix configuration parameter in order to generate absolute routes, from relative URLs. This feature is present in order to assist with possibly mismatching hostnames when proxying through an improperly configured load balancer.

Given a scenarion in which the location_prefix parameter is set to https://example.com calling ->withRelativeLocation('/article/test') will generate the absolute URL https://example.com//article/test.

The DL\SitemapBundle\Enum\ChangeFrequencyEnum class can be used in order to define a strict change frequency. Possible values are:

  • ChangeFrequencyEnum::ALWAYS
  • ChangeFrequencyEnum::HOURLY
  • ChangeFrequencyEnum::DAILY
  • ChangeFrequencyEnum::WEEKLY
  • ChangeFrequencyEnum::MONTHLY
  • ChangeFrequencyEnum::YEARLY
  • ChangeFrequencyEnum::NEVER

Configuration Reference

The following configuration parameters are also available for the bundle:

dl_sitemap:
    # The listener prefix, can be used in order to assist with the generation of absolute URLs from relative URLs.
    location_prefix: string # https://example.com

Testing

$ composer test

PSR-2 Compatibility

$ composer check-styles
$ composer fix-styles

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email petre [at] dreamlabs.ro instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager