#Hugo

Making use of Webmentions

In which we finish with Webmentions for the time being by massaging a flat list of mentions into a two-level hash table/JSON object that’s easy to make use of in Hugo.

And speculate about how we could improve things further, because things can always be improved.

  • 1 like
  • 0 reposts
  • 0 replies
  • 1 mention

Written by Piers Cawley , updated

Read more…

@07:51

Progress!

Before:

./data/mentions/3f256ff[...]494.json
./data/mentions/62afe34[...]020.json
...

Hmm, so which file pertains to which post?

{{ $slug := .RelPermalink | sha256 }}
{{ $all_mentions := index site.Data.mentions $slug | default slice }}
{{ $likes := where $all_mentions "wm-property" "like-of" }}

At least the template code to get at it is more or less sane.

During:

./data/mentions/note/8/mentions.json
./data/mentions/note/9/mentions.json

Well, that’s clear as day!

{{ $key := (split path.Dir .RelPermalink) "/" | after 1 | append "mentions" }}
{{ $all_mentions := index site.Data.mentions $key | default slice }}
{{ $likes := where $all_mentions "wm-property" "like-of" }}

What the actual fuck? I want to write {{ index site.Data.mentions .RelPermalink }} and have done with it. To the data mungery!

Now

./data/mentions/all.json

That’s a tad more opaque, isn’t it? Ah well, there’s always jq. I can’t see what’s got new mentions from git status any more, but also, I can’t forget to add any new data files either. Call it a win on aggregate.

{{ $all_mentions = index site.Data.mentions.all .RelPermalink | default dict }}
{{ $likes := index $all_mentions "like-of" | default slice }}

Well structured data for the win! And I’m working on eliminating the annoying default dict and default slice in that too.

  • 1 like
  • 0 reposts
  • 0 replies
  • 2 mentions

Adding a generic oembed handler for Hugo

If you’re at all like me, you have content on a bunch of different sites (Instagram, Youtube, Flickr, Soundcloud, Bandcamp…) and, especially for multimedia content, it’s great to be able to link to ’live’ versions of that content. Of course, all those sites will let you ‘share’ content and usually have an ’embed’ option that hands you a bunch of HTML that you can paste into your blog entry. But screw that! I’m a programmer for whom laziness is one of the cardinal virtues – if it’s at all possible, I prefer to let the computer do the work for me.

If nothing else, once I’ve got the programming right, it’s less likely to screw up than me

Hugo1 sort of supports this out of the box with its youtube, instagram, vimeo etc. built in shortcodes. The thing is, they’re not lazy enough – you have to dig into each URL to extract a content ID and pass that in to {{% youtube kb-Aq6S4QZQ %}} or whatever. Which would be kind of fine, if you weren’t used to the way sites like Facebook, Twitter, Tumblr and so on work. With those sites, you enter a URL and they disappear off behind the scenes and fill in a fancy preview of the page you linked to. Why can’t Hugo do that?

  • 0 likes
  • 0 reposts
  • 1 reply
  • 2 mentions

Written by Piers Cawley , updated

Read more…