bobdenotter / sitemap

Provide a sitemap (.xml) for your Bolt 4 site
MIT License
5 stars 4 forks source link

Does not take account of contentType overrides #7

Open ghost opened 3 years ago

ghost commented 3 years ago

If I have a contentType where I have done an override in routes.yaml so that the contentType slug is not in the URL, the Sitemap does not reflect this.

Context: https://docs.bolt.cm/4.0/routing#contenttype-overrides

Example:

pagebinding:
  path: /{slugOrId}
  methods: [GET|POST]
  defaults:
    contentTypeSlug: page
    _controller: Bolt\Controller\Frontend\DetailController::record

The sitemap.xml still shows domain.com/page/slug instead of domain.com/slug

Right now I'm not familiar enough with Bolt core to devise a PR for this.

bobdenotter commented 3 years ago

I think there's a slightly broader problem underlying.

Whilst you can add a pagebinding to map an incoming request to the correct controller in the application, it doesn't necessarily work for the reverse: Create the desired URL from a given view.

What you're seeing in the sitemap should be the same as what you can see in the <canonical> meta tag in a page's header, right?

It will be non-trivial to fix this in a robust way, but the beginnings of a proper solution are here: https://github.com/bolt/core/pull/2559

ghost commented 3 years ago

Yes you're right, sticking with my example above, the canonical tag is also wrong on the page contenttype. I hadn't noticed previously.

I also tried overriding the canonical link using the appolodev/bolt-seo extension but that doesn't seem to work.

A little checking shows that the contenttype override option in routes.yaml completely stops the seo extension from working on that contenttype. It makes the seoData property of the seo variable null in the template. So that explains why the canonical override doesn't work in this case. I'll post an issue in the seo extension.

So a robust solution will be most welcome!