3
votes

I created a Hugo site that working well locally. I deployed my Hugo site as a Github Pages project via a /docs folder on the master branch. So now, I have my Github Page project and my URL looks like that:

https://myname.github.io/myrepository/myHugoSite.

I have a problem with my link. All my links redirect to https://myname.github.io/ but not https://myname.github.io/myrepository/ because my links are /next-page/. These links are working locally because I don't have a repository.

My question is: Do I have to add /myrepository/ to all my links or there is another solution?

2

2 Answers

3
votes

You need to add your site prefix to the baseUrl parameter in the config file. In your case the prefix is myrepository/

If you are using TOML format in your config file it would look like this:

baseUrl = "https://myname.github.io/myrepository/"
0
votes

Note that with Higo 0.62.1 (and more recent), you can have portable links.

See bep/portable-hugo-links as an example.

truly portable Markdown links and images. No shortcodes used.

This page includes the following links, which would be rendered correctly both on GitHub and Hugi generated pages:

* [Blog Link1](../blog/p1/index.md)
* [Blog Link2](../blog/p2.md)
* [Home Page](/README.md)
* [Local Anchor](#et-illis-ossaque-loqui-ille)