I’m come from China user of Hugo, when we visited to github pages service that sometime is miss. So there need backup a pages in China land. Now I come true sync github repository code to other Chinese repository, when github build pages code(static files) would auto sync the Chinese repository. But found that the baseURL were fixed, so when visited Chinese pages service and clicked page’s link that would jump to Github pages, there was not good.
My site build with Hugo CLI like this:
hugo -b https://xxxx.github.io/demo/ --minify
At first I think the baseURL parameter will support subfolder , then I tried some command in local like this:
hugo server -b demo or hugo server -b demo/
## output visit url: //demo:port/
hugo server -b /demo/
## output visit url: //C:1414/Program%20Files/Git/demo/
Actually I want it could generate relative path with subfolder which name is demo, Then when visited different domain as below it can jump right things.
So is there some way can set baseURL not full domain & subfolder, just with the subfolder then it could be generate once code and bind with different domain more easy.
I’m not sure what your setup is but hugo -b https://sub.domain.tld/subfolder/ should work.
For example:
hugo -b https://sub.domain1.tld/subfolder/
hugo -b https://sub.domain2.tld/subfolder/
hugo -b https://sub.domain2.tld/subfolder/
Since you are mirroring your Github repo in a China-hosted git repo, you can do it two ways
1st method: Use hugo -b https://sub.domain2.tld/subfolder/
2nd method: Add the environment variable HUGO_BASEURL with a value of https://sub.domain2.tld/subfolder/
There is another way, by setting a different destination path for built files. I think the command is hugo -d so say hugo -b https://sub.domain2.tld/subfolder/ -d /public_domain2/. Then you can set your domain name to point to that folder. (note: I haven’t tried this setup, it may or may not work.)
So I don’t want fixed the -b parameter setting, maybe it could sets /hugo-next-docs , and then when user visited under domain hugo-next.github.io all href will appen baseURL with domain, the link come be like this https://hugo-next.github.io/hugo-next-docs/post/. I don’t known it there could be support this.
That’s true, you will have to customize your server environment and other related settings.
Unfortunately, at least as far as I know, it is not possible the have multi-domain support by just setting up the path.
I haven’t tried an empty baseURL, baseURL = "", I’m not sure how it will affect other functions of Hugo (like URL generations for assets, permalinks, etc.) Maybe someone tried this before.
Thanks @bep suggest, but in here I want to backup site all things to other repository. But when Hugo generate static site files were with baseURL settings , so that only one domain could be set in. Maybe I need build tow times with different domain settings and push each other.
Ok, there I found more & more history discusses in forum, then found that could use canonifyURLs: true parameter to keep the Permalink with subfolder then use Hugo build command same as the github-action-script .
Becase the page have creative commons links need full links so can’t without baseURL.