Crawl profiles | laravel-sitemap-rust | Spatie       

 SPATIE  

laravel-sitemap-rust
====================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-sitemap-rust](https://spatie.be/docs/laravel-sitemap-rust/v1)  Customizing-the-crawler  Crawl profiles

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-sitemap-rust/v1) 

  Crawl profiles    
- [ Introduction ](https://spatie.be/docs/laravel-sitemap-rust/v1/introduction)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-sitemap-rust/v1/installation-setup)
- [ Support us ](https://spatie.be/docs/laravel-sitemap-rust/v1/support-us)
- [ Changelog ](https://spatie.be/docs/laravel-sitemap-rust/v1/changelog)
- [ Questions and issues ](https://spatie.be/docs/laravel-sitemap-rust/v1/questions-issues)
- [ Testing ](https://spatie.be/docs/laravel-sitemap-rust/v1/testing)
- [ About us ](https://spatie.be/docs/laravel-sitemap-rust/v1/about-us)

Creating sitemaps
-----------------

- [ Generating a sitemap ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/generating-a-sitemap)
- [ Manually creating a sitemap ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/manually-creating-a-sitemap)
- [ Creating a sitemap index ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/creating-a-sitemap-index)
- [ Splitting large sitemaps ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/splitting-large-sitemaps)
- [ Grouping URLs into multiple sitemaps ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/grouping-urls-into-multiple-sitemaps)
- [ Adding an XSL stylesheet ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/adding-an-xsl-stylesheet)
- [ Returning a response ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/returning-a-response)
- [ Sorting URLs ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/sorting-urls)

Customizing the crawler
-----------------------

- [ Crawl profiles ](https://spatie.be/docs/laravel-sitemap-rust/v1/customizing-the-crawler/crawl-profiles)
- [ Filtering URLs ](https://spatie.be/docs/laravel-sitemap-rust/v1/customizing-the-crawler/filtering-urls)
- [ Configuring the crawler ](https://spatie.be/docs/laravel-sitemap-rust/v1/customizing-the-crawler/configuring-the-crawler)

Adding content to URLs
----------------------

- [ Alternates ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/alternates)
- [ Images ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/images)
- [ Videos ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/videos)
- [ News ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/news)
- [ Sitemapable models ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/sitemapable-models)

Advanced usage
--------------

- [ Scheduled generation ](https://spatie.be/docs/laravel-sitemap-rust/v1/advanced-usage/scheduled-generation)
- [ Writing to disks ](https://spatie.be/docs/laravel-sitemap-rust/v1/advanced-usage/writing-to-disks)
- [ Handling errors ](https://spatie.be/docs/laravel-sitemap-rust/v1/advanced-usage/handling-errors)

 Crawl profiles
==============

###  On this page 

1. [ Application-wide profiles ](#content-application-wide-profiles)

- Implement `CrawlPolicy` or pass a closure to choose which URLs may be fetched.
- A custom profile replaces the default same-host scope:

```
use spatie_sitemap::spatie_crawler::CrawlPolicy;

struct CustomCrawlProfile;

impl CrawlPolicy for CustomCrawlProfile {
    fn should_crawl(&self, url: &url::Url) -> bool {
        if url.host_str() != Some("localhost") {
            return false;
        }

        url.path() == "/"
    }
}
```

Register your `CustomCrawlProfile` with `crawl_profile`:

```
use spatie_sitemap::SitemapGenerator;

let generator = SitemapGenerator::new("https://example.com")?
    .crawl_profile(CustomCrawlProfile);
```

Application-wide profiles
-----------------------------------------------------------------------------------------------------------------------------------

Override the provider's transient binding to apply a profile to every generator the application resolves. Laravel runs application service registration after package registration.

```
use laravel::Application;
use spatie_sitemap::{SitemapGenerator, service_provider};

let app = Application::configure()
    .with_providers(|providers| { providers.add(service_provider()); })
    .with_services(|services| {
        services.bind(|app| async move {
            Ok(SitemapGenerator::from_config(app.config(), &app.config().app.url)?
                .crawl_profile(|url: &url::Url| {
                    url.host_str() == Some("example.com") && !url.path().starts_with("/private")
                })
            )
        });
    })
    .create();
```

Use `bind`, not `singleton`: crawling consumes a generator and each run needs fresh callback state. A custom profile replaces same-host filtering, so include your host restrictions in it. `should_crawl` still applies in addition to the profile.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
