Linking to a directory of resources without error

I am doing upkeep on a course webpage built in hugo. For each lecture, I provide a link to a directory of example python-files I used during the lecture to illustrate different concepts. However, hugo is not happy about me linking to a directory, throwing these types of error messages:

´ERROR Failed to publish Resource: open […]/public/slidelitt/kod/t3: is a directory´

However, other than these messages the site builds, and the links work, taking me to exactly what I expect and want to see:

index_of_slidelitt_kod_t3

I can see why hugo wouldn’t like me doing this without giving any instructions and why it would assume I did it by mistake. However, the behavior I get is exactly the behavior that I want, and I would also argue that this is a legitimate way of doing things (it is at least a way of doing things as old as the www). Thus, I suspect that there must be way for me to tell hugo that I’m doing this “on purpose” and that I don’t need an error message.

So, is there a way to do this without hugo getting upset? The superfluous false positive errors are jarring and makes debugging actual errors more difficult.

(I’m not averse to a page that looks different and less 1993, but I really don’t want to have to build (or rather, write a script that generates) a markdown file with a hard-coded link to each individual file either.)

Without any code, config and used theme you won’t get more than an educated guess.

Here is mine:

  • You are using standard markdown to reference the folder.
  • you have a link render hook (your own or from hugo or from theme)
  • the hook tries to find and render the resource (a file) but fails.

You can solve that in various ways.

  • adapt the render hook to handle folders.
  • create a shortcode that creates a link to a folder without calling any hugo method that tries to render the page
  • use verbatim html <a href tag in markdown. See Configure markup | Hugo

Beyond this hugo can create a listing page for your resources using content adapters or a list layout.

Btw. Serving a listing page when linking to a folder is an option of a web server.

2 Likes