Download the PHP package spatie/laravel-sitemap without Composer
On this page you can find all versions of the php package spatie/laravel-sitemap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download spatie/laravel-sitemap
More information about spatie/laravel-sitemap
Files in spatie/laravel-sitemap
Package laravel-sitemap
Short Description Create and generate sitemaps with ease
License MIT
Homepage https://github.com/spatie/laravel-sitemap
Rated 5.00 based on 1 reviews
Informations about the package laravel-sitemap
Generate sitemaps with ease
This package can generate a sitemap without you having to add urls to it manually. This works by crawling your entire site.
You can also create your sitemap manually:
Or you can have the best of both worlds by generating a sitemap and then adding more links to it:
You can also control the maximum depth of the sitemap:
The generator has the ability to execute JavaScript on each page so links injected into the dom by JavaScript will be crawled as well.
You can also use one of your available filesystem disks to write the sitemap to.
You may need to set the file visibility on one of your sitemaps. For example, if you are writing a sitemap to S3 that you want to be publicly available. You can set the third parameter to true
to make it public. Note: This can only be used on the ->writeToDisk()
method.
You can also add your models directly by implementing the \Spatie\Sitemap\Contracts\Sitemapable
interface.
Now you can add a single post model to the sitemap or even a whole collection.
This way you can add all your pages super fast without the need to crawl them all.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
First, install the package via composer:
The package will automatically register itself.
If you want to update your sitemap automatically and frequently you need to perform some extra steps.
Configuration
You can override the default options for the crawler. First publish the configuration:
This will copy the default config to config/sitemap.php
where you can edit it.
Usage
Generating a sitemap
The easiest way is to crawl the given domain and generate a sitemap with all found links.
The destination of the sitemap should be specified by $path
.
The generated sitemap will look similar to this:
Customizing the sitemap generator
Define a custom Crawl Profile
You can create a custom crawl profile by implementing the Spatie\Crawler\CrawlProfiles\CrawlProfile
interface and by customizing the shouldCrawl()
method for full control over what url/domain/sub-domain should be crawled:
and register your CustomCrawlProfile::class
in config/sitemap.php
.
Changing properties
To change the lastmod
, changefreq
and priority
of the contact page:
Leaving out some links
If you don't want a crawled link to appear in the sitemap, just don't return it in the callable you pass to hasCrawled
.
Preventing the crawler from crawling some pages
You can also instruct the underlying crawler to not crawl some pages by passing a callable
to shouldCrawl
.
Note: shouldCrawl
will only work with the default crawl Profile
or custom crawl profiles that implement a shouldCrawlCallback
method.
Configuring the crawler
The crawler itself can be configured to do a few different things.
You can configure the crawler used by the sitemap generator, for example: to ignore robot checks; like so.
Limiting the amount of pages crawled
You can limit the amount of pages crawled by calling setMaximumCrawlCount
Executing Javascript
The sitemap generator can execute JavaScript on each page so it will discover links that are generated by your JS scripts. You can enable this feature by setting execute_javascript
in the config file to true
.
Under the hood, headless Chrome is used to execute JavaScript. Here are some pointers on how to install it on your system.
The package will make an educated guess as to where Chrome is installed on your system. You can also manually pass the location of the Chrome binary to executeJavaScript()
.
Manually adding links
You can manually add links to a sitemap:
Adding alternates to links
Multilingual sites may have several alternate versions of the same page (one per language). Based on the previous example adding an alternate can be done as follows:
Note the function which takes an alternate URL and the locale it belongs to.
Adding images to links
Urls can also have images. See also https://developers.google.com/search/docs/advanced/sitemaps/image-sitemaps
Adding videos to links
As well as images, videos can be wrapped by URL tags. See https://developers.google.com/search/docs/crawling-indexing/sitemaps/video-sitemaps
You can set required attributes like so:
If you want to pass the optional parameters like family_friendly
, live
, or platform
:
Manually creating a sitemap
You can also create a sitemap fully manual:
Creating a sitemap index
You can create a sitemap index:
You can pass a Spatie\Sitemap\Tags\Sitemap
object to manually set the lastModificationDate
property.
the generated sitemap index will look similar to this:
Create a sitemap index with sub-sequent sitemaps
You can call the maxTagsPerSitemap
method to generate a
sitemap that only contains the given amount of tags
Generating the sitemap frequently
Your site will probably be updated from time to time. In order to let your sitemap reflect these changes, you can run the generator periodically. The easiest way of doing this is to make use of Laravel's default scheduling capabilities.
You could set up an artisan command much like this one:
That command should then be scheduled in the console kernel.
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
First start the test server in a separate terminal session:
With the server running you can execute the tests:
Contributing
Please see CONTRIBUTING for details.
Security
If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.
Credits
- Freek Van der Herten
- All Contributors
Support us
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-sitemap with dependencies
guzzlehttp/guzzle Version ^7.8
illuminate/support Version ^10.0|^11.0
nesbot/carbon Version ^2.71|^3.0
spatie/crawler Version ^8.0.1
spatie/laravel-package-tools Version ^1.16.1
symfony/dom-crawler Version ^6.3.4|^7.0