The main goal of this project is to show how easily you can develop a flat file blog with markdown as the primary writing language. It’s not perfect, it will never be, some people are already doing great things based on that idea, like Hugo for instance. Let’s note though, that’s not a static website generator.
As stated earlier, SmallBlog isn’t a static website generator. It’s a dynamic
web server, meaning that when you start it, it will parse the content of the
pages
directory. While the server is running you can add new files to this
directory, they will be automatically parsed and added to the site. Same goes if
you modify the content of an already parsed file, it will be parsed once more.
You can even change the metadata of the file, the server will keep its
consistency.
I already made a markdown based blog engine : MarkDownBlog. I’m tired of its design, it was my first real project, and I made a lot of bad technology choices. Like, why would I syntax-highlight on the server-side when there are perfectly good JS libs that do that automatically on the client-side ? That’s one less problem to deal with.
That’s why I’m using prismjs to do that. Plus it integrates perfectly with Blackfriday, the markdown parser I’m using. Blackfriday provides a parser for Github formated markdown. Which means you can use the notations of Github to write your articles, include the triple-backticks notation to write some code.
I also decided not to use any CSS framework this time. Keeping things simple and sober. And because I suck at designing things, I’d like to thank bettermotherfuckingwebsite.com for the inspiration.
When starting, the server will scan for the pages
directory. For each file
present in that directory it will parse the headers that are written in the yaml
format, as well as the markdown under the header (which are separated by a blank
line). A map containing the slug of the posts will be created as well as a slice
of articles sorted by date. The map will be used for a low complexity access to
the articles by their slugs, which will result in fast performances, something
like 150µs to display a post.
This method has its flaws. The more posts you have, the more RAM the server will consume.
While the server is running, it will also monitor the pages
dir for new files,
modification of exisiting files, or removal. This way, the server doesn’t need
to be restarted when you want to publish or remove one of your posts. If you
detect that something went wrong, the state of your filesystem doesn’t match
your blog for example, then restart the server. I make mistakes sometimes. And
make sure to open an issue on Github so this can be fixed.
Just to be sure to please everyone, everything is grey. Customize the CSS to match your color preferences.
func main() { log.Println("Hello World !") }
You can go build
to build this, and here’s a list for your pretty eyes :
inlined
content !Here is how a quote looks like. I hope you like it because I didn’t put much work on styling that.
– Benjamin Franklin