Writing to disks | 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)  Advanced-usage  Writing to disks

 Version   v1      

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

  Writing to disks    
- [ 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)

 Writing to disks
================

- Resolve a disk with Laravel's storage API.
- Pass it to `write_to_disk` and await the write inside the application's context:

```
use laravel::storage;
use spatie_sitemap::{Sitemap, SitemapIndex};

let disk = storage::disk("public")?;
Sitemap::new("https://example.com")?
    .add("/page")
    .write_to_disk(&disk, "maps/pages.xml").await?;

SitemapIndex::new("https://example.com")?
    .add("/storage/maps/pages.xml")
    .write_to_disk(&disk, "sitemap.xml").await?;
```

Laravel's default `public` disk stores files under `storage/app/public` and serves them under `/storage`. The `local` disk is private. Custom local disks use `config.filesystems.add_disk` with `LocalDisk::new(root)`, optionally followed by `.mount("/path").public()`.

The framework has no per-file visibility setting. Choose the appropriate disk. For S3, the bucket policy controls access, not object ACLs. The application must enable the framework's `s3` feature to use that driver.

When splitting a sitemap, chunk keys retain their directory (`maps/pages_0.xml`). Sitemap URLs resolve against the document's base URL. For the default public disk, use a base ending in `/storage` if those URLs should point at its mount. Indexes are written after chunks, but writes are not transactional and old chunks are not deleted.

 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)
