I recently came across a very neat trick to spice up your GitHub user profile page. If you look at my GitHub user page, you'll see that it has some extra info about me as well as my latest blog posts. You can set this up yourself as well.

We'll be using the blog-post-workflow GitHub Action by Gautam krishna R to accomplish this.

The first thing you need to do is to create a repository named after your username. In my case, this was creating the following repository:

https://github.com/pieterclaerhout/pieterclaerhout

As soon as you name the repository the same as your username, GitHub will tell you that this is a "special" repository 🙀.

Once you created the repository, you can add a README.md file which contains the contents shown on your user profile page. To get the latest posts in there, we need two extra things: a GitHub action and the RSS / Atom feed for our blog posts.

Let's start with adding the markup to our README.md file to indicate where the latest posts should show up (please note the special placeholders):

# 📩 Latest Blog Posts // You can name it whatever you want.
<!-- BLOG-POST-LIST:START -->
<!-- BLOG-POST-LIST:END -->

Once you committed this, we can setup a GitHub action which updates the README.md on a regular basis. To set it up, create a file called .github/workflows/latest_posts.yml in the same repository. Then put in the following content in that file:

.github/workflows/latest_posts.yml

name: Latest posts workflow
on:
 schedule:
   - cron: '0 * * * *' 
 workflow_dispatch: 
jobs:
 update-readme-with-blog:
   name: Update this repo's README with latest blog posts
   runs-on: ubuntu-latest
   steps:
     - uses: actions/checkout@v2
     - uses: gautamkrishnar/blog-post-workflow@master
       with:
         # Replace this URL with your rss feed URL/s
         feed_list: "https://www.yellowduck.be/index.xml"
         max_post_count: 10
         template: "- `$date` | [$title]($url)  $newline"
         date_format: yyyy-mm-dd
         tag_post_pre_newline: true

Commit the code, go to the Actions panel in your repository, select the workflow and run it manually. This will let the action do it's work and the posts should appear in the README.md file now. As the action is setup with a cron trigger as well, it will run every hour.

In my action, I've customized the action options slightly:

  • feed_list: the link to the RSS / Atom feed
  • max_post_count: the maximum number of posts to show
  • template: a custom template for each blog post entry (I wanted the date to be included)
  • date_format: to customize how the date will show up
  • tag_post_pre_newline: Allows you to insert a newline before the closing tag and after the opening tag when using the template option if needed, for better formatting

If you want to learn more about GitHub actions, have a look at the official documentation.

Related Posts

  • Running pytest as a Github Action
  • Deploying a Hugo site with Github Actions
  • Tips and tricks for creating Kubernetes secrets
  • Kubernetes Port Forwarding for Local Development