icamys / php-sitemap-generator

A simple PHP sitemap generator.
MIT License
168 stars 65 forks source link

documentation: make lastmod optional #50

Closed kasperkamperman closed 1 year ago

kasperkamperman commented 1 year ago

For the lastmod element to be useful, first it needs to be in a supported date format (which is documented on sitemaps.org); Search Console will tell you if it's not once you submit your sitemap. Second, it needs to consistently match reality: if your page changed 7 years ago, but you're telling us in the lastmod element that it changed yesterday, eventually we're not going to believe you anymore when it comes to the last modified date of your pages.

https://developers.google.com/search/docs/crawling-indexing/sitemaps/overview

I actually passed null and that removed lastmod from the generated sitemap. Maybe good to mention that somewhere.

$generator->addURL('/blauwalg-radar', null, 'daily', $priority+0.5);

 <url>
  <loc>https://zwemindex.nl/blauwalg-radar</loc>
  <changefreq>daily</changefreq>
  <priority>1.0</priority>
 </url>
icamys commented 1 year ago

Hi @kasperkamperman and thanks for the proposal. Currently, the generators' addURL() function has a signature with all parameters except the path having default values (equal to null or empty array), which means, according to the PHP specification, that they can be omitted. Also, the documentation of the method also shows that the value can be of type string or null. Do you think there's another way to mark them as optional?

    /**
     * Add url components.
     * Instead of storing all urls in the memory, the generator will flush sets of added urls
     * to the temporary files created on your disk.
     * The file format is 'sm-{index}-{timestamp}.xml'
     * @param string $path
     * @param DateTime|null $lastModified
     * @param string|null $changeFrequency
     * @param float|null $priority
     * @param array|null $alternates
     * @param array $extensions
     * @return $this
     */
    public function addURL(
        string   $path,
        DateTime $lastModified = null,
        string   $changeFrequency = null,
        float    $priority = null,
        array    $alternates = null,
        array    $extensions = []
    )