Skip to content

Feature/skip pages where path is starting with locale already #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chrisrueger
Copy link

@chrisrueger chrisrueger commented Feb 5, 2022

This PR suggests a new option skipPagesStartingWithLocale (default: false)

It skips creating page clones per locale if the path already starts with a locale e.g. /en/blog/foo or /de/blog/foo

This can be the case for gridsome templates which already contain a locale-prefix coming e.g. from a .md file where people maintain the language / locale themselves (e.g. in a frontmatter block with a "lang: en" flag)

In this case those pages are already correct and can be skipped while still creating a locale-path for everything else.

What problem does it solve?

Without this option this plugin will create double-prefix the locale to pages which already have a locale-prefix.
This leads to a deeply nested /dist folder where each locale contains the locale sub-folders again.

e.g.

  • /dist/de
  • /dist/de/de
  • /dist/de/en
  • /dist/en
  • /dist/en/de
  • /dist/en/en

This increases the resulting /dist folder size a lot. It works technically, because all files are there and correct, but the dist folder is larger than needed which wastes build and deployment time.

Example:

// gridsome-config.js

templates: {
Post: [
 {
  path: (node) => {
    return `/${node.lang}/blog/${node.slug}`
  }
 }
],
}

In this example the locale is take from node.lang which could come from a .md file when using @gridsome/source-filesystem.

Since template paths are different for every template / type, some could contain the locale, some not.

This might be a corner-case flag, but useful if this plugin works for 90% of existing pages, but you have some exceptions, where you have maintained you locale yourself already.

Just some background about our use case

We build a site using different datasources:

  • @gridsome/source-filesystem
  • @gridsome/vue-remark
  • and some items from a remote REST-API via api.loadSource(({ addCollection }) and templates

Our templates in gridsome.config.js are:

templates: {
    
    Tag: '/tag/:id',
    
    PostType: '/explore/:id',

    Post: [
      {
        path: (node) => {
          return `/${node.lang}/blog/${node.slug}`
        }
      }
    ],



    Addon: [
      {
        path: (node) => {
          return `/${node.lang}/addon/${node.slug}`
        }
      },
}

As you see some templates do have the /${node.lang} some have not. The latter work already fine with this plugin.

This new option 'skipPagesStartingWithLocale' allows to skip creating page clones per locale if the path already starts with a locale e.g. /en/blog/foo or /de/blog/bar

This can be the case for templates which already contain a locale coming e.g. from a .md file where people maintain the language / locale themselves (e.g. in a frontmatter block with a "lang: en" flag)

In this case those pages are already correct and can be skipped while still creating a locale-path for everything else.
@chrisrueger chrisrueger changed the title Feature/skip pages starting with locale already Feature/skip pages where path is starting with locale already Feb 5, 2022
@chrisrueger
Copy link
Author

Hi @daaru00 , any chance you could have a look at this? Thanks 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants