Link to index.md doesn't work

This is a follow-up to my last question.

I have updated the repository at https://github.com/pgundlach/hugoexample/

There are two changes: the first is that I now have _index.md as the index page and a new shortcode linkto:

({{ with .Site.GetPage "section" ( .Get 0 ) }}{{ .URL }}{{ end}})

because ref cannot link to _index.md, right?

But still I can’t get any link to the index page. I’d like to get offline support (no server) with .html URLs

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.

1 Like

Hello @bep,

I have problems following the suggestions you have made: none of these give me a link to the home page index.html.

({{ with .Site.GetPage "section" "index.md"  }}{{ .Relpermalink }}{{ end}})
({{ with .Site.GetPage "section" "index.md"  }}{{ .Permalink }}{{ end}})

({{ with .Site.GetPage "section" "_index.md"  }}{{ .Relpermalink }}{{ end}})
({{ with .Site.GetPage "section" "_index.md"  }}{{ .Permalink }}{{ end}})

({{ with .Site.GetPage "section" "/_index.md"  }}{{ .Relpermalink }}{{ end}})
({{ with .Site.GetPage "section" "/_index.md"  }}{{ .Permalink }}{{ end}})

({{ with .Site.GetPage "section" "/"  }}{{ .Relpermalink }}{{ end}})
({{ with .Site.GetPage "section" "/"  }}{{ .Permalink }}{{ end}})

({{ with .Site.GetPage "section" "index.html"  }}{{ .Relpermalink }}{{ end}})
({{ with .Site.GetPage "section" "index.html"  }}{{ .Permalink }}{{ end}})

And your other suggestion to use relativeURLs=true: this is what I have in my config anyway.

The source (updated) is here:

https://github.com/pgundlach/hugoexample/

None of your examples look similar to my suggestion.

@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?

@frischefarbe this feature is broken in the current release, dude. You’re out of luck. it worked before, but somehow this is broken.

–mm

@markmiller Which version have you used?

I have now tried the following:

# 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)

and

.Page: {{ .Page }}<br>
.Page.File: {{ .Page.File }} <br>
.Page.Kind: {{ .Page.Kind }}<br>
.Page.Next: {{ .Page.Next }}<br>
.Page.Permalink: {{ .Page.Permalink }}<br>
.Page.RelPermalink: {{ .Page.RelPermalink }}<br>
.Page.CurrentSection: {{ .Page.CurrentSection }}<br>
.Page.Parent: {{ .Page.Parent }}<br>
.Page.Sections: {{ .Page.Sections }}<br>
.Page.Section: {{ .Page.Section }}<br>

and this is the result (index.html in the public folder):

from _index.md
.Page: Page("my title")
.Page.File: {_index.md _index.md _index <nil> md 3976528693a0108357f4928017600865 _index en}
.Page.Kind: home
.Page.Next: <nil>
.Page.Permalink: /
.Page.RelPermalink: /
.Page.CurrentSection: Page("my title")
.Page.Parent: <nil>
.Page.Sections: Pages(0)
.Page.Section: 

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.

How about adding index.html when the value is /? :sunglasses:

1 Like

@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.

We build static pages from templates and text files; every workaround is a solution.

Good luck! :slight_smile:

You have plenty of typos in your examples which gives ERROR in the log and, not surprisingly, wrong result.

See:

https://github.com/pgundlach/hugoexample/pull/1

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.

Patrick

You need to

  1. Enable relativeURLS=true
  2. Use relative links only in your project (i.e. RelPermalink etc)
  3. 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.

Hello @bep,

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.

Thanks for your help anyway!

Patrick

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.

@frischefarbe Have you created an issue? I have the similar case with the learn theme, (described here: The theme generates wrong URLs in menu when relativeURLs = true · Issue #91 · matcornic/hugo-theme-learn · GitHub), so I can create a new issue, if not done already.

I have not created an issue. (Sorry for the late answer)

Ok, I’ve just created the issue: https://github.com/gohugoio/hugo/issues/4642

1 Like