This repository has been archived by the owner on Dec 24, 2021. It is now read-only.
Add netlifly URL aware build (fixes sitemaps and absolute urls in Hugo) #532
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.
- Summary
There is a problem-ish with Hugo itself, as specified here: https://discourse.gohugo.io/t/invalid-sitemap-url/26269/3
If you have
Hugo will generate a sitemap that does not have valid URLs, according to the sitemap standard. This is problematic if you want to add your site to Google search index.
If you do
Then all your dev environment links will link to your production site, which is not great.
Other templates added their own magic to their build process, as is the example of Atlas template: https://github.com/indigotree/atlas/pull/39/files#diff-7291edac743a0e6f594d817cb46f00cb3866bf89f40569ae494e36c1b722afa8R65
In this approach I leveraged the Netlify build env and just
bashsh:Netlifly has a build env
DEPLOY_PRIME_URL
that contains the main url of the site. By passing that env variable in the build process (defaulting to/
) we are able to generate valid site maps with the default templates.Warranted that the default value might generate some confusion if they change
baseUrl
and the setting is overridden by the build process. Suggestions are welcome. Maybe making an if/elif would be better.EDIT Added support for production and deploy builds
- Test plan
npm run build
Generates:URL=hello.com DEPLOY_PRIME_URL=world.com CONTEXT=production npm run build
Generates
URL=hello.com DEPLOY_PRIME_URL=world.com CONTEXT=deploy-preview npm run build
Generates
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)