开始使用 Hugo

- hugo development

Step 1. 安装 Hugo

以 Debian 9 为例,下载Hugo,并解压到 $HOME/app/hugo/,添加下面的命令到 .bashrc:

export PATH=$PATH:$HOME/app/hugo

执行 source ~/.bashrc

Step 2. 新建站点

hugo new site mySite

会在当前目录下生成名为 mySite 的文件夹。

Step 3. 添加主题

cd mySite
git clone https://github.com/yursan9/manis-hugo-theme themes/manis

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

Step 4. 运行调试

Hugo themes Hugo 主题 下载主题。

git clone https://github.com/yursan9/manis-hugo-theme themes/manis
hugo server --theme=manis --buildDrafts --baseURL="http://localhost/"

本地浏览器打开: http://localhost:1313

Step 5. 自动化部署

server$ mkdir mySite.git
server$ cd mySite.git
server$ git --bare init
server$ vi hooks/post-receive

#!/bin/bash

GIT_REPO=$HOME/mySite.git
TMP_GIT_CLONE=$HOME/tmp/mySite
PUBLIC_WWW=/var/www/mySite

git clone $GIT_REPO $TMP_GIT_CLONE
cd $TMP_GIT_CLONE
export PATH=$PATH:$HOME/app/hugo
hugo
rm -rf $PUBLIC_WWW/*
mv public/* $PUBLIC_WWW/
rm -Rf $TMP_GIT_CLONE
exit

server$ chmod +x hooks/post-receive
server$ mkdir -p /var/www/mySite
server$ chown hugo:hugo /var/www/mySite