ref cannot currently get home page, sections etc., but I consider them as static (i.e. they don’t move around, and if they did move around I would have to change the refs as well) so I have never found a use for that.
You should use Permalink or Relpermalink, not URL.
As to offline support I suggest looking at relativeURLs=true.
@bep, obviously I don’t understand, and I have problems understanding what I am doing wrong. I’d appreciate any pointer to the right direction.
I understood your answer to replace URL by Relpermalink or Permalink. And to try relativeURLs=true. The last thing is in my config, the first one is what I have tried, but obviously something is wrong with my approach. Can anybody help me on that?
# when I include the line, all my links contain example.com
#baseURL = "http://example.com"
languageCode = "en-us"
title = "foo"
theme = "mytheme"
canonifyURLs = false
uglyURLs = true
relativeURLs = true
(including other combination of true/false in all values and setting the baseURL)
So I assume that you are right. But I still like to know if there is any way to get a correct link to “index.html”. The .RelPermalink is broken when it comes to non-served files.
@maiki This would of course work, but that is a workaround, not a real solution. IMO the idea to link to the start page is not so off, that others might participate in having a proper solution.
Having a PermaLink of “/” or a RelPermalink of “/” is just wrong (in this setting). So either it is a bug in Hugo (which I slightly doubt) or it is an incorrect setting on my side (site). But I have no idea which setting this could be, as I have tried a lot of differnt things here.
Hello @bep, thank you for the patch, but it doesn’t solve my problem with the linking:
I try to state my goal: I have lots of pages that serve as a documentation for software product. I want to ship the HTML pages with the software as “static files” which can be viewed without a webserver, just a browser. Therefore the href="…" URLs must not start with a “/” nor with “http”. They must contain relative links for that. An example is at https://speedata.github.io/publisher/manual/index.html.
The normal relative links can be easily achieved with the <relref "...md"> shortcode. But the <relref ...> doesn’t seem to work for _index.md (as you have written). I have tried your code on Github with .RelPermalink, but this always starts with a slash.
{{ with .Site.GetPage "home" }}{{ .RelPermalink }}{{ end}}
should give something like
../index.html
or whatever, but instead it gives me
/
which is a page that does not exists.
I know that I am bothering people (esp. you) here by keeping insinsting on finding a solution, I really apologize. Since I know that Hugo is really full of features and great, I still doubt that this is a limitation of Hugo but a misunderstanding on my side.
Use relative links only in your project (i.e. RelPermalink etc)
Look at the LINKS in the generated HTML out put. Your test isn’t realistic.
No, it shouldn’t. You don’t understand how the relativeURLS=true feature works – it translates links (a href etc.), so you cannot look at RelPermalink in isolation.
But I would say that this currently is a “expert feature”. Maybe we can make this simpler in the future.
I think we have a complete misunderstanding of each other. I do have relativeURLs=true and use RelPermalink, but still I can’t achive my goal. My test is realistic in the sense that this is exactly the problems I want to solve, but it seems not to be possible with Hugo at the moment.
I understand that Hugo’s relative links are not the same as I need them to be (except for relref), so I think I need to stick with a workaround. Which is ok, I just wanted to make sure that there is no Hugo solution available.
OK, I see it now. The RelPermalink to the home page Isn’t “ugly” – which I guess is by design. We could change that in the relativeURLs=true case, but you need to create a GitHub issue.
But note that the value of RelPermalink would then be /index.html and not ../index.html or whatever. And you can also easily append the “index.html” suffix to the URL yourself, as home page is a special case. The other sections should be ugly.