Skip to content
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

Proper URL-handling between local and production builds #38

Closed
olafghanizadeh opened this issue Feb 20, 2018 · 13 comments

Comments

@olafghanizadeh
Copy link

@olafghanizadeh olafghanizadeh commented Feb 20, 2018

After having launched a site based on Atlas I found out that Google requires you to have full-path URL's (including protocols) to validate sitemaps. Therefore the baseURL can't be set to /. It should be set to the production URL. However, when doing this running atlas with browsersync sets the URL's to production URL.

I think running the default task "gulp server" should run a command similar to "hugo server" that changes the URL's relative to the environment.

@crgeary

This comment has been minimized.

Copy link
Member

@crgeary crgeary commented Feb 20, 2018

Thanks for raising the issue with the sitemaps, I'll try look into that ASAP, although that might not be for a day or two.

I'm yet to look into this which may help solve the problem.

The main problems with setting the baseURL to the live domain is that it's hard to distinguish the difference between Netlify previews, Netlify branch deploys & the primary website. It's been a while since I looked at the docs for this, so perhaps things have changed.

In the meantime, you could overwrite the netlify.toml file to set the baseURL for production builds.

Sorry :)

@moshie

This comment has been minimized.

Copy link
Contributor

@moshie moshie commented Feb 20, 2018

This should be fixed now!

If you wouldn't mind merging my PR @crgeary 👍

@crgeary crgeary closed this in #39 Feb 20, 2018
@crgeary

This comment has been minimized.

Copy link
Member

@crgeary crgeary commented Feb 20, 2018

Merged, thanks both of you for raising it, and fixing it 👍

@olafghanizadeh

This comment has been minimized.

Copy link
Author

@olafghanizadeh olafghanizadeh commented Feb 21, 2018

So for this to work properly, which URL's do I have to define and where?

@crgeary

This comment has been minimized.

Copy link
Member

@crgeary crgeary commented Feb 21, 2018

Assuming you're using Netlify (as this is heavily integrated with Netlify), then it should just work for you without any changes from you.

The builds make use of the DEPLOY_PRIME_URL and the URL environment variables that Netlify makes available in the build. Your config.toml should still be / (for localhost), the other sites (production, branches & deploy previews) will be set by Netlify.

Please let me know if you have any issues :)

@olafghanizadeh

This comment has been minimized.

Copy link
Author

@olafghanizadeh olafghanizadeh commented Feb 21, 2018

Ah, I see. Keep baseURL as / and then Netlify injects the correct URL on build then?

@crgeary

This comment has been minimized.

Copy link
Member

@crgeary crgeary commented Feb 21, 2018

Exactly that 👍

@raheems

This comment has been minimized.

Copy link

@raheems raheems commented Aug 2, 2018

Can anyone confirm that to properly have the URLs in the generated sitemap.xml file, the Netlify build parameters should be like this:

Key: URL
Value: http://www.domain.com

I've done this but the sitemap.xml still does not show the site's actual url.

@crgeary

This comment has been minimized.

Copy link
Member

@crgeary crgeary commented Aug 2, 2018

The Netlify URL environment variable should be set for you automatically, based on which your settings are within the Netlify control panel.

It'll either be your *.netlify.com subdomain, or your primary domain as set up within the domain settings of the panel.

I've just checked a site we built recently running Atlas, and the urls within the sitemap appear to be correct.

@raheems

This comment has been minimized.

Copy link

@raheems raheems commented Aug 2, 2018

This is how it worked:

Added the deployment parameter:

Key:URL
Value: http://mysite.com

And then modified the build command to following:

hugo -b $URL

@crgeary

This comment has been minimized.

Copy link
Member

@crgeary crgeary commented Aug 2, 2018

Oooh, you're not using Atlas. You probably want to raise these on https://discourse.gohugo.io/ as this Issue is for Atlas issues.

For the record, Atlas handles all of this stuff for you.

@jonas-sk

This comment has been minimized.

Copy link

@jonas-sk jonas-sk commented Apr 23, 2019

@crgeary Despite having my primary domain set, my sitemap still points at the netlify.com subdomain:

grafik

How do I fix this?

@crgeary

This comment has been minimized.

Copy link
Member

@crgeary crgeary commented Apr 23, 2019

Hi @jonas-sk

Could you try this fix: #70

Please let me know how this helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.