Adding the equivalent of Hugo's `new` command

I could have sworn there was already a thread on this topic, but I cannot find it for the life of me so I’m opening this one again. Sorry if this is a duplicate.

I personally really liked Hugo’s command new and kinda missed it in Zola. Espeically because I personally have a lot of sections that have a very specific structure but also the index.md file has specific tags so having something to copy all of that easily is a big plus for me, though I admit it’s just a creature comfort thing.

The specific use case for me right now is making new publications. Every time I make a new publication it gets its own section for asset colocation, and has a bunch of fields like abstract, authors,pdf,bibfile,venue. Additionally it also has a sub folder called images for images about that publication.

I’ve added an archetypes folder, after Hugo’s function of the same name. This folder must at least contain a file called default.md, which at the moment just looks like this:

---
title = "%TITLE%"
date = %ISODATE%
draft = true
---

Right now I have an implementation that works like this:

  • zola new temp-file-with-title.md will copy archetypes/default.md over to content/temp.md and change it’s title to Temp file with title and the date to the current local ISO date.
  • zola new type/subtype/specific-title.md will look to use the file archetypes/type/subtype/default.md as a template
    • if it finds it it will do the same as before. if archetypes/type/subtype/ contains other files or folders those get recursively copied over to the target directory without modification.
    • if it does not find it, it will still create the file along with the folders if necessary but use archetypes/default.md as a template
  • if content/type/subtype/specific-title.md already exists, then zola new type/subtype/specific-title.md will do nothing

So far the implementation has tests for the most important functionality, but I don’t have coverage stats at the moment. I will be adding some documentation on it in the next few days if possible. The template functions that it supports are very simple atm but I figured it was a good enough start. Can I submit a PR with this?

1 Like

That’s a cool addition!

Question though, if an archetype is not found would it be safer to not create the file and explain why? At least a warning would be appropriate. For instance what if there was a typo, then someone gets the default archetype when they really did have some custom archetype? That could be confusing.

if it uses the default archetype because the provided one can’t be found it does show a warning, but you might be right that at that point it’s better to do nothing. It’s hard to say why the archetype couldn’t be found though

There won’t be a zola new for the foreseeable future because I don’t want to add the concept of archetypes and it’s just simpler to copy an existing file.

To bad that you’re not open to the idea. If anyone else is interested in this feature I plan to keep it up to date for a while on my fork.

1 Like