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\\."):

  [[module.mounts]]
    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?

Yes.

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

https://gohugo.io/content-management/page-resources
https://gohugo.io/content-management/image-processing

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:
https://gohugo.io/functions/getpage

Anything in the assets directory. See:
https://gohugo.io/content-management/image-processing/#the-image-resource

1 Like

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