Custom Front Matter

I think being able to specify front-matter for Hugo would solve many of the challenges I’ve been running in to setting this up. I got to thinking about how to do that.

I’d like to suggest and request that the Micropub endpoint add any unknown/unexpected properties as front-matter.

For example, curl -L 'https://micro.blog/micropub' -H "Authorization: $MICROPUB" -d 'h=entry' -d 'snarf=mongler' -d 'content=Scruffy looking nerf herder!' should add to the front matter for Hugo snarf: mongler as a custom property.

The Micropub specification already expressly contemplates using and accepting unknown vocabulary, so I think this would be well within the spirit of the spec.

Thanks!

1 Like

That’s an interesting idea… One of the reasons we haven’t added custom front matter yet is I’m not sure where to put it in the UI, so supporting it via Micropub would solve that, keeping the main interface simple for now.

3 Likes

Support for custom front matter from Micropub would very elegantly solve a feature I’m planning for my blog.

My current prototype uses <data> elements in the note content. It works fine but it requires me to use regex to parse the data from the posts. By putting the data into the front matter it would be queryable by Hugo which would simplify my code considerably. :blush:

3 Likes

I would be super appreciative of frontmatter-by-custom-header-Micropub before you figure out the UX.

Alsö, keeping my original post without preprocessing

1 Like

I would also love to have some frontmatter variables for Hugo as well. My use case is around excerpts - I want to be able to write an excerpt that shows when a post is in a list/archive page, but does not show on the single post page. I can see that Hugo has a variable for that purpose (“summary”) - would love to have that implemented.

As for UI, what about something simple like Obsidian and many others use: just — to start and — to end the frontmatter section at the beginning of the post? Or maybe just another text block, like you do for the title?

1 Like

Thinking about this some more, another text field is probably the way to go. Maybe there’s a new “Add Custom Field” menu option to enable it. That way Micro.blog can more easily keep track of any custom fields for you.

Something like this has been a requested feature for a long time. I’ll try to work on it soon.

4 Likes

I think there are some common Hugo ones that you should be able to include— summary comes top of mine, but also possibly (ducks) types?

But otherwise I actually think the format from plugins for plugin settings is awesome and I can see that being the maximum flexibility— essentially reuse the custom forms you get for a plugin using a config file to let people design a custom config file that gives them that form per post online. Then support over API is a json blob that fits.

Would that not preclude the ability to declare these things when posting via third party app, though?

I still think it would be awesome to have some custom field availability, but I did find a solution to my specific use case. I’ll put the template stuff below, in case anyone comes here via search and needs a quick fix.

What this does: If you write a bespoke excerpt, and end it with the <!--more--> tag, the excerpt will not appear wherever you use the following template code. Only the rest of the body of your post will appear. If you don’t use the <!--more--> tag (and allow the system to truncate your post automatically), the whole post will appear as normal.

{{ if .Truncated }}
	{{ $body := replace .Content .Summary "" }}
	{{ $body | safeHTML }}
{{ else }}
	{{ .Content }}
{{ end }}
4 Likes

Nice, that’s a smart hack! :blush:

1 Like

I think I understand this, but can you point to a post of yours where you have used the bespoke excerpt and show how it displays vs how it appears in your editor?

Sure!

Here’s the post in the editor:

Here’s how it appears on a list page (only the excerpt appears):

Here’s how it appears on an article (single) page (only the body, not the excerpt appears):

If you just write a long post, without using the <!--more--> tag, the auto-generated excerpt will show in lists, and the whole post will appear on the article page. (Just like normal.)

One more note about the template code above: this code goes in your “article.html” partial. In your “list.html” partial, you’d just use {{ .Summary }}.

In my own personal style, I like the excerpt/summary to actually be a summary or précis, not just the first paragraph of the post. So this accomplishes that - I can write a summary that appears in lists, but that doesn’t appear on the post page.

PS. This post is here: It's a Test! // graphic content , but I don’t know how long I’ll leave it live on the site, because, ya know, it’s a test.

1 Like

Wow! This is great and how I was envisioning it. Thanks for the screenshots. I agree about the summary.

BTW, will the summary also appear that way in the Micro.blog timeline?

No, it just shows the title and link in the timeline.

I was actually just looking for a place to make a feature request on this: I would love a setting so I can choose whether to show title+summary+link or title+link in the timeline.

Dang it! I thought we finally had a hack for the timeline display for macro posts :smile:

BTW here’s a long thread just for feature requests. But no idea if @manton keeps an eye on it.

Yep, I read everything! I don’t usually comment just because discussions are difficult in a long thread like that.

2 Likes

No worries. As long as you read and are aware of the requests :smile:

This is achievable if you’re comfortable modifying templates, which you’ve already proven you are. :blush: What shows up on the Micro.blog timeline is controlled by the feed or feeds you’ve added to the Edit Sources & Cross-posting page. And you are in full control of the presentation of the RSS (and JSON) feeds by overriding their templates in your custom theme.

And for people who don’t want to tinker with custom themes (@pratik, maybe?), an alternative is to be more selective about what gets sent to the Micro.blog timeline. I, for example, only include short posts in my Micro.blog timeline. No long articles with headlines.

So, when I post a long article to my blog, I also write an accompanying short note where I summarize and link to the long article. Only the short note go to the Micro.blog timeline.

Instead of having the main feed (/feed.xml) included on my Micro.blog timeline, I’ve pointed it to the feed for the notes’ category (/categories/notes/feed.xml).

2 Likes

:star_struck: Cooooooool - thanks for that. I didn’t realize I could change that on my own!

Well, I do have a custom theme but have never dabbled with modifying the main feed template. However, I hate to be selectively about what I post. I do post both long and short posts here on Micro.blog. I tried the posting-the-long-ones elsewhere and adding its RSS link but too much friction in deciding.