vaersaagod / seomate

SEO, mate! It's important. That's why SEOMate provides the tools you need to craft all the meta tags, sitemaps and JSON-LD microdata you need - in one highly configurable, open and friendly package - with a super-light footprint.
MIT License
36 stars 8 forks source link

Multi-Site Sitemaps #88

Closed SwiseWeb closed 3 months ago

SwiseWeb commented 3 months ago

Hello! We have a multi-site setup right now where one Site is public-facing and the other is gated by a user login. Ideally, we'd like to turn on sitemaps for the public site and disable entirely for the gated site. There are some CMS Sections which are shared between the two Sites with different Entry statuses/visibility.

Perhaps I'm missing something, but it doesn't look like there's a way to have Site-specific configuration right now. Is there a workaround for this which we could consider here?

SwiseWeb commented 3 months ago

Disregard, got this sorted by using a ternary for sitemapEnabled based on the currentSite handle

mmikkel commented 3 months ago

Hi @SwiseWeb, good to hear that you found a solve – I'm assuming you're using Twig to override SEOMate's config for the sitemapEnabled setting?

For posterity and FYI, elements from disabled sites will never appear in SEOMate sitemaps – but having some way of excluding particular enabled sites from sitemaps in config/seomate.php would be a good addition. I'd probably implement this by adding closure support to the sitemapEnabled setting (similarly to how the outputAlternate setting accepts either a boolean, or a closure returning a boolean).

SwiseWeb commented 3 months ago

@mmikkel adding "sitemapEnabled" => Craft::$app->sites->getCurrentSite()->handle === "default", as part of the seomate.php config file seems to be working the way we want, so no Twig required.

Yea, the closure option would be great here - that's I initially thought to try before seeing the accepted types for sitemapEnabled. The Site where we want sitemaps turned off in this case is fully enabled in Craft with live entries. And we want some of the SEOMate features here for metadata purposes, just not sitemaps.

mmikkel commented 3 months ago

@SwiseWeb Thanks for the follow-up. That's a clever way to handle it.

Note that that solution won't prevent entries from the other site from appearing as alternates in sitemaps for the default site, if the outputAlternate setting is set to true, and entries are configured to propagate across sites.

I'm guessing that isn't an issue for your install, but for others ending up here with a similar use case, you could do something like this in your config/seomate.php file (in addition to what you're already doing for sitemapEnabled):

'outputAlternate' => static fn($element, $alternateElement) => $alternateElement->site->handle === 'default',

In any case, I think the ability to have sitemapEnabled conditionally apply for different sites would be useful, so I'll try to remember to add a solution for that in a future release. Will update this issue if I do 🙃

SwiseWeb commented 3 months ago

@mmikkel yep, I turned outputAlternate off entirely in this case since it's not really relevant in our situation. Good to know for the future though, thanks for the discussion here!