openscript-ch / gatsby-plugin-i18n-l10n

Gatsby I18n Plugin 🌐, which let you translate pages, content and the url or slugs of pages. Batteries 🔋 included.
https://www.gatsbyjs.com/plugins/gatsby-plugin-i18n-l10n
MIT License
19 stars 2 forks source link

Gatsby option `trailingSlash` not considered #176

Closed acocheo closed 10 months ago

acocheo commented 1 year ago

By now this plugin doesn't use Gatsby trailingSlash option for URLs. Every time the plugin needs to build a path from scratch, it calls trimRightSlash. For example here
Example

/test/ ✅   ==>    /test ❌

(Note: Gatsby automatically does a redirect to correct url, but wrong urls give troubles to SEO).

Consider that trailingSlash default is always.

acocheo commented 10 months ago

This bug impacts every times the code uses the translations context. For example:

openscript commented 10 months ago

Thank you for creating this issue.

I'll try to observe https://www.gatsbyjs.com/docs/reference/config-files/gatsby-config/#trailingslash and do it as configured for Gatsby.

openscript commented 10 months ago

Unfortunately there is no possibility to read the option from a plugin. I've introduced another option here: https://github.com/openscript-ch/gatsby-plugin-i18n-l10n/pull/187

Does this work for you?

acocheo commented 10 months ago

Branch downloaded, compiled and tested in a project. It seems ok! All urls I can see (in hrefLang etc ) are correct TY! Waiting for release

openscript commented 10 months ago

I've released a new version. I hope everything works out. Thank you for raising this.

acocheo commented 10 months ago

Hi again @openscript , sorry but we have noticed an issue during production build. It's about 404 page

 ERROR  UNKNOWN

Truncated page data information for the failed page "/it/404.html/": {
  "errors": {},
  "path": "/it/404.html/",
  "slicesMap": {},
  "pageContext": {
    "locale": "it-IT",
    "localePagesId": "404.html",
    "translations": [
      {
        "locale": "en-GB",
        "path": "/404.html/"
      }
    ],
    "prefix": "it"
  }
}

failed Building static HTML for pages - 2.622s

Reading docs https://www.gatsbyjs.com/docs/how-to/adding-common-features/add-404-page/ I see that the 404 page is compiled as 404.html, so I think it's a special route where trailingSlash should not be used (my guess)

Thanks for your help