command to generate index for the blog

There’d never been a kind blog because there are no index page. But now it has changed. I have index pages for each directories like 2018.

I prepared a command for this purpose, named mmyoji/blogexporter. This has a few lines of code and written by Golang.

I will write about the code here a little.

Looking for a better way to parse the content

My Blog structure is like following:

title: "here is a title"
date: 2018-09-25T00:00:00+09:00




The first --- separated part is for metadata, title and date. I firstly parse this part one by one, very gross way. After that, I changed the code just strings.Split(body, "---") and use yaml package. Code got better, but this didn’t work. If the content contains more --- delimiter? Finally, I changed the code back to the 1st approach, read each line, determine the metadata part and body part, but still use yaml package. This fortunally works well. I want to know the better way if there is. (and i hope it is)

What I learned from this command

I’ve gotta a master of flag, filepath and strings package.

In this time I didn’t use spf13/cobra because the command doesn’t need sub command.

I’ll use it whenever I need to create a command with sub commands.


I feel I’ve become a better Golang programmer day by day.

Next I will build a bit larger web app with this great language.