(gatsby-plugin-sitemap) omit assetPrefix from page URLs #31454
Closed
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.
Description
The sitemap plugin uses an internal function
prefixPath
to append a site's base URL, as well as its path prefix if one is set, to the URL of each serialized page in the sitemap. The path prefix is retrieved from thepathPrefix
string available via the arguments to theonPostBuild
hook. This string is a concatenation of theassetPrefix
andpathPrefix
configuration options. Currently, the sitemap plugin naively uses this string in generating sitemap page URLs, when in fact only thepathPrefix
string should be part of a page URL in the sitemap and theassetPrefix
should not.This PR modifies the
prefixPath
function, such that it avoids also including an asset prefix if one is set ingatsby-config
. This is done by retrieving theassetPrefix
configuration option and passing it toprefixPath
so that it can then be omitted from the prefix, if it is indeed present.Notes
In this PR the
assetPrefix
value is retrieved via the Reduxstore
passed in theonPostBuild
hook's arguments. This argument is marked as "use only if you have to" in the Gatsby source code . I was not able to find any public/"safe" API for accessing the value of theassetPrefix
config option insideonPostBuild
.