Setting up this Blog

I wanted to do a small write up on how I set this blog up. This blog uses hugo to generate content. Things to note about Hugo:


1. Github Repository

Create a repository to host all your content. This is where you will be maintaining markdown files. So I created

2. Setup using Hugo CLI

Hugo CLI allows us to bootstrap a new site.

$ hugo new site website
$ cd website && tree
| |

Note: Please refer Hugo docs for extensive documentation. This blog touches upon only few things I did.

3. Choose a theme

Choose a hugo theme from an exhaustive list. Add the theme as a submodule to your project. Configure config.toml with theme information. Refer here

$ git submodule add${THEME_URL}.git themes/${THEME_NAME}

4. Github Repository to host HTML

We will be writing content only in Markdown files. Once that is done, we need to generate HTML content with appropriate static assets based on our theme. To host this, we need a github repository. This needs to be created in the domain name of the site. We could choose from 2 options

Use Github’s domain

Create the repository in the name ${USERNAME} Your site will be served with the same URL.

Use custom domain

Create a custom domain using some provider. E.g Create the repository in your name. In my case, I created the repo Go to the Settings page of your repository. In the GitHub Pages section, specify your custom domain. Also read this to point your domain to Github servers.

Whatever domain you choose, make sure to update it in ./config.toml under baseURL. We are at a point where if we put any HTML content into this repository, it will be served as a website. Let’s do that.

5. Continously deploy with Travis

Now we need to generate HTML content from our markdown files. If we run hugo in our codebase, it would generate all those content inside public directory. If we could bring that content to our ${USERNAME} repository, it will be hosted. Let’s automate that part. We are going to use Travis CI’s Pages deployer. Create a .travis.yml with content

sudo: false
dist: trusty
- wget -q ""
  -O "hugo.tar.gz"
- tar -xzf hugo.tar.gz
- "./hugo"
  provider: pages
  repo: ###${USERNAME}/${REPO}###
  fqdn: ###YOUR DOMAIN###
  target-branch: master
  skip_cleanup: true
  local_dir: public
  github_token: "$GITHUB_TOKEN"
  keep-history: true
    branch: master
    secure: ###SECURE_TOKEN###

The above steps download hugo and create the public directory by running ./hugo. The following needs to be configured by you (things that are prefixed with #):

To get the secure token, first go your profile Settings, then Developer Settings and then create a Personal Access token with public_repo access (it will be under repo). Save the token. We need to pass this token to Travis. In order to that, we can encrypt it using Travis CLI and store it in our YAML directly.

# Install Travis CLI
$ sudo gem install travis

# Login
$ travis login

# Encrypt

This would have populated the section of the .travis.yml. You can check-in this now. Travis will build and publish the HTML files to Github pages. You could access your URL using the domain you chose.

6. Future workflow

To create posts

# This would create a Draft
$ hugo new posts/

To view and live reload

$ hugo server - -D

# In case, if themes are not checked out
$ git submodule update --init

To publish, remove this content from your post

draft: true

Commit & push, it will be automatically deployed!