3 configs add recommend articles into your Hugo blog by GitHub Actions

Leverage prelims to do content-based recommendations

Recommendation example of https://chezo.uno/blog/2017-07-24_simple-way-to-distribute-your-private-python-packages-within-your-organization-fb7af5dbd4c9/

Hugo has a feature to show keyword based related articles.

Yeah, keyword based articles might be useful, for people who can manage keyword, category, etc, constantly. I’d love to add content based recommendation that doesn’t require to write explicit keywords by myself. Then, I found an open source named “Prelims” which is developed by takuti.

Prelims is a post-processing tool for Front matter of Hugo/Jekyll, that is a metadata of an article. The recommendation method which is implemented for now is classical, create a TF-IDF based word vector and find similar articles by consign similarity.

The reason why I love Prelims is it’s simple and flexible. Post-processing of front matter doesn’t break your articles nor blog system at all. You can remove extra meta data Prelims generated whenever you want.

Isn’t it practical, right?

One downside of Prelims is it requires to implement Python code for tokenizing or vectorizing TF-IDF. I don’t want to bring my laptop for blog writing and wanna use Netlify CMS and iPad without having Python environment.

So, I built a CLI tool for Prelims, named prelims-cli, which enables to add recommended articles just writing 1 configuration YAML file. It also runs with GitHub Actions.

The three things you need to prepare are:

  1. Configuration YAML file for prelims-cli. e.g., scripts/config/myconfig.yaml
  2. Hugo HTML partial layout, e.g., layouts/partials/page_related.html
  3. GitHub Actions workflow for prelims-cli

Here is the example gist what you need to write.

where content/blog is the directory for English articles and content/post is the directory for Japanese articles.

Putting three files enables you to show recommended articles into your Hugo blog, like the screenshot in the top of this article.

Internally, for Japanese tokenization, it uses SudachiPy. Since keywords prelims generates are a-bit noisy and didn’t wanted to cleanup, so I stopped using it.

The good things I feel are, I can use my blog articles for my hobby recommendation project, and I don’t need to manage tags and categories seriously.

You can enjoy your recommendation without having Python environment, so you can write your articles on iPad with Netlify CMS!

Aki Ariga
Aki Ariga
Principal Software Engineer

Interested in Machine Learning, ML Ops, and Data driven business. If you like my blog post, I’m glad if you can buy me a tea 😉

  Gift a cup of Tea

Related