Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

lukas-pierce
Copy link
Contributor

@lukas-pierce lukas-pierce commented Apr 5, 2025

Main Idea of This PR:

The sitemap protocol allows the use of <lastmod> and <priority> tags inside <url>.

For <priority>, any value from 0.0 to 1.0 is valid.
This means we can safely render <priority>0.0</priority>.
Therefore, the check for an empty value has been replaced with a check for is_null.

To ensure a consistent style for all optional values, their default is now set to null.
If a value is not null during rendering, the corresponding tag will be rendered.

The Spatie\Sitemap\Tags\Url class has methods like setPriority and setChangeFrequency,
which mean they were implemented previously, but later removed in this PR:
#545

However, since these fields are now optional (nullable), this implementation satisfies both groups:
those who want these tags and those who don’t.

Going forward, I recommend adhering to the official protocol:
https://www.sitemaps.org/protocol.html — instead of being Google-centric, as there are other search engines as well.


Additional small changes:

  • Removed .phpunit.cache/test-results from git
  • Added .phpunit.cache and .idea (PhpStorm) to .gitignore
  • Fixed indentation in resources/views/url.blade.php

Spatie\Sitemap\Tags\Url provides setChangeFrequency()

but it not renders in xml
@freekmurze
Copy link
Member

The tests are failing. Could you take a look? Probably you just need to update the snapshots.

@lukas-pierce lukas-pierce changed the title render <changefreq> Render <changefreq> and <priority> Apr 8, 2025
@lukas-pierce
Copy link
Contributor Author

@freekmurze @Verkasha I updated my PR and top comment

@freekmurze freekmurze merged commit 506b2ac into spatie:main Apr 10, 2025
7 checks passed
@freekmurze
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants