Excursions avatar

Dev

Paper Theme Now Supports Full Posts on Homepage

I have released an upgrade (v1.1) to Paper theme for Micro.blog today that allows modifying the default behaviour of the homepage. It includes a setting now to display full post content on the homepage of the blog. Here’s how the homepage with this setting on will look like. You can also check the same on my test blog.

Paper Theme 1.1.

This is one of the most asked for features since the first release. I could never get the look right without ruining the spirit of the theme. Or so I like to believe because the change isn’t too significant in itself. So, irrespective of which option you decide to go with, the homepage should feel as part of the original simple and clean theme.

If you are using the Paper theme, look out for the upgrade option in Plugins. It should be enabled soon. As always, if you find any bug or want any improvements, kindly let me know either as GitHub issue or connect with me on Micro.blog / via email.

Porting Hugo theme to Micro.blog

Micro.blog is a blogging platform built over Hugo, a fast static site engine. Given the way it is structured, every theme created for Hugo can potentially work with the blog hosted by Micro.blog. However, there are a few aspects added to Hugo that are specific to the way things work in Micro.blog. These need to be included as part of the themes to make the most of the features of this platform.

This article presents a non-extensive list of things that should be evaluated and included while porting a theme that is made for Hugo to Micro.blog. I have written this as I dug into the existing themes while porting Paper theme. As of this writing, a theme is considered as a plug-in in Micro.blog. Hence, many references link back to the way plug-ins work with the platform.

To reiterate, this is not an extensive list. Based on how a theme, that is being ported, is set up, one may need only a few of these steps or may need a few more than those listed below. However, this should be a good start to get a working version of the theme out for testing. If there are any issues or concerns, please reply to our email addresses.

Pre-requisites

Of course, the article assumes that you have already identified the theme that you want to port. The Hugo theme Showcase is a good place to check for all the wonderful themes available.

Though you are not required to have a detailed understanding of Hugo to port a theme, the knowledge on the below aspects should be handy.

Getting Started

The first step to get started is to access and clone the repository of the theme to be ported. You can either do this offline on your desktop or directly create a new theme in Micro.blog with mentioning the theme repository URL as Clone URL. You could then select this newly added theme as a custom theme for your test blog. This allows you to find out what breaks and also validate the additional modifications that you make to the theme.

For a theme to work, you only need a few folders and files — a typical Micro.blog theme directory structure is provided below for reference.

.
├── theme.toml
├── config.json
├── plugin.json
├── layouts
└── static
  • theme.toml - Contains bare meta information about the theme, like name, description, license, features, author.
  • config.json - Contains any properties required and referenced by the template files of the theme. If the property is to be provided by the user, typically it should be taken as a setting, defined in a separate file.
  • plugin.json - Contains meta information about the custom theme to be displayed as part of plugin repository. It also defines the feature settings that can be provided by user while plugin configuration. Refer to official guide on plug-ins for more details about this file.
  • layouts - A folder that stores html templates that defines how views of different content types will be rendered on a website with the style.
  • static - A folder that stores all the static content like CSS, JavaScript, etc.

You can get rid of all the other unnecessary files and folders and only keep the above-mentioned ones. This will keep the list of files in which changes are to be made manageable.

Before we move ahead, here’s a list of basic template files in the layouts folders that one would modify typically to port a theme.

  • /_default/list.html - A template that renders pages with multiple pieces of content, this includes the homepage. A homepage can also be independently styled by defining a template index.html in the root directory.
  • /_default/single.html or posts/single.html - A template that renders a page for a single post.
  • /_default/list.archivehtml.html - A template that renders the archive page of your website.
  • /partials/head.html - A template that defines the head section of your final rendered HTML.
  • /partials/header.html - A template that defines the header of your blog. This typically includes the site title, subtitle, navigation menu etc.
  • /partials/footer.html - A template that defines the footer of your blog. This typically includes the copyrights, author information etc.
  • /_default/baseof.html - A base template that stitches all the above defined partials together, including the main sections defined in list and single template pages above.

A theme might have all the above files, or have just a subset of these. In case a theme does not provide a particular template file, one from the basic theme (which forms the base of every theme) of Micro.blog is used.

Moreover, make sure you configure the appropriate Hugo Version to be used for your blog. Micro.blog allows two versions of Hugo to be used, 0.54 and 0.91, the latest being relatively new. Many themes may not work with the older 0.54 version of the Hugo, typically indicated by the min_version configuration in the theme.toml. If the value is above 0.54, set the Hugo version to be used as 0.91. This can be done via Design → Hugo Version.

Fix the Broken Pages

Usually, the home page might not render the list of all the posts with the ported templates. This is often due to the wrong selection of the posts. To check the selection, visit the list template mentioned above and fix the file which is fetching all the posts. It should typically look like below where you pull all the regular pages where type is defined as post.

{{ $pages = where .Site.RegularPages "Type" "post" }}

A similar fix would also need to be applied to the archive page’s template, if it is defined custom. The archive page would also need styling the components appropriately, as these are all Micro.blog specific classes, not part of the default styling of the theme.

Next, you will have to fix the templates to handle the title-less posts. Most posts published with Micro.blog are, well, micro-posts with no titles. So, wherever a Title is referenced, it should be wrapped in a {{ if .Title }} condition. So, the title reference at every place should read like below.

{{ if .Title }}
	<h2>{{ .Title }}</h2>
{{ end }}

The title-less posts might also need minor styling fixes. A typical pitfall is when a post permalink is only available with title. So, a micro-post requires a different element to carry the permalink, mostly the date-time of the post.

Another aspect that is typically broken is rendering of the taxonomy. Most of the themes in Hugo use tags to define the taxonomy. Micro.blog uses categories and hence need to fetch them differently. So at every place a template mentions tags, mostly on list template, archives template and single template, replace them with categories. This primarily involves replacing all the references of .Params.tags with .Params.categories.

With these changes handled, you should have a working website that renders correctly. However, it is still not customised to include the benefits that Micro.blog brings to the table.

Add Micro.blog Specific Tags

Micro.blog packs the key IndieWeb principles, like IndieAuth, MicroPub, Webmentions, out-of-box for all websites hosted with the platform. However, this does involve defining a few relevant aspects at appropriate places. In addition, the platform is also rich in the ways a user not adept with coding can customise their website to their liking, with support for providing custom CSS, footer and plug-ins. Enabling these also need relevant components to be defined.

The changes to be made are in two files. First, modify the partials template that defines the head section of your website, /partials/head.html.

<link rel="stylesheet" href="{{ "custom.css" | relURL }}?{{ .Site.Params.theme_seconds }}">
<link rel="me" href="https://micro.blog/{{ .Site.Author.username }}" />
{{ with .Site.Params.twitter_username }}
	<link rel="me" href="https://twitter.com/{{ . }}" />
{{ end }}
{{ with .Site.Params.github_username }}
	<link rel="me" href="https://github.com/{{ . }}" />
{{ end }}
{{ with .Site.Params.instagram_username }}
	<link rel="me" href="https://instagram.com/{{ . }}" />
{{ end }}

<link rel="authorization_endpoint" href="https://micro.blog/indieauth/auth" />
<link rel="token_endpoint" href="https://micro.blog/indieauth/token" />
<link rel="micropub" href="https://micro.blog/micropub" />
<link rel="microsub" href="https://micro.blog/microsub" />
<link rel="webmention" href="https://micro.blog/webmention" />
<link rel="subscribe" href="https://micro.blog/users/follow" />

{{ range .Site.Params.plugins_css }}
	<link rel="stylesheet" href="{{ . }}" />
{{ end }}
{{ range $filename := .Site.Params.plugins_html }}
	{{ partial $filename $ }}
{{ end }}

Next, add the below lines to the end of your base template, /_default/baseof.html just before </body>. These load the custom footer and the plug-ins defined JavaScripts.

{{ partial "custom_footer.html" . }}

{{ range .Site.Params.plugins_js }}
	<script src="{{ . }}"></script>
{{ end }}

Display Replies as Conversations

Micro.blog allows including replies made on the posts to be shown as conversations on a post page via a design setting (Design → Include conversation on post page). However, for the replies to be rendered on your post page, you need to modify your single template, /_default/single.html or posts/single.html, and add the below lines at the end.

{{ if .Site.Params.include_conversation }}
	<script type="text/javascript" src="https://micro.blog/conversation.js?url={{ .Permalink }}"></script>
{{ end }}

Summary

The difficulty involved in porting a Hugo theme to Micro.blog depends completely on the complexity of the original theme. Though it is difficult to extensively cover all the changes required, fixing the things that are broken and adding support for the Micro.blog specific features and tags is all it takes. This article attempted to list down the majority of the identified changes.

In the future, the way of including the Micro.blog specific changes may be simplified significantly. This article would be updated accordingly to reflect the same. However, the awareness of the changes being done allows one to appreciate the hidden complexity and beauty of the platform that is Micro.blog.


PS: This post was written for, and is also published at Custom by Miraz Jordan - a website that intends to “develop reference information and tutorials to help people customise themes in hosted Micro.Blogs”.

I have released a new version of the Paper theme (v1.0.3) today to display category list on the archive page – this can be disabled via plug-in settings. The theme now also supports Reply by email and Conversation on M.b plug-ins by @sod. So if any of the plug-in is already installed, the appropriate link will be displayed under the posts. The upgrade also brings support to include Buy Me a Coffee profile in the social icons list.

I appreciate all the feedback I have received until now. With all the improvements, Paper has become my default theme for my blog (what you see here).

I have released a new version 1.1 of Posts Stats plug-in today. It adds the support to display a chart for the posts by year, displays categories as a cloud and introduces a new stat to show the longest post published. I am pleased with this version - demo here. 😊

I have released a new version 1.0.2 of the Paper theme today, which addresses the reported issues and suggestions since the first release yesterday. Here are the changes, in brief.

  • Added support to include replies on individual posts
  • Added the configuration of social icons as plug-in setting
  • Updated the styling to display categories along with posts
  • Updated documentation to include installation steps
  • Fixed styling of images on smaller screens

You can go to the Plug-ins section in Micro.blog and click “Upgrade” once the option is available. You will have to reconfigure (for the last time, hopefully) the social IDs in the settings of the plug-in. No need to modify the config.json, anymore. This also means the configurations will not be lost during the future upgrades.

I am thrilled with all the feedback that I have received. Paper is a beautifully designed theme, something I can take no credit for. At the same time, I am glad I could make it simpler for others to adopt it.

Paper – A Clean Theme for Micro.blog

After playing around briefly to understand how to bring a theme made for Hugo to Micro.blog, I have finally ported one that I love. Today, I am ready to share it with the Micro.blog community. The theme is called Paper and goes with a tagline “simple, clean, flexible”. You can check for yourself in the screenshot below, or see it live at my test blog.

I am a big fan of clean themes that are minimal, yet impressive. Paper is one such theme — I had used it earlier when I was hosting this blog with Hugo. Although it looks minimal, it isn’t so in the way it works. It has a simple, yet signature header, a built-in dark mode support with a beautiful toggle and a clean black & white look.

I have added the first version of this theme to the plug-ins directory so that you can install it directly as a plugin. It works with both Hugo versions that Micro.blog supports (0.54 and 0.91) [Update]: An issue was reported while using the theme with Hugo version 0.54. So, until further update, the theme supports only version 0.91 of Hugo. However, here are a few points to remember before you install the theme.

Uninstall any theme that you have installed as a plugin. Set you current theme to blank and Hugo Version to 0.91 in the design section of your blog. Make sure there are no other conflicting custom CSS configured for the previous theme. Then install the Paper theme from the plugin directory. Once the theme is successfully installed, you can configure the social icons displayed in the header by modifying the available options in config.json.

There’s already a brilliant selection of themes available for Micro.blog and I am excited to see the support grow further with every passing day. I hope you like this and a few folks benefit from it. If you do, I would love to hear from you.

Styling Newsletter Digests in Micro.blog

I recently changed the newsletter to a weekly digest instead of every long-form posts with Micro.blog. A fixed schedule is better for me than thinking about whether to include as part of the newsletter every time I post a post with a title. Until there is a better control (via categories) on what posts I can schedule for delivery, I want to avoid risking this particular setting.

That said, I didn’t really like the way the first digest looked. It was… mhmm … messy. Maybe a bit more control over the elements, like title etc. would be good. Without that, to make the digest look slightly better, here’s the custom CSS that I have added currently.

You can apply this to your digest by including this CSS block to your custom CSS (‘Design’ ⇾ ‘Edit CSS’).

/* Set the font display */
.microblog_email {
    font-family: "Avenir Next", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
	font-size: 16px;
	line-height: 1.7em;
	max-width: 600px;
	margin: auto;
}

/* Assign area and display for the blockquote */
.microblog_email blockquote {
	display: block;
    margin: 0;
    margin-bottom: 14px;
    padding: 0 20px;
    border-color: #E0E4E8;
    border-left: 2px solid #E0E4E8;
    line-height: inherit;
}


/* Assign area and display for the images */
.microblog_email img {
	display: block;
	max-width: 100%;	
	height: auto;
	margin: 0 auto 0.5rem;
  	vertical-align: middle;
  	border-radius: 5px;  	
}

/* Style links */
.microblog_email a {
	color: #4F8BCA;
}

/* Hide the profile image and header */
.microblog_email .microblog_header, .microblog_email p:first-child img {
	display: none;
}

/* Style the footer links */
.microblog_email .microblog_footer {
	margin-top: 20px;
    text-align: center;
    font-size: 13px;
    padding-top: 10px;
    padding-left: 30px;
    padding-right: 30px;
    line-height: 1.5em;
}

/* Styling for the separator */
.microblog_email hr {  
  margin: 12px 0;
  border: 0;
  text-align: center;
}

.microblog_email hr:before {
	content: "\2022 \2022 \2022 \2022";
    font-size: 20px;
    color: #4F8BCA;
}

/* Styling the links */
.microblog_email .microblog_permalink {
    color: #4F8BCA;
} 

I would like to avoid these :nth-of-type and :first-child blocks. But until the elements across the body are assigned classes, I will have to stay with this. Anyway, hope this helps. Or if there’s a better, simpler way to achieve this, I would love to hear.


Update [24 April 2022]: Fixed the issue with blockquotes being hidden due to the selection for headers being mistakenly applied to the blockquotes too. This uses the recently added CSS selectors for .microblog_header and .microblog_footer.

A minor styling suggestion while using Posts Stats plugin with Marfa theme in dark mode. Add this snippet to custom CSS (‘Design’ -> ‘Edit CSS’) to fix background of alternate rows in tables.

@media(prefers-color-scheme: dark) {
	tr:nth-child(odd)>td {
	  background: initial;
	}
}

Thanks to Andrew for bringing this to my notice.

I like to remind myself about the number of words that I’ve written on my blog. Well, now I do, through my Archive page. It’s auto-generated, refreshed every time I publish. And if you host with Micro.blog, you can achieve the same with this plugin. It’s basic, but works.