HUGO

Posts without frontmatter?

I have a large repository with markdown files that I would like to serve with hugo. It seems like plain markdown files will not render unless they have frontmatter at the top. I would like to not have to add this front matter to all of the files to make them browsable. Is there a way to provide or make hugo autodetect front matter based on the file?

I had the same problem a while back and ended up using Franklin which is based on Middleman.

If anybody has a solution for Hugo I would be interested to learn more.

frontmatter should be placed in a separate file, and then merge it in line with other files. This can be done with the script, but the script depends on the operating system.

http://www.heatware.net/linux-unix/insert-add-string-to-beginning-top-of-file/

Have you looked into Pandoc. I’m not sure if Hugo will provide as much of an advantage without front matter, which gives you a lot of flexibility as key-value pairs. For example, how else are you going to generate your title, meta tags, description, publish date, etc if you have nothing but markdown?

Easy:

  • Title: the “# title” in the markdown, of course
  • Meta tags: filename components, but not necessary anyway
  • Description: a truncated extract or the first paragraph, like CMSs do
  • Date: filename component

In other words, front matter may be entirely superfluous for a file called 2020-06-01-forest-trees-asia.md which begins with the markdown title “# Forest trees of Asia” and a descriptive intro paragraph.

The right solution is surely some kind of global front matter template with variable substitution. Surprising this does not already exist.

Or does it?

1 Like

@Friptick, you raise many good point :smile:

In the context of a rapidly evolving product like Hugo, I think it’s fair to assume that the advice I gave four years ago is no longer up to date…

That said, can you expand on the following:

The right solution is surely some kind of global front matter template with variable substitution. Surprising this does not already exist.

Are you talking about archetypes?

As an aside, keeping all your metadata in a filename can have negative consequences. For example, “description” and “lead paragraph” are not always the same thing, although you can do what you’re asking for in Hugo as well.