Empty sub-directories in directory-based archetypes

I’m building a simple archetype for blog posts on my site. The directory structure is straightforward, with an index.md file in the root alongside an images folder that will contain images. I want the images directory to be created empty when I run hugo new --type blogpost but so far it only creates the index.md.

Am I missing something here or is this a bug? Looking at the docs I’d expect this to work.

You can see the current state of the archetype and the generated files in the following picture:

04%20PM

I’m running Hugo v 0.51 on OSX (latest at time of writing).

The example has a file in the images directory. We don’t create empty directories. Maybe we should, but I didn’t think about that use case. Create a GitHub issue and someone will consider it.

That said, if your project is Git-based, you may consider adding a “.gitkeep” to your /images folder, as Git also does not track empty dirs.

That’s a very good point. In the meantime is there a benign file I can put in there to ‘anchor’ it for both git and Hugo?

(The reason I mentioned the docs is because they state “[this] Will create a new folder in /content/post/my-post with the same set of files as in the post-bundle archetypes folder” although I realize reading it now it does say files and not folders.)

As I said, “.gitkeep” seems to be a common empty file to use for this.

Ah! I understand. Thanks for the advice :slight_smile:

@bep

can we activate the ignoreFiles here to create empty sub-directories?

1 Like