Can Hugo pick a default title?

Viewed 103

Can pick a default title for existing Markdown files? I'd like to take all of the Markdown files from a git repo and use Hugo to turn it into an internal readthedocs.org-style site. The biggest impediment to this idea I've seen so far is that Markdown files without frontmatter are completely missing a title and the themes I've seen so far don't work well with files that don't have titles.

  1. Is it possible for hugo to figure out that what the title should be from the Markdown content (The # at the top smells like a title.) or the name of the file?
  2. If not, is there a good tool for generating frontmatter?
1 Answers

A few answers:

  1. Templates, i.e.
    in /read-the-docs/single.html or /default/single.html etc. etc. all depending on your look up order. Or if you have a partial for your head, etc. etc. etc.

(Man the Stackoverflow code markdown does not like HTML nested in the Go {{ }})

{{ if .Title }}

    <title>{{ .Title }}</title> 

{{ else }} 

    <title>Read the Docs generic Title</title>

{{ end }}

Note instead of a hard coded 'Read the Docs' you could also findRe a title: {{ findRE "<h2.*?>(.|\n)*?</h2>" .Content 1 }} (this is 100% copied from the docs - docs are good) https://gohugo.io/functions/findre/

You could also {{ .Site.Params.generic_title }} and put that in Params under Config.

  1. Hugo uses something called Archetypes to generate front matter. It's a good tool. Plenty covered in the docs. Pretty simple.

That should give you food for thought methinks.

Related