该方式适用于Ubuntu系统,Windows/Macos类似
安装Brew
- 首先需要确保已经安装git
sudo apt-get install build-essential curl file git
- git clone安装brew
git clone https://github.com/Homebrew/brew ~/.linuxbrew/Homebrew
mkdir ~/.linuxbrew/bin
ln -s ~/.linuxbrew/Homebrew/bin/brew ~/.linuxbrew/bin
eval $(~/.linuxbrew/bin/brew shellenv)
- 运行
brew
即可完成安装
安装hugo
- 通过brew安装hugo
brew install hugo
- 安装完成后可通过
hugo version
验证是否安装成功
hugo v0.109.0+extended linux/amd64 BuildDate=unknown
初始化hugo博客
- 创建hugo根目录
hugo new site blog
其中,blog为博客根目录的文件夹名称。
当终端中出现congratulations
字眼时,说明创建成功。
- 下载hugo主题,通过主题内的
git clone
进行安装
cd blog
git clone git clone https://github.com/vaga/hugo-theme-m10c.git themes/m10c
下载完成后即可在/blog/themes/
中看到下载的主题
- 本地启动hugo博客进行测试
hugo server -t m10c --buildDrafts
m10c为需要启用的主题
启动后即可通过本地地址访问博客
创建博客文章
hugo博客一般通过markdown格式进行编写
- 在post目录下创建一篇名为myblog的博客
hugo new post/myblog.md
创建完成后在blog/content/post
即可看到myblog.md
文件
- 本地预览博客文章
cd&&cd blog
hugo server -t m10c --buildDrafts
测试无误后即可部署到远端
部署至github仓库
创建github博客仓库,仓库名称必须为“用户名.github.io”,例如FBwenoll.github.io
部署时Git工具必须已初始化完成,具体方法详见百度
- 生成public文件
hugo --theme=m10c --baseUrl="https://FBwenoll.github.io" --buildDrafts
其中m10c为主题名称,url为博客的访问地址
- public文件夹中初始化git
cd public
git init
git add .
git commit -m "第一次提交"
- 关联github仓库
git remote add origin https://github.com/FBwenoll/FBwenoll.github.io.git
地址为前面新建仓库的地址
- 推至远端
git push -u origin master
输入用户名&密码
此时若出现Support for password authentication was removed on...
等字眼,则需要新建KEY进行导入。
- 进入
github->settings-> Developer settings->Personal access tokens->generate a new token
- 复制生成的KEY
-
git remote set-url origin https://刚刚复制的口令@github.com/FBwenoll/FBwenoll.github.io.git
- 再次尝试
git push
即可成功