With this content file:
/home/user/project/content/en/about.md
{{ .File.Filename }}
returns:
/home/user/project/content/en/about.md
But what I really really want is:
/content/en/about.md
If I add PWD
to security.funcs.getenv
I can do this:
{{ strings.TrimPrefix (os.Getenv "PWD") .File.Filename }}
But this approach is somewhat fragile (e.g., executing hugo from another dir with hugo -s something
).
Running hugo config
(with or without a -s
flag) shows:
workingdir = "/home/user/project"
So we have access to the value to trim, somewhere.
Justification: avoid hardcoding contentDir
when interacting with GitHub, GitLab, etc. For example: