Hugo: REF_NOT_FOUND for pages using post_name/index.md file structure

Created on 25 Feb 2020  Â·  12Comments  Â·  Source: gohugoio/hugo

What version of Hugo are you using (hugo version)?

$ hugo version
Hugo Static Site Generator v0.65.3/extended linux/amd64 BuildDate: unknown

Does this issue reproduce with the latest release?

Yes

I'm a big fan of the post_slug_or_ref/index.md file structure because it makes it easy to keep track of post-specific assets. Hugo 0.65.0 broke {{< ref other_post >}} cross-linking between any two pages that use this directory-based structure, with the following error:

ERROR 2020/02/24 20:46:56 [en] REF_NOT_FOUND: Ref "some-other-page": "/.../hugoBasicExample/content/post/some-page/index.md:1:22": page not found

Here's a sample repository that demonstrates the issue.

Bug

All 12 comments

I stumbled across this issue too after updating to the latest hugo dev version (this issue does not happen on Hugo 0.64.1).

Here's a simple example:

content
  - posts
    - abc
      - index.md <-- This has {{< relref "def" >}}, which used to work awesome earlier but now gives REF_NOT_FOUND
    - def
      - index.md

I have ensured that all my post file names are unique, so {{< relref "post name" >}} worked beautifully from any post even when referencing to posts from other sections.


Here's another failure that did not happen earlier:

content
  - posts
    - abc
      - index.md <--  {{< relref "abc#some-heading" >}} also fails with REF_NOT_FOUND

The issue might be that relref and ref shortcodes are not doing the referenced post retrieval from the Site root.


This update would be essentially breaking almost all the examples in https://gohugo.io/content-management/cross-references/ (at least when used inside _leaf bundles_ index.md .. I don't use regular pages anymore.. so cannot comment on how those shortcodes behave there).

Same issue. My blog is mixed from Bundled and Single pages. 0.64 work well but 0.65 fails with multiple REF_NOT_FOUND issues. Structure is: https://gitlab.com/h4tr3d/h4tr3d.gitlab.io/-/tree/master/content

Log output sample:

Building sites … ERROR 2020/02/26 13:18:11 [ru] REF_NOT_FOUND: Ref "notes.md": "/home/hatred/Documents/Blog/h4tr3d.gitlab.io-git/content/linux.md:16:66": page not found
ERROR 2020/02/26 13:18:11 [ru] REF_NOT_FOUND: Ref "post/2008-07-03_10.32_obzhimka_kabelja": "/home/hatred/Documents/Blog/h4tr3d.gitlab.io-git/content/obzhimka_setevogo_kabelja.md:8:108": page not found
ERROR 2020/02/26 13:18:11 [ru] REF_NOT_FOUND: Ref "s.t.a.l.k.e.r._via_wine_ili_zapusk_igry_stalker_stalker_v_wine": "/home/hatred/Documents/Blog/h4tr3d.gitlab.io-git/content/notes.md:39:93": page not found
ERROR 2020/02/26 13:18:11 [ru] REF_NOT_FOUND: Ref "integrirovannyj_zvuk_na_platax_s_chipom_nforce4_alsa_i_5.1_zvuk": "/home/hatred/Documents/Blog/h4tr3d.gitlab.io-git/content/notes.md:40:109": page not found
ERROR 2020/02/26 13:18:11 [ru] REF_NOT_FOUND: Ref "post/2011-06-26_14.58_gotovim_rastrovuju_kartu_dlja_navigatora_garmin_gpsmap_62s": "/home/hatred/Documents/Blog/h4tr3d.gitlab.io-git/content/turizm.md:18:10": page not found
ERROR 2020/02/26 13:18:11 [ru] REF_NOT_FOUND: Ref "s.t.a.l.k.e.r._via_wine_ili_zapusk_igry_stalker_stalker_v_wine": "/home/hatred/Documents/Blog/h4tr3d.gitlab.io-git/content/post/2007-10-01_12.12_stalker_v_linux.md:11:124": page not found
ERROR 2020/02/26 13:18:11 [ru] REF_NOT_FOUND: Ref "post/2007.05.31_emacs": "/home/hatred/Documents/Blog/h4tr3d.gitlab.io-git/content/post/2007.06.05_vot_uzhe_sovpadenija.md:11:420": page not found
...

Same issue on my blog and I don’t use the post_slug_or_ref/index.md structure but rather blog/post_slug_or_ref.md. Can confirm 0.64.1 works and 0.65 doesn’t.

Just a quick note ... I have seen this issue and it's on my radar. Just that regular life has been a little bit busy lately. You know, work.

Understood! Bugs happen, and I've pinned my website to v0.64.1 so it's not causing me any loss of sleep in the meantime :)

@bep I am using a nested content structure and the current master (3e9db2ad) did not work for me. See https://github.com/bilke/hugoRegressionExample/commit/59952780ff8b94e145405a99c8f1cc8ea8abffbf. 0.64 worked with this structure.

@bilke I tested your site before I closed this issue ... I tested it OK again now. I assume it is the navigation between some-page and some-other-page? Are you running Windows? But I don't understand that, either, because I added a test for this.

@bep No I am another guy (I am not @thirtythreeforty) but I took his example and modified it to reproduce my issue!

See my repo: https://github.com/bilke/hugoRegressionExample/commit/59952780ff8b94e145405a99c8f1cc8ea8abffbf

I am on macOS:

$ ./hugo version
Hugo Static Site Generator v0.64.1-C327E75D/extended darwin/amd64 BuildDate: 2020-02-09T20:50:50Z

$ ./hugo
...
                   | EN
-------------------+-----
  Pages            | 18
  Paginator pages  |  0
  Non-page files   |  0
  Static files     |  1
  Processed images |  0
  Aliases          |  9
  Sitemaps         |  1
  Cleaned          |  0

Total in 60 ms

$ /Users/bilke/tmp/hugo/hugo version
Hugo Static Site Generator v0.66.0-DEV darwin/amd64 BuildDate: unknown

$ /Users/bilke/tmp/hugo/hugo
...
ERROR 2020/03/02 19:29:22 [en] REF_NOT_FOUND: Ref "content-a": "/Users/bilke/tmp/hugoRegressionExample/content/post/nested-b/content-b.md:1:21": page not found

I can confirm the same behavior on Arch Linux (where the second error is already fixed by this PR):

$ hugo version
Hugo Static Site Generator v0.65.3/extended linux/amd64 BuildDate: unknown

$ hugo
...
ERROR 2020/03/02 19:30:26 [en] REF_NOT_FOUND: Ref "content-a": "/home/bilke/tmp/hugoRegressionExample/content/post/nested-b/content-b.md:1:21": page not found
ERROR 2020/03/02 19:30:26 [en] REF_NOT_FOUND: Ref "some-other-page": "/home/bilke/tmp/hugoRegressionExample/content/post/some-page/index.md:1:22": page not found

OK... I Will have a look ...

I confirm the fix. Thanks!

Hello. I'm slightly late to this discussion. I'm using Hugo Extended v0.74.3 on Windows.

I had my file structure as content/posts/a.md and today, I decided to move it to content/posts/a/index.md and I started getting the error mentioned in this thread.

I've narrowed it down to my partial that's causing the issue:

{{ $headers := findRE "<h[2-4].*?>(.|\n])+?</h[2-4]>" .Content }}

{{ .Scratch.Set "lastLevel" 1 }}

{{ $hasHeaders := ge (len $headers) 1 }}

<div class = "grid-item" data-cues = "slideInUp" data-duration = "500"> <!-- Cell container -->

  <div class = "mdc-card mdc-typography" style = "padding: 16px;" data-turbolinks = "false"> <!-- TOC container -->

    <h5 class = "mdc-typography--headline5" style = "margin: auto 0 24px; text-align: left;"> <!-- TOC name -->
      Contents...
    </h5>

    {{ if $hasHeaders }}

      {{ range $headers }}

        {{ $lastLevel := $.Scratch.Get "lastLevel" }}

        {{ $header := . }}

        {{ $base := ($.Page.File.LogicalName) }}

        {{ $anchorId := ($header | plainify | htmlUnescape | anchorize) }}

        {{ $href := delimit (slice $base $anchorId) "#" | string }}

        {{ range findRE "[2-4]" . 1 }}

            {{ $nextLevel := (int .) }}

            {{ if gt $nextLevel $lastLevel }}

              {{ range seq (add $lastLevel 1) $nextLevel }}

                <ul class = "mdc-list toc toc-h{{ . }}">

              {{ end  }}

              {{ else if lt $nextLevel $lastLevel }}

                {{ range seq (add $nextLevel 1) $lastLevel}}

                  </ul>

                {{ end }}

            {{ end }}

              <a href = "{{ relref $.Page $href }}">
                <li class = "mdc-list-item" data-mdc-auto-init = "MDCRipple">
                  <span class = "mdc-list-item__ripple"></span>
                  <span class = "mdc-list-item__text">{{ $header | plainify | htmlUnescape }}</span>
                </li>
              </a>

            {{ $.Scratch.Set "lastLevel" $nextLevel }}

        {{ end }}

      {{ end }}

    {{ end }}

  </div>

</div>

As soon as I remove the href attribute with the value of the <a>, my build succeeds, I add it back and it doesn't gives the same errors. The number of times the same error appears in the console is equal to the number of headings (h2-h4) that I have in my markdown file. Also, if I switch back to content/posts/a.md, the website works again. Can someone help me?

Edit: I don't have a Git repo for the project yet, so, here's my project folder as it is: Portfolio.zip.

We have an active discussion forum where users and developers can ask questions. Please don't use the GitHub issue tracker to ask questions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vielmetti picture vielmetti  Â·  3Comments

VoidingWarranties picture VoidingWarranties  Â·  3Comments

sigma picture sigma  Â·  3Comments

mumblecrunch picture mumblecrunch  Â·  3Comments

kaushalmodi picture kaushalmodi  Â·  3Comments