Lei Zhilong

The best way to input is to output

Aug 29, 2018 - 2 minute read - Comments - Blog

First Post Using Hugo

Hello Hugo

I have changed my blog to a hugo site and this is my first post using hugo.

Hugo Introduction

Hugo is a fast and modern static site generator written in Go, and I use it to build my blog. Here are some steps to build your own blog pages with Github Pages and Hugo, and it’s fast and all free.

Create two projects on Github

  • Blog source, assuming github.com/<username>/blog
  • Generated blog static pages, assuming github.com/<username>.github.io

Initialize github.com/<username>.github.io with a README.md or anything else you like, while the source blog repo can be left empty.

Install hugo

Check docs on Hugo doc site

Build a new hugo site

1
2
3
## new blog site
hugo new site blog
cd blog

Commit blog site into source repo

git init
git add .
git commit -m "first commit"
git remote add origin git@github.com:<username>/blog.git
git push -u origin master

Add a theme to your blog

git init;
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke;

# Edit your config.toml configuration file
# and add the Ananke theme.
echo 'theme = "ananke"' >> config.toml

To find more themes, go http://themes.gohugo.io/

Add some content and preview it

hugo new posts/my-first-post.md

New post is configurated as draft in meta data block, change it to false when you finish editing and decide to publish it.

1
2
3
4
5
---
title: "About"
date: 2017-08-29T18:05:29+08:00
draft: true
---

Start a local draft server to preview it at http://localhost:1313/

1
hugo server -D

The flag -D enables hugo to render draft pages.

Host hugo blog site on GitHub

  • Remove your public directory in you blog source repo
1
rm -rf public
  • Use your generated static blog repo as a submodule of the source repo
1
git submodule add -b master git@github.com:<usename>/<username>.github.io.git public.
  • Use a deploy script to publish your generated pages

Save script as deploy.sh in your source repo and run it to publish.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

echo -e "\033[0;32mDeploying updates to GitHub...\033[0m"

# Build the project.
hugo # if using a theme, replace with `hugo -t <YOURTHEME>`

# Go To Public folder
cd public
# Add changes to git.
git add .

# Commit changes.
msg="rebuilding site `date`"
if [ $# -eq 1 ]
  then msg="$1"
fi
git commit -m "$msg"

# Push source and build repos.
git push origin master

# Come Back up to the Project Root
cd ..

DONE

Now you can try to access your blog at https://<usename>.github.io

Tags: hugo blog

Hexo Test Drive gVisor VS Kata Container

comments powered by Disqus