I am trying to create a SCORM manifest XML file, which essentially lists all the files (html + assets) by section. Note that these have to include the actual filename (not permalink).
I managed to set up a custom output format, and it’s generating fine. But I’ve stumbled on the file listing part. Essentially, I need to run readDir on my publishDir so I can list the files as they are published, and not on the folder containing source files.
When I run:
{{ range (readDir "/") }}
{{ .Name }}
{{ end }}
I get the project folders (assets, config, content, data, layouts, resources, static). So the contents of my site folder. I’d like to run:
{{ range (readDir "../build/") }}
{{ .Name }}
{{ end }}
But that errors out:
execute of template failed: template: _default/section.imsmanifest.xml:47:26: executing “_default/section.imsmanifest.xml” at <readDir “…/build”>: error calling readDir: failed to read directory “…/build”: open …/build: file does not exist
Is what I’m trying to do possible? Or should I suck it up and do it in webpack. (I’m using victor-hugo, so node is already part of the stack).
You cannot use readDir/readFile outside of the project folder (due to security reasons; we kind of trust you to do the right thing, but any {{ readFile "/etc/passwd" }} from a random theme would not be too … great.
You can, however, build to a folder below your project (which is a common thing to do). But you will end up with some chicken and egg problems.
So that confirms my suspicion. It’s making more and more sense then to use node. (And that will let me compress the files as well. Just kinda frustrating that I’m setting up all my string variables for Hugo, and then need to somehow reuse them in the node env.