Episode 15 – micro.blog()


After a gap of over a year, we resumed our IndieWeb podcast and got together to discuss what has been going on, how we have been building the community during the pandemic, and about our topic of micro.blog. There is also a video attached this time.

 

Micropub 2.2.3 for WordPress has been released. It fixes a variety of warning notices.  Published, updated, name, and summary properties are no longer stored in post meta. When queried, they will be pulled from the equivalent WordPress properties. Content should be as well, however as content in the post includes rendered microformats we need to store the pure version. Might address this in a future version. As timezone is not stored in the WordPress timestamp, store the timezone offset for the post in meta instead of the full published and updated date. It will also sideload and set featured images if featured property is set. Note: Version 8.9 of JetPack apparently breaks this plugin. This is under investigation.
I bumped up a little plugin for my site that generates rewrite URLs for avatar images. So if you visit /avatar/username you get redirected to the avatar for that username. You can add ?s=250 to pass the size to the other side. This is the same query used by Gravatar. Right now, this calls the gravatar URL and does a temporary redirect to it, setting cache control headers to save the redirect. This means that there could be up to two http queries per avatar image. In a future version, I might actually serve the avatar locally. I got tired of broken URLs for my image. Now, the same link will always produce my image.

Post Kinds 3.4.0 Released

Post Kinds 3.4.0 was released. If I broke your site, I’m sorry. Please tell me so I can fix it. I tried to cover everything, but I wrote a lot of the storage code and will have to continue to do so in preparation for the next iteration at some point in the future.

A lot of the code focused on fixing the storage and display of media. Whenever you save a post, your content is searched for image, video, and audio tags. If there are any, it will ignore anything in these properties sent by Micropub or saved otherwise. If it finds none, it will. This should hopefully reduce duplicate displays.

Shortly after 3.4.0 went out, I found another bug, so quickly released 3.4.1. If additional bugs are found, I’ll quickly iterate.

Converting Your WordPress Theme for Microformats 2 Part 2

Okay, so four years after I wrote how to start Converting Your WordPress Theme for Microformats 2, I’m back with Part 2.

First, four years later, we need to recap, update, and expand what we discussed last time.

Before you start, you need to clean up two very simple things.

  •  Don’t style any Microformats Classes. WordPress commonly supports classic microformats. WordPress actually adds hentry, the predecessor to h-entry, into every single post in the post_class filter. So, you want to be able to supplement, replace, or fix Microformats classes without changing the look of your theme. So if you are updating a theme that already does this, add a styling class and change your CSS to do that. For example, I add entry alongside hentry and rewrite all the CSS to style entry, then I can take hentry out where it shouldn’t be.
  • Someone years ago decided to add hfeed to the header file of their theme and everyone copied it. hfeed indicates a page is a feed…which means it contains multiple entries(date archive, author archive, main posts page, etc). This should therefore not appear on a single page…so if it does, take it out.

Where do you start?

Add h-entry and h-feed in the proper places. See Part 1 for some sample code on how to do that using the body_class and post_class filters. You could also add it manually by surrounding your post, class="h-entry", and surrounding all the posts in an archive/feed page with an element that has class="h-feed" Congratulations, you’ve now marked up your posts as posts and your feeds as feeds.

Now that we’ve marked up feeds and posts, we want to get down deeper…namely, inside your posts. We want to mark up things like author, publish date, etc.

In most themes, time is already marked up, something like this, with an HTML5 time element. The full time is present in ISO8601 format, with the timezone offset for your site, and inside the tag is the human readable one.

<time datetime="2016-06-22T23:52:09-04:00">June 22, 2016</time>

You get two times per post..the published time and the updated time.  Many themes have the updated time visually hidden, but available for parsing. If you do not have a fully formatted timestamp in datetime, you should do so. Positively, since WordPress 5.3, the offset is properly set based on your site settings, where previously you had to edit the theme to get this. The displayed time is up to you.

Add class="dt-published" to the publish time of the post, and class="dt-updated" to the updated/modified time of the post.

We also, most importantly, want to make sure the author is marked up correctly. That should include, at minimum, the author’s name, if not URL and photo. All author properties should be surrounded by an element that has class="p-author h-card". The photo should have class="u-photo", indicating it is a representative photo of the element it is inside…the h-card. H-cards represent people, organizations, or places. By adding the p-author, we indicate that this person is the author of the piece. The p- tells the parser that whatever text is inside here is the value of the author property. You can also add a url for the author website, marking it class="u-url" which states it is the URL that represents the containing element…the h-card/author property.

Here is a simplified example of what this might look like…

<div class="h-entry">
<time class="dt-published" datetime="2016-06-22T23:52:09-04:00">June 22, 2016</time>
<span class="p-author h-card"><a class="u-url" href="https://joebloggs.com">Joe Bloggs</a><img class="u-photo" src="https://joebloggs.com/avatar.jpg" /></span>
</div>

So, if we run the new file through a Microformats parser(I like php.microformats.io), we’d get a nice output…

{
   "type": [
     "h-entry"
    ],
   "properties": {
     "url": [
       "https://joebloggs.com"
     ],
     "published": [
       "2016-06-22T23:52:09-04:00"
     ],
     "author": [
       {
         "type": [
           "h-card"
         ],
         "properties": {
           "photo": [
             "https://joebloggs.com/avatar.jpg"
           ],
           "name": [
             "Joe Bloggs"
           ]
         },
         "value": "Joe Bloggs"
         }
     ]
  }
}

Looks pretty good…except no content… Content is a bit more complicated, because WordPress stores content in the database, but when outputting it, puts it through a filter called “the_content”, which many plugins use to add things that aren’t content to the post.

Content is supposed to be wrapped in an element with the class="e-content". If we wrap the output of the_content, we might incorporate things from other plugins.

While it is by no means the most reliable way, my solution is to use the same content filter, but at the first priority, wrapping what original came out of post_content before all the other items.

You can do the same with the summary, if it exists, wrapping it in p-summary.

function add_econtent( $content ) {
  // Do Not Add this is it is a Feed.
  if ( is_feed() ) {
    return $content;
  }
  $wrap = '<div class="e-content">';
  // If there is no content, do not bother.
  if ( empty( $content ) ) {
    return $content;
  }
  return $wrap . $content . '</div>';
}
add_filter( 'the_content', 'add_econtent', 1 ); 

function add_psummary( $excerpt ) {
  // Do Not Add this is it is a Feed.
  if ( is_feed() ) {
    return $excerpt;
  }
  $wrap = '<div class="p-summary">';
  // If there is no excerpt, do not bother.
  if ( empty( $excerpt ) ) {
    return $excerpt;
  }
  return $wrap . $excerpt . '</div>';
}
add_filter( 'the_excerpt', 'add_psummary', 1 );

In the next part, we’ll dive even more into the weeds, talking about other classic microformats and rel-values and what to do with them. Probably before 2024.

Tonight begins Yom Kippur, and for the first time in my life, I will not be at services. There was no option, due to lack of committed individuals and rain, for an outdoor service, and I’m still uncomfortable with the way they are not distancing inside. So I will be fasting and praying at home. There is a very different feel to solo prayer than group prayer and Yom Kippur feels different than praying at home alone on Passover, which I also did. I am pleased that we were able to get services outside available for Rosh Hashanah. If Rosh Hashanah is, akin to a trial, the verdict, Yom Kippur is the final appeal before the sentence is carried out for the next year. In a year that included so many difficult things, and the challenges of the current situation the world finds itself in…most of us cannot imagine this continuing till next Yom Kippur. Here is hoping things will look better soon.