Custom Front Matter

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.

I still post my long articles to my Micro.blog hosted blog. I just don’t automatically include them in the Micro.blog timeline. I write custom short notes instead. For example, this long blog post was promoted on the timeline by this short post.

Alright, alright, I got all excited but now I’m stuck. How/where do I tell Micro.blog to display the summary?

I changed the index.json template so that the “content_html” is the summary, not the full content.

But that doesn’t show in the timeline, it still just shows the title and link.

My “Edit Sources” is pulling from feed.json

Can you point me at what template or part of this template I need to change in order to have the summary and the link show up in the timeline?

You might have stumbled upon a race condition. When making a change to a template, it sometimes takes a while before Micro.blog rebuilds your site.

It could be that when Micro.blog added your test post to the timeline, the JSON feed was still the old version (with the full post). Try removing the latest post from the timeline (just from the timeline, not the actual post), and then try refetching the feed by navigating to the feeds page (linked above) and hitting the :arrows_counterclockwise: button.

Also, it’s worth noting that the changes you make to the feed only affect future posts. Posts that are already on the timeline will remain the same (unless you explicitly remove them to be re-added, but then you probably lose their comments).

Oh, sorry! You should remove the title from the feed as well. :blush: That’s what’s triggering Micro.blog to just link to the post. More about timeline display rules.

Hmmm. Removing the title does show the summary, but no link back to the post.

Ah. So I’ve removed the title, and made “content_html” be the summary - however, this summary is not 300 characters, so it’s just being displayed as-is without a link. But if I make a summary that is longer than 300 characters, it’ll just be truncated, too.

This just isn’t very feasible, I don’t think. Not for my use case, anyway.

So I’ll just go back to my feature request: the ability to specify how long posts are displayed, whether with the title+link or the title+summary+link (or even just summary+link, while we’re at it).

Oooh, weirdly, the timeline posts did change retroactively! I just deleted my custom index.json template, and now they appear like this

You could add a link to the post in your feed template. But you’re right about the 300-character limit. If the summary + link text are longer than 300 characters, Micro.blog will truncate. Unless you make it a quote, then you get 600 characters, but that’s kind of a hack. :blush:

And even if you get your feature request realized, I would be very surprised if @manton would allow arbitrary long summaries. They would probably still be truncated if they were longer than 300 characters.

I don’t need them to be longer than 300 characters, so that’s fine by me!

Well, then you’re almost there with your custom feed template; add the post’s title and link to content_html. And as long as you make sure that the title, link text, and summary are less than 300 characters total (or 600 with the quote hack), you will get what you want.

Cool about the updated timeline! That’s more than I knew about.

@sod Would the link characters also count in the 300-character limit if done this way? If it is hyperlinked to “Read More,” then that’s fewer characters, no?

Ok, I know next to nothing about json formatting, but I’m assuming I need some sort escaping or somesuch for the html elements here. Can you help with that?

"content_html": <a href="{{ .Permalink }}">{{ .Title }}</a> {{ $s }},

($s is the summary)

My impression is that you know quite a lot. :blush: This should do it:

"content_html": "<a href=\"{{ .Permalink }}\">{{ .Title }}</a> {{ $s }}",

Yes, the link text would count against the 300 characters.

Oh. my. goodness. I have been at this for hours, but I think I’ve finally got it.

Your code didn’t work - it kept sticking in weird extra quote marks and <p> elements and was just generally being disagreeable.

I kept digging through docs, figuring I might need to build the whole string before sticking it in the “content_html” line.

String concatenation in Hugo, is, uh, pretty arcane, as best as I can see. So this is the final result. It lives in the index.json template, and for truncated posts (those with a <!--more--> tag), it shows the summary/excerpt and then a link to read more. For other posts, it follows the standard rules.

{{- if .Truncated -}}
  {{- $tt := .Title -}}
  {{- $sm := .Summary -}}
  {{- $lk := .Permalink -}}
  {{- $lkb := " Read more: <a href='" -}}
  {{- $lke := "' >" -}}
  {{- $lkc := "</a> " -}}
  {{- $tp := printf "%s" $lkc | printf "%s%s" $tt | printf "%s%s" $lke | printf "%s%s" $lk | printf "%s%s" $lkb | printf "%s%s" $sm | printf "%s" -}}
  {{- $tp := $tp | jsonify -}}
  {{- $tp := replace $tp "\\u003c" "<" -}}
  {{- $tp := replace $tp "\\u003e" ">" -}}
  {{- $tp := replace $tp "\\u0026" "&" }}
  "content_html": {{ $tp }},
{{- else -}}
  {{- $tp := .Content -}}
  {{- $tp := $tp | jsonify -}}
  {{- $tp := replace $tp "\\u003c" "<" -}}
  {{- $tp := replace $tp "\\u003e" ">" -}}
  {{- $tp := replace $tp "\\u0026" "&" }}
  "content_html": {{ $tp }},
{{- end -}}

I’m sure there’s a more elegant way to do this, but outside of the crazy printf incantation, it’s at least fairly clear what it’s doing.

1 Like