ben-rogerson / nuxt-seomatic-meta

A module for connecting Nuxt.js to the Craft CMS SEOmatic plugin via GraphQL. Nuxt-o-matic!
31 stars 8 forks source link

Multisite not working with language in path #5

Open maximepalau opened 4 years ago

maximepalau commented 4 years ago

Hi,

I'm experiencing an issue with the multisite logic.

I’m using nuxt-i18n to manage the languages of my application. For a same page in two different languages, the URLs are like the following:

The issue is that, when I do have a /fr prefix in my route, that prefix is sent to SEOmatic via the uri parameter (see screenshot below), and because of this SEOmatic cannot find the related entry. Craft does not include the language in the URIs of the pages. When I remove this prefix manually, it works.

Screenshot 2020-04-02 at 10 19 17

This is what I did (in a simplified version) to make it work:

let fullPath = route.fullPath;

if (fullPath.startsWith('/fr')) {
     fullPath = route.fullPath.replace('/fr/', '/');
}

return await app.seomaticMeta({ fullPath }, siteId);

I guess we can agree this is not a sustainable solution. Is there a way (with the current methods/configuration elements) to indicate to the plugin the languages to remove from the path for all the pages? Would it be possible to implement that feature otherwise?

ben-rogerson commented 4 years ago

Hey sorry for the late reply. Yeah should be possible to do - If you'd like to submit a PR with the functionality I'd be more than happy to review 👍

toddpadwick commented 3 years ago

@maximepalau @ben-rogerson I am trying to do the same - did you find a solution for this? I also have another issue related - how would I get the siteId from the siteHandle (eg fr)? the only data I will have to determine which site I am on is from the locale/handle so there's no way of me knowing what the ID is.

async asyncData (context) {
      const siteHandle = context.app.i18n.locale;
      const siteId = 1; // how do I get the siteId from the siteHandle?
      return {
          headData: await context.app.seomaticMeta(context.route, siteId),
      }
  },
ben-rogerson commented 3 years ago

Great question, I'd like to know this too. A quick google brings this function: craft.app.getSites().getSiteByHandle('handle') But the I wonder how you'd grab that from within nuxt?