Generating a sitemap | laravel-sitemap-go | Spatie       

 SPATIE  

laravel-sitemap-go
==================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-sitemap-go](https://spatie.be/docs/laravel-sitemap-go/v1)  Creating-sitemaps  Generating a sitemap

 Version   v1      

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

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

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

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

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

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

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

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

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

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

 Generating a sitemap
====================

###  On this page 

1. [ Manually adding links ](#content-manually-adding-links)

The easiest way is to crawl the given domain and generate a sitemap with all found links. The destination of the sitemap is specified by `path`:

```
generator := sitemap.NewGenerator("https://example.com")
err := generator.WriteToFile(ctx, path)
```

In a Laravel application, use `sitemap.From(ctx).Generator(url)` to apply its configured base URL, public directory, crawler settings and clock. Standalone generators resolve relative output URLs against the seed's origin.

The generated sitemap will look similar to this:

```
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url><loc>https://example.com/</loc></url>
<url><loc>https://example.com/page</loc></url>
</urlset>
```

Only successfully crawled pages are included. Modification times, priorities and frequencies are omitted unless you set them. Robots rules are respected by default. Individual failed pages are omitted, while terminal crawl errors and cancellation are returned to the caller. Use a crawler observer to inspect per-page failures.

Manually adding links
-----------------------------------------------------------------------------------------------------------------------

You can manually add links to a crawled sitemap:

```
document, err := sitemap.NewGenerator("https://example.com").GetSitemap(ctx)
if err != nil {
    return err
}
return document.AddURLs("/extra-page", "/another-extra-page").
    WriteToFile(ctx, sitemapPath)
```

`GetSitemap` returns all accepted URLs, including when splitting is enabled. This deliberately avoids the PHP generator's first-chunk-only return value. Reusing a generator starts a fresh crawl rather than accumulating old results. Ordering follows crawl completion and may vary with concurrency. Call `Sort` on the returned document if you need alphabetical output.

 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)
