Essays on self-improvement, software development, and esports.
© 2022. All rights reserved.
Getting Bridgy and Jekyll to work together took a little more effort than I expected.
Since it looks like Twitter isn’t going to instantly suspend my account again, I can try to get Bridgy set up to publish my posts there.
Bridgy is a POSEE service. Once you have an account set up there, it will monitor Twitter (and several other social sites) for posts that link to your content, and turn them into webmentions. It also works the other way – if I make a new post here, Bridgy will tweet it for my on my Twitter account.
This blog is built with Jekyll, and Jekyll posts have an excerpt attribute. By default, the excerpt is just the first paragraph, although I found that too restrictive so I manually specify a divider in each post I compose. The excerpt is the little snippet of text you see on the index page, before the “Read More” link.
Bridgy, when it publishes a tweet for you, computes its own snippet, but it’s looking for microformats. Specifically, it wants an h-entry and a p-summary which it will then tweet for you. If it doesn’t find those, it just uses the first 120 characters or so, which looks ugly.
I don’t want to type microformats into every post. Ideally, the blog should just convert the Jekyll except into the appropriate microformat. I can add h-entry into the template, since that will wrap every blog post. But the p-summary has to be computed separately for each new post.
Jekyll has hooks which are meant precisely for use-cases like this. In fact if you look at that documentation page you’ll see at the end how they make an excerpt hook, which is exactly what I need. But it seems that was only added in version 4.2.0 for Jekyll, and right now I’m locked at 3.9 because that’s what the jekyll-webmention_io plugin specifies. I could see if I can change that, but I already have a pull request in for that gem and I don’t want to flood the maintainer.
Instead I’m using the
post-render hook and it looks like this
Jekyll::Hooks.register :posts, :post_render do |post, output| excerpt = post.data['excerpt'].output wrapped_excerpt = '<div class="p-summary">' + excerpt + '</div>' post.output.sub!(excerpt, wrapped_excerpt) end
This goes into its own
microformat.rb file in
_plugins. That won’t work if you’re using GitHub Pages, since GitHub doesn’t allow custom code, but I abandoned GitHub Pages very quickly when I found that out.
This is some ugly code. Doing search-and-replace on HTML is fraught. Ideally I’d like to modify the except before it gets rendered to HTML, and there’s supposedly a hook for that,
pre-render. But when I tried it I found somewhat confusingly that the page had already been rendered and changing my except didn’t do anything. So I’m going to leave it like this and call it a day. It seems to work, and Bridgy is posting nice snippets automatically for me.