In Hugo Themes Dont’s, it’s said that
readDir
orreadFile
are not really meant for themes that are supposed to be usable under various hosts and various situations.
Lacking experience in web hosting, I’ve having difficulties in understanding this. Maybe it’s due to file I/O errors caused by Linux’s file permissions?
To understand this, let’s use the Minimo theme as an example. The link shows two places where readFile
is used. One of them is to read parameters from a root-level YML config file named staticman.yml
.
# layouts/partials/comments/staticman/GetStaticmanYML.html
{{ $rawStaticmanYML := ( readFile "staticman.yml" ) }}
{{ $parsedStaticmanYML := ( transform.Unmarshal $rawStaticmanYML ) }}
{{ return $parsedStaticmanYML }}
# layouts/partials/comments/staticman/form.html
{{- $staticman := ( partialCached "comments/staticman/GetStaticmanYML" . ) -}}
{{- $reCaptcha := $staticman.comments.reCaptcha | default ( dict "enabled" false ) -}}
...
{{- if $reCaptcha.enabled -}}
<input type='hidden' name='options[reCaptcha][siteKey]' value='{{ $reCaptcha.siteKey }}'>
<input type='hidden' name='options[reCaptcha][secret]' value='{{ $reCaptcha.secret }}'>
{{- end -}}
Can @alexandros’s advice above be applied to this theme?
P.S. In this theme, Hugo uses the paramters in the YML config file for reCAPTCHA v2.