使用Hugo搭建自己的博客

运行环境与工具

服务器:VPS + CentOS 7.0
工具:yum、wget、go、git、hugo

安装 wget

yum -y install wget

安装 git

yum -y install git

安装步骤

  1. 下载 Go 环境
    手动 wget 安装,不推荐 yum 安装
wget http://www.golangtc.com/static/go/1.11/go1.11.linux-amd64.tar.gz
sudo tar -xzf go1.11.linux-amd64.tar.gz -C /usr/local
  1. 配置 Go 环境变量
vi /etc/profile
or
vi $HOME/.profile

插入以下内容并保存

# GO PATH
export PATH=$PATH:/usr/local/go/bin
# GO GOPATH
export GOPATH=/home/golang

使 profile 立即生效

source $HOME/.profile

查看版本号

go version #查看go版本
go env #查看go环境变量
  1. 下载 Hugo
mkdir $HOME/src
cd $HOME/src
git clone https://github.com/gohugoio/hugo.git
  1. 编译 Hugo
cd hugo
go install

创建博客

  1. 创建新的博客站点
hugo new site "博客名"
  1. 下载主题
cd quickstart
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
  1. 编辑配置文件
    自用示例配置文件
  2. 添加新文章
hugo new posts/my-first-post.md
  1. 添加评论
  2. 发布博客
hugo server -D
Started building sites ...
Built site for language en:
1 of 1 draft rendered
0 future content
0 expired content
1 regular pages created
8 other pages created
0 non-page files copied
1 paginator pages created
0 categories created
0 tags created
total in 18 ms
Watching for changes in /Users/bep/sites/quickstart/{data,content,layouts,static,themes}
Serving pages from memory
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop

TODO

  • Hugo 服务常驻后台
  • Hugo Short Code 配置
  • Google 点击量记录
  • 其他插件试用

附录