Feature/skip pages where path is starting with locale already #43
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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:
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:
Our templates in
gridsome.config.js
are:As you see some templates do have the
/${node.lang}
some have not. The latter work already fine with this plugin.