gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
73.79k stars 7.4k forks source link

tpl: Create functions to inspect the union file system #12321

Open jmooring opened 3 months ago

jmooring commented 3 months ago

Reference: https://discourse.gohugo.io/t/methods-to-traverse-the-virtual-filesystem/49058/

{{ ufs.ReadDir }}
{{ ufs.FileExists }}

Why not just modify os.ReadDir and os.FileExists?

  1. We wouldn't have to worry about breaking existing sites
  2. We're not inspecting the OS file system; we're inspecting the union file system
bep commented 3 months ago

{{ ufs.ReadDir }}

Maybe fs.ReadDir would mke more sense -- it's not likely we're going to invent another file system.

There are some potential suprises, though, which we need to think about before doing this. This is component dependant, but e.g. doing fs.ReadDir "content/posts" may return multiple files with the same name (with different languages). Also, the behaviour of these are very much tied to "what Hugo needs", which may change.

So we can add fs.FileExists, but we need to think about the ReadDir.

cmahnke commented 3 months ago

See also #11917