Error when trying to create content with 'hugo new'

Hi there,

When trying to create a new post in my-site/content/post using the following command ‘hugo new post/first.md’ I’m getting the following error:

ERROR: 2014/10/07 Unable to Cast to map[string]interface{}

I’ve tried issuing the command from various directories within my Hugo site but I get the same error wherever I am. If I move up out of /my-site and run the same command the new content is created without issue (but obviously in the wrong place!)

I have changed the format of my site and config files to use json instead of toml. Could this issue be caused by a malformed config file?

Thanks for any help you might be able to provide

Regards

Dan

Did you create a archetype for posts?

Hugo has a command to generate a skeleton post, just like it does
for sites and themes.

$ hugo --verbose new post/first.md
INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/config.toml
INFO: 2014/09/29 attempting to create  post/first.md of post
INFO: 2014/09/29 curpath: /Users/quoha/Sites/zafta/themes/zafta/archetypes/default.md
ERROR: 2014/09/29 Unable to Cast <nil> to map[string]interface{}

$

The “new” command uses an archetype to create the post file. Hugo
created an empty default archetype file, but that causes an error
when there’s a theme. For me, the workaround was to create an
archetypes file specifically for the post type.

$ vi themes/zafta/archetypes/post.md
+++
Description = ""
Tags = []
Categories = []
+++
:wq

Thank you both for your feedback. It was indeed a lack of an archetype that was causing the problem.

In the tutorial I was following the author creates new content via mkdir instead of using the ‘hugo new’ command. I’m guessing that this was to circumvent the exact problem I outlined above. From here on in I shall follow the tutorials more closely :slight_smile:

I noticed you need an extra line at the end of the file.
If you end with +++ then it gives the same error. Just add another return after that and it should work.

@michael_henderson the workaround you suggest is also present in your excellent tutorial on theme creation in the documentation, which I’m currently reading. Thank you for that.

I think that it would be better fixing the empty default.md archetype, as suggested in the archetype section of the docs. This worked for me.

Can I send feedback on this tutorial based on version 0.14? Do you care for keeping it up-to-date with the latest stable version?

I would appreciate that feedback. An out of date tutorial is almost as bad as no tutorial:)

@michael_henderson I’ve been quite busy and didn’t have the chance to check the whole tutorial, but this is my feedback. I hope it’s useful.

Updates

Warning on missing layouts has improved

Hugo 0.14 can tell which page the layout is for:

WARN: 2015/07/21 Unable to locate layout for homepage: [index.html _default/list.html]
WARN: 2015/07/21 Unable to locate layout for 404 page: [404.html]

Index template

The second sentence here is out-of-date:

The file, layouts/index.html, is used to generate the HTML for the home page. The Hugo documentation says that this is the only required template, but that depends.

Changes

Error: Unable to Cast to map

In this paragraph:

The “new” command uses an archetype to create the post file. Hugo created an empty default archetype file, but that causes an error when there’s a theme. For me, the workaround was to create an archetypes file specifically for the post type.

I’d explain that this error occurs because the archetype available is empty.
And optionally suggest editing the default archetype instead of creating a
new one. Changing the default one is also the approach used with the single
template later on in the tutorial. Even better: show that adding content to the default fixes the error and then suggest using a specific archetype for posts (while the default may be used for normal pages like about).

Partials

Hugo searches for them along a TODO defined search path.

Did you forget removing the TODO?
Or did you mean to add a commented TODO to add some more content in the future?

Lists

In these listings:

find themes -type f | xargs ls -l

I would omit the -l to avoid line breaks and make it more readable, at least
where this option is not needed.

MetaDataFormat

Is this really necessary? It seems redundant as toml is the default:

MetaDataFormat = "toml"

Add an example of section view

You showed how to create a list of page objects in the homepage. I think that also an example of how to list content types in a section would be useful and within the scope of the tutorial (it’s a very common need). This discussion proves that it’s not that easy for a new user.