getgrav / grav-plugin-sitemap

Grav Sitemap Plugin
https://getgrav.org
MIT License
42 stars 42 forks source link

Multilanguage sets unpublished pages as alternates #43

Closed redrohX closed 7 years ago

redrohX commented 7 years ago

So I have a lot of multilanguage pages, but for quite a lot of them the parent language is set to published: false. What I do see in my sitemap.xml is that these pages are still included there (and generate a 404). What I expect is that pages which are not published don't end up as alternates in the sitemap.xml.

Current situation where the EN version is set to published: false.

<url>
    <loc>http://www.md.dev/nl-nl/blog/blog-post-in-dutch</loc>
    <xhtml:link rel="alternate" hreflang="en" href="http://www.md.dev/blog/blog-post-in-dutch" />
    <xhtml:link rel="alternate" hreflang="nl-nl" href="http://www.md.dev/nl-nl/blog/blog-post-in-dutch" />
    <lastmod>2017-05-03</lastmod>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>

What I expect to happen:

<url>
    <loc>http://www.md.dev/nl-nl/blog/blog-post-in-dutch</loc>
    <xhtml:link rel="alternate" hreflang="nl-nl" href="http://www.md.dev/nl-nl/blog/blog-post-in-dutch" />
    <lastmod>2017-05-03</lastmod>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>

Also I'm not 100% sure if it should set rel="alternate" if there is only one URL (and I guess no alternates). But I do expect the unpublished page not to be there.

flaviocopes commented 7 years ago

Strange, I tried and when I set published: false an a translation of the page, the alternate disappears.

redrohX commented 7 years ago

That's odd. What I get back from $page->translatedLanguages() in sitemap.php are all the local pages if they exist. There doesn't seem to be a check for published: true.

So just to be clear. My default language is en. Then I have nl-nl, fr-fr and en-gb. This is the structure:

/page-title
   blog-post.de-de.md <-- published: false
   blog-post.en.md <-- published: true
   blog-post.nl-nl.md <-- published: false

What I see in my sitemap.xml for the default language on md.dev/sitemap.xml:

<url>
    <loc>http://www.md.dev/blog/page-title</loc>
    <xhtml:link rel="alternate" hreflang="en" href="http://www.md.dev/blog/page-title" />
    <xhtml:link rel="alternate" hreflang="nl-nl" href="http://www.md.dev/nl-nl/blog/page-title" />
    <xhtml:link rel="alternate" hreflang="de-de" href="http://www.md.dev/de-de/blog/page-title" />
    <lastmod>2017-05-16</lastmod>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>

Yes the page is not available in the sitemap for nl-nl, but it already shouldn't be visible as alternate for the default language either.

Is there something I'm missing here?

flaviocopes commented 7 years ago

I tested it again, but I cannot replicate the problem. Maybe send me your user/ folder on Slack so I can replicate on your same page structure and config.