readDir - assets - GetPage

What I want:

  • storing files in /asstes/data/test
  • readDir /asstes/data/test
  • range with GetPage to every file

How to do it?

Pro: files are only copied if I reference it

OK, I can left it under /static/data …

CON: files are always copied to public

Knowing your purporse would help. But if you’re using GetPage it means those files will be .md and you don’t want to them copied to public.
Though you putting them underneath assets, makes me thing you want to use Hugo Pipes on them… The following solution does not involve any Piping.

I suggest you create a Headless Page Bundle and add those mardkdown files underneath it (as its Page Resources). Those won’t be published, but you will be able to retrieve them as Page Resource of the said headless bundle.

Here’s safe code example:

{{ with (.Site.GetPage "headless-bundle-name") }}
	{{ with .Resources.ByType "page" }}
	<ul>
		{{ range . }}
			<li>Title: {{ .Title}}, whatever: {{ .Params.whatever }}</li>
		{{ end }}
	</ul>
	{{ end }}
{{ end }}
1 Like

I missed that GetPage will work only with markup .md files.

What I will do:

Create a web for documenting a Linux system.

  • In /assets I have a link to /etc
  • range over /etc/apache2/sites-enabled/*.conf etc…

all interesting files are copied into the web htdocs/etc/…
headless is a good point!

@bep
Can we have a frontmatter condition, if a page will be rendered
ex:
render: fileExists "/assets/etc/apache2/"

If there is no apache on this system, no need to generate pages