funkydan2 / hugo-kiera

Kiera - A Hugo Theme for writing
https://hugo-kiera.netlify.app
MIT License
71 stars 52 forks source link

Some used URLs ignore baseURL? #78

Open vadcx opened 2 months ago

vadcx commented 2 months ago

Some used URLs appear broken if the website is not hosted at domain root. While it won't affect most users, this ought to be a bug. Docs: https://gohugo.io/functions/urls/relurl/

Consider that hugo.toml sets the expectation of a sub-site:

baseURL = 'https://example.org/suburl/'

Currently when built, I witness this on index.html for header_includes.html:

  <link rel="stylesheet" href="/suburl/css/normalize.min.css" />
  <link rel="stylesheet" href="https://example.org/suburl/fontawesome/css/all.min.css" />

    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab|Ruda" />

  <link rel="stylesheet" type="text/css" href="/suburl/css/styles.css" />
</head>

header.html:

      <h1>
        <a href="/">My New Hugo Site</a>
      </h1>

I think if I really uploaded it to a webserver's subdirectory, the CSS/JS links would've continued to work. In contrast the literal / root link pointing to domain root rather than baseURL:

https://github.com/funkydan2/hugo-kiera/blob/dcf867345d7b5a875fc320953483db3578db97e8/layouts/partials/header.html#L19-L21

It could lead to nowhere or to a different website at domain-root/

I had thought to replace "/" with config's baseURL, but that code wants relative language URL and I've never worked with that, so I don't know if just using baseURL is appropriate here?

funkydan2 commented 2 months ago

I think you're headed in the right direction...see https://gohugo.io/functions/urls/rellangurl/

From the docs I think it should be <a href="{{ relLangURL "" }}">{{ .Site.Title | markdownify }}</a>

Are you aware of anywhere else in the code where this happens?

vadcx commented 2 months ago

I am only playing with Hugo for now. I had used ripgrep on the example site but don't remember what for. If you run a site with this theme too, maybe the search pattern "/ could find all such URLs.

It seems weird to me. After finding out the above (baseurl needed to put the website in a subdirectory), I can't find many a valid use for relative URLs. Especially because they are not directory-traversal relative ../parents-subfolder/resource.png but Hugo assumes relative ought to mean relative to root.