I’ve created a site using Hugo. Everything is OK so far. Now I need to deploy the site to several other domains as a sub-site. To do that, I have to change the baseURL manually everytime.
I’m wondering if there is a way to set a dynamic baseURL, so that I don’t have to change it everytime when deployed to a different domain?
There are common scenario where one wants to host the same site with multiple host, say example.org, example.com. given architectural perspective it not necessarily feasible to build different version for each host.
I guess given the static nature of Hugo (not sure there is any runtime js executed the client) one assumes it may not be to possible for dynamic host support based on using window.location.hostname and window.location.protocol to construct dynamic links.
If one has CORS set up with the require allowed origins one can avoid host spoofing.
@jmooring it’s not the site contents but the links built into the generated site in for example the index.html that have the base URL hard coded into them. This will not work in a desirable/consistent way if via another host.
Imagine you have deployment of the same site build to two hosts, one on an internal and one on an external network, there is not way to have these deployment be independent and the links for one will try and fetch resources from the other.
I don’t, if you build the hugo static site, and look at the resultant public/index.htm you notice that any resources, ccc, js, fonts etc have the Base URL generated into the files, as does the public/index.mim<>.js such that deploying the site on a different host word not work.
My suggestion is to. make these links dynamic by leverage the window.location.hostname and window.location.protocol
The base url is configured I the config/next/config.toml or can be overridden on the Hugo command line with the -b option.