I noticed posts without titles do not have proper HTML Title tags on my new Micro.blog.

Even as I type this, I kind of get it. How do you have a title without a title? šŸ¤”

Many services rely on a title element when building links, and seeing “ScottW’s Blog” (or whatever I eventually name this thing) looks silly.

I checked the source for a couple other Micro.blog templates and found none of them did anything special to handle the missing title. Most looked something like this:

1
<title>{{ if not .IsHome }}{{ .Title }} - {{ end }}{{ site.Title }}</title>

After some trial and error, I noticed the .Summary value for the default meta description tag and decided to use that. This is the first ‘code’ I have written in Hugo, so it might need some more tweaking in the future:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  <title>
      {{ if .IsHome }}
        Home
      {{ else if .Title }}
        {{ .Title }}
      {{ else}}
        {{ .Summary }}}
      {{ end }}
      - {{ .Site.Title }}
  </title>