Access file system path of content directory when module.mounts is used

Ordinarily, as in this shortcode, the below works fine for computing a certain path:

{{- $rootDir := $.Get "rootDir" | default (print "/content/" .Page.File.Dir) }}

However, on a windows machine (Hugo Static Site Generator v0.72.0/extended windows/amd64 BuildDate: unknown), we have the following config for which the above fails on use with readDir (error calling readDir: failed to read directory "/content/sAma\\meta\\paravastu-sampradAyaH\\images\\."):

    source = "../vedAH-content"
    target = "content"

How would I avoid hardcoding /content/? I tried looking at Site Variables | Hugo and did not notice any variable which will give me the path to the content directory. I want to avoid doing something ugly like passing it in .Site.Params. Any ideas?


Change your shortcode to access images as page or global resources.

1 Like

Page resources wouldn’t work if I want the shortcode to list contents of an arbitrary content directory (passed as argument to the shortcode). What are global resources (googling did not help)? Would it overcome this problem?

Yes, it would. See:

Anything in the assets directory. See:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.