Getting Related Content working
The latest release of Hugo includes Related Content, which I thought would be nice to add to my blog. However the docs, although they show you how to set it up, don’t explain how it works. To find that out, I had to look at the various threads on the Hugo forums.
There are four parts - you need to create a new partial template in
layouts/partials/related.html
containing something like this:
{{ $related := .Site.RegularPages.Related . | first 5 }}
{{ with $related }}
<hr>
<h3>See Also</h3>
<ul>
{{ range . }}
<li><a href="{{ .RelPermalink }}">{{ safeHTML .Title }}</a></li>
{{ end }}
</ul>
{{ end }}
You need to add a reference to your new partial template in your single page template in layouts/_default/single.html
possibly near the end:
Adding a calendar event in android
The android docs for the Calendar Provider are quite useful, but
recommend the use of an AsyncQueryHandler for querying or adding
events to calendars in an asynchronous thread. However the
AsyncQueryHandler
docs don’t include much guidance as to how to use
it.
To add an entry to an android calendar you first have to find out the calendar id using an asynchronous query on the calendars table.
// QueryHandler
public class QueryHandler extends AsyncQueryHandler
{
private static final String TAG = "QueryHandler";
// Projection arrays
private static final String[] CALENDAR_PROJECTION = new String[]
{
Calendars._ID
};
// The indices for the projection array above.
private static final int CALENDAR_ID_INDEX = 0;
private static final int CALENDAR = 0;
private static final int EVENT = 1;
private static final int REMINDER = 2;
private static QueryHandler queryHandler;
// QueryHandler
public QueryHandler(ContentResolver resolver)
{
super(resolver);
}
// insertEvent
public static void insertEvent(Context context, long startTime,
long endTime, String title)
{
ContentResolver resolver = context.getContentResolver();
if (queryHandler == null)
queryHandler = new QueryHandler(resolver);
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startTime);
values.put(Events.DTEND, endTime);
values.put(Events.TITLE, title);
if (BuildConfig.DEBUG)
Log.d(TAG, "Calendar query start");
queryHandler.startQuery(CALENDAR, values, Calendars.CONTENT_URI,
CALENDAR_PROJECTION, null, null, null);
}
This method is called from an app activity.
Read more →Whatever-o-meter revisited
I wrote the whatever-o-meter about five years ago in PHP and
Javascript as a Wordpress plugin. As I have migrated my blog to Hugo,
I thought to have a go at reimplementing it. The exporter I used made
a good job of translating the Wordpress custom fields to Hugo front
matter parameters. I had to put dashes in quotes, otherwise they get
interpreted as [<nil>]
.
intro: Please answer the following questions carefully and truthfully.
question:
- You are lying in bed on Monday morning...
result:
- '%d percent, Perhaps you should consider emigration.'
- '%d%, Consider taking a long holiday somewhere far away.'
left:
- Go and jump in the shower quick
right:
- Jump on him
weights: 2,1,1,1,1
centre:
- '-'
- '-'
- So so
more: https://billthefarmer.github.io/blog/morris-o-meter
The javascript part should just work as it is, the PHP plugin needed re-implementing as a hugo shortcode. The first part of the plugin just outputs svg code to draw the dial and pointer, that was fairly easy to implement, it just has some iteration in it. I had to change the ticks slightly as Hugo doesn’t appear to support floating point arithmetic in templates.
Read more →Migrating this blog from Wordpress
I have got fed up with Wordpress. It required constant updates, which doesn’t work automatically on Sourceforge developer web, and it’s slow, especially in admin mode. I came across a reference to Hugo while following up on something unrelated, so I decided to investigate.
I looked for migration tools, and found two:
- Exitwp, which reads a Wordpress export xml file and converts to Jeckyll
- WordPress to Hugo Exporter, which is a Wordpress plugin and exports to Hugo
I found a blog post from Justin Dunham documenting migrating his blog. He tried the WordPress to Hugo Exporter first, but couldn’t get it to work, so he used Exitwp. I tried this, which just worked, but I didn’t like the look of tidying up all the blog entries to work with Hugo.
Read more →Resolving content uris in android
If you write an android app that handles images or any other sort of file your app may be required to deal with ‘content’ uris (content://
). There is a very useful utility which resolves these into ‘file’ uris (file:///
) FileUtils.java. This contains one external reference to LocalStorageProvider, which can be resolved by removing the function isLocalStorageDocument()
and references to it.
// import com.ianhanniballake.localstorage.LocalStorageProvider;
// ...
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is {@link LocalStorageProvider}.
* @author paulburke
*/
public static boolean isLocalStorageDocument(Uri uri) {
return LocalStorageProvider.AUTHORITY.equals(uri.getAuthority());
}
Having done that, you can then resolve ‘content’ uris
Read more →