How do you handle branches with the baseURL?

Hi everyone,

We often use feature branches on our website. We currently set the baseURL as the root domain (for the main website). This causes issues when going to another branch. Currently, we manually change the baseURL but that’s risky as the pull request might accidentally update it for the live too.

My current thinking is to replace baseURL from:

baseURL: "https://domain.com/"

to:

baseURL: "/"

Is there any risks in doing that? I’ve tested it on a branch and seems to work well. Just wondered if there are any implications that not being a domain.

How does everyone else handle this, please?

Thanks,

Dave.

How/where are you deploying your website?

You can pass the baseURL as a command line arg when running Hugo: Basic Usage | Hugo

If you are using Netlify for example, you can pass the deploy url as part of the build.

This is perfect. Yes, I’m using Netlify. Thanks for your help.

This conf works fine on netlify

[build]
publish = "public"
command = "hugo --minify"

[context.production.environment]
HUGO_VERSION = "0.80.0"
HUGO_ENV = "production"
GO_VERSION = "1.14.4"
RUBY_VERSION = "2.6.2"
HUGO_ENABLEGITINFO = "true"
TZ = "Europe/Zurich"
NODE_VERSION = "12.2.0"

[context.deploy-preview]
command = "hugo --buildFuture -b $DEPLOY_PRIME_URL"

[context.deploy-preview.environment]
HUGO_VERSION = "0.80.0"
RUBY_VERSION = "2.6.2"
GO_VERSION = "1.14.4"
HUGO_ENABLEGITINFO = "true"
TZ = "Europe/Zurich"

[context.branch-deploy]
command = "hugo -b $DEPLOY_PRIME_URL"

[context.branch-deploy.environment]
HUGO_VERSION = "0.80.0"
RUBY_VERSION = "2.6.2"
GO_VERSION = "1.14.4"
HUGO_ENABLEGITINFO = "true"
TZ = "Europe/Zurich"
1 Like

Thanks for sharing, @ divinerites. Almost exactly what I ended up with! :smiley:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.