joeroe / risotto

A minimalist, responsive hugo theme inspired by terminal ricing aesthetics.
https://risotto.joeroe.io
MIT License
393 stars 109 forks source link

Remove Absolute URL and replace with Relative URLs for Docker compatibility #36

Closed AIndoria closed 2 years ago

AIndoria commented 2 years ago

When you run a Hugo server in docker, and serve via nginx, things get a bit iffy.

Absolute URLs like {{.Permalink}} and {{ . | absURL }} cause issues when site is served to the point that blog links are served as

image

and base URL(s) as

image

which is not ideal. Replacing them with {{.RelPermalink}} and {{ . | relURL }}fixes the issue.

Further, {{.Site.BaseURL}} in header.html, will do the same, but replacing with "/" works, although I am less sure about this change.


Note that above things while they work on default on published sites for Hugo, they will always fail while running Hugo in a docker server unless said changes are made.

joeroe commented 2 years ago

Hmm, I generally prefer absolute URLs, and hard-coding links to / is definitely not going to work (e.g. for sites served under a directory).

Are you sure this not a configuration problem? Have you set baseURL in config.toml?

AIndoria commented 2 years ago

The "/" is something I don't have a good solution for tbf, was thinking you could provide an alternative, but the {{.RelPermalink}}and {{ . | relURL }} are necessary for it to work in docker when run as a server. the "/" is only at one spot when clicked on the title, but I'm unsure how else to point it to the accurate url.

and yes, the baseURL is set appropriately. It just always redirects it to localhost when run in docker for most content links (such as posts).

image

https/http make no difference.

I can modify it to just do the relative urls while we figure out the "/" issue, if you'd like.

It should be fairly easy to emulate : Run Hugo server like the docs refer to here, add the theme, add a post, check the title URL of the post from the posts page, and the title link of the blog etc.

joeroe commented 2 years ago

I see, thank you. I do think this is a configuration issue rather than something than needs to be changed in this theme.

hugo server is intended for local development so it ignores the baseURL setting. The expected way to serve the site in production is to build it with hugo or, using the docker image from https://github.com/klakegg/docker-hugo, the command listed under "normal build". If you have to use it in production, you need to add some extra command line options to hugo server, including --baseURL as explained here: https://discourse.gohugo.io/t/hugo-website-deployment/388/11

But as far as we're concerned, if hugo and the server is configured correctly, .Permalink should be the URL of where the page is actually served. Maybe consider opening an issue at https://github.com/klakegg/docker-hugo to clarify their documentation?