How to resources.Copy entire directory with its content

I want to copy entire folder on build.

/assets/img/favicon into /img/favicon(in static folder)

This code give error:

{{- range resources.Match "img/favicon/*.*" -}}{{ $src := . }}{{- (resources.Get $src | resources.Copy "img/favicon/$src").Publish -}}{{ end -}}

Why don’t you just put your favicons in static? That directory gets copied automagically on build.

And please: Don’t tell us just that you get an error; post the error as well.

  • $src := . : here $src is already assigned a Resource
  • resources.Get $src this is superflouus, cause $src is a resource. In fact you are lucky, cause hugo here does an implicit conversion of Resource to String so it will just reload the same resource
  • "img/favicon/$src" there’s no variable interpolation in Strings with Go templates → it results in a literal $src in the string.
  • No need to Copy and Publish - whatever you tried there

Simplify to :

{{ range resources.Match "img/favicon/*" }}  <- use ** for recursive copy
  {{ .Publish }}
{{ end }}

p.s. this looks like plugging together some code snippets. On the long run you won’t get lucky without a deeper understanding of the template language