Linkblog + Microblog in Hugo

About two weeks ago now I moved this site to Hugo, and I’ve been slowly working on re-adding the features my old Middleman blog had here, including the linkblogging and microblogging capabilities. Here’s the code for anyone interested:

For index.html

{{ range first 30 .Data.Pages }}
{{ if .Params.link}}
<h2><a href="{{ .Params.link }}">{{ .Title }}</a></h2>
<small>{{ .Date.Format "2 of January, 2006" }} | <a href="{{ .Permalink }}">♠</a> </small>

{{ else if not .Title }}
<small class="micro"> <a href="{{ .Permalink }}">{{ .Date.Format "2 of January, 2006" }}</a></small>

{{ else }}
<h2 class="non-link"><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
<small>{{ .Date.Format "2 of January, 2006" }} </small>
{{ end }}
{{ .Content }}
<hr style="margin-left:calc(20%); margin-right:calc(20%); ">
{{ end }}

For single.html

{{ if .Params.link }}
<h2><a href="{{ .Params.link }}">{{ .Title }}</a></h2>
{{ else }}
<h2 class="non-link">{{ .Title }}</h2>
{{ end }}
{{ if .Params.page }}
{{ else }}
<small>{{ .Date.Format "2 of January, 2006" }}</small>
{{ end }}
{{ .Content }}

To use, we obviously need to do some stuff in the front matter of a post. I use YAML, but it shouldn’t be too hard to convert to TOML.

For a link post:

--- 
title: This is a link post date:
2016-08-17T22:13:00
link: https://valiantghost.com
---

For a microblog post:

--- 
date: 2016-08-17T22:13:00
url: /2016/09/159 #So, the URL. I can't figure out how to get Hugo to link straight to the blog post itself, instead of the most recent one this month. So you need to manually enter the URL until I figure out how to fix it. The URL can be whatever you want, this is just how I style them.
---

Leave a comment if you need any help. I’d be more than happy to help.

Leave a Reply