A minimal and static blog engine written in Go.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
_example_site
.gitignore
AUTHORS
LICENSE
README.md
config.go
main.go
posts.go
site.go
utils.go

README.md

blgo

A minimal and static blog engine written in Go.

Overview

Blgo is a static blog engine written in Go, aimed at minimalism and flexibility.

Blgo takes a directory with content written in Markdown and another one with templates and renders a full static website.

Getting started

Install

go get github.com/zlowram/blgo

Creating your site

Blgo needs to know where the directories with the content and templates are, as well as some parameters, and this can be done via the configuration file, which is in toml format.

An example of Blgo configuration file is the following:

# Site parameters
Title = "blgo" # Title of your site
Description = "A static blog engine written in Go" # Description for your site
Keywords = "blog, Go" # Keywords for your site
PreviewLength = 30 # Length of the post preview in the index (number of words)
PostsPerPage = 1 # Index posts pagination

# Disqus parameters
DisqusShortname = "blgo"

# GoogleAnalytics
GoogleAnalyticsID = "UA-XXXXXXXXX-X"

# Directories
Posts = "posts" # Directory containing the posts
Templates = "templates" # Directory containing the templates
Public = "static" # Directory where the generated static site will be stored

Writing posts

In blgo each post is a plaintext file with the following structure:

Author: zlowram
Date: 01-08-2015 00:45
Title: Hello, world!
Template: post
Comments: enabled


Here starts the content of the post.

Posts content is created using the Markdown syntax, and file must be placed in the posts directory.

It is recommended to name the file with the title of the post replacing spaces with hyphens, because it will be included in the post's permalink. The permalink of the example post above, if the file is named "test-post.md" would be:

http://example.com/2015/01/08/test-post/

Writing templates

Blgo has support for templates so, if you have web-design skills, you may want to write your own templates. Then, good news for you: writing themes for blgo is stupidly simple! You need to create a file template for the index and for the posts, and place it in the templates directory.

The template directory structure is the following:

templates/
├── css/
├── fonts/
├── images/
├── index.html
├── js/
└── post.html

A template is an HTML file that contains Go template syntax at the concrete places where you want the content and information to appear.

The data struct passed to the template is different for the index and the posts:

Post

 data := struct {
     Config Config
     Post   Post
 }{
     site.Config,
     p,
 }

 type Post struct {
 	Author    string
 	Date      time.Time
 	Title     string
 	Content   string
 	Preview   string
 	Template  string
 	Permalink string
 }

 type Config struct {
 	Title         string
 	Description   string
 	Posts         string
 	Templates     string
 	Public        string
 	PreviewLength int
 }

Examples:

  • Print the title of the post: {{.Post.Title}}
  • Print the Date: {{.Post.Date.Month}} {{.Post.Date.Day}}, {{.Post.Date.Year}}
  • Print the title of the site: {{.Config.Title}}

Index

 type Site struct {
 	Config Config
 	Posts  []Post
 }

 data := struct {
     Config       Config
     Posts        []Post
     PreviousPage string
     NextPage     string
 }{
     s.Config,
     s.Posts[st:ed],
     prev,
     next,
 }

Examples:

  • Iterate over the posts and print the title of the post: {{range .Posts}} {{.Title}} {{end}}
  • Check if next page exists and print the path to it: {{if .NextPage}} {{.NextPage}} {{end}}

Whether you don't want to make a template, or you created one and would like to share it, check the official templates repository!

Using Google Analytics

Blgo currently has built-in support for Google Analytics. However, the Template that you use must also support it. If the template does not support Google Analytics, it is really easy to do so, just add the following script tag within the tags in each template page:

<script>
	(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	 })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

	ga('create', '{{.Config.GoogleAnalyticsID}}', 'auto');
	ga('send', 'pageview');
</script>

Deploying your site

The easiest way to deploy your site generated with blgo, is to copy the contents of the public directory in the root folder of your favorite web server.

Blgo is a command-line tool, so the deploy process can be automated in different ways (Makefiles, Git Hooks, etc.).If you have a cool deploying method, let us know!

Current features

  • Index pagination
  • Comments via disqus
  • Support for GoogleAnalytics

Future features

  • Support for pages.
  • Tags for posts.
  • Permalink customization.
  • Etc.

Sites using blgo

If you are using blgo for your site, we would like to know! You can either contact me via twitter or you can send a pull-request adding your URL in the following list:

Contributing

If you would like to contribute to this project, you can do it in several ways:

  • Opening an Issue to report a bug, suggest a feature, whatever.
  • Sending a pull-request with your changes.

In both cases it will be reviewed and studied if it should be merged or not in the project.