使用Hugo将个人博客部署到Github上

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/rectsuly/article/details/79352625

Hugo是一个用Go 语言编写的静态网站生成器。如果你正想在GitHub上搭建个静态的博客,不妨试试用Hugo.

1.安装Hugo

$ wget https://github.com/gohugoio/hugo/releases/download/v0.36.1/hugo_0.36.1_Linux-64bit.deb
$ sudo apt-get -f install
$ dpkg -i hugo_0.36.1_Linux-64bit.deb

hugo version查看版本信息,显示以下即安装成功:

$ hugo version
Hugo Static Site Generator v0.36 linux/amd64 BuildDate: 2018-02-05T15:22:28Z

2.创建新网站

$ hugo new site myBlog

3.添加主题(以tranquilpeak为例)

$ cd myBlog/themes
$ git clone https://github.com/kakawait/hugo-tranquilpeak-theme.git

该主题的用户说明见:https://github.com/kakawait/hugo-tranquilpeak-theme/blob/master/docs/user.md

4.复制主题标准样式的配置文件及资源文件到对应路径下:

$ cd ~/myBlog/themes/hugo-tranquilpeak-theme/exampleSite
$ cp config.toml ~/myBlog/
$ cp -r static ~/myBlog/static
$ cp -r content ~/myBlog/content

5.适当修改config.toml的内容,在/content/目录下添加新的.md文件可以发表新文章。

6.测试网站

$ hugo server

打开http://localhost:1313/查看修改后的网页内容。

7.发布网站

hugo --theme=hugo-tranquilpeak-theme --baseUrl="https://rectsuly.github.io/

此时,在~/myBlog目录下会创建一个public的文件夹,将此文件夹下的所有内容git pushgithub上的rectsuly.github.io仓库即可把博客部署到Github Pages中,我个人的博客地址为:https://rectsuly.github.io/

部署代码如下:

$ mkdir ~/github.io/rectsuly.github.io/
$ cd ~/myBlog/public/
$ cp -r . ~/github.io/rectsuly.github.io/
$ cd github.io/rectsuly.github.io/
$ git init
$ git status
$ git add .
$ git commit -m "add new article"
$ git push https://github.com/rectsuly/rectsuly.github.io.git master

到这里,我们的第一个Hugo个人博客网站就成功地部署到了Github上。以后添加新文章时,只需要重新编辑~/myBlog/content上的文章内容,然后发布文章,将更新后的public文件夹内容重新提交到Github仓库上。

猜你喜欢

转载自blog.csdn.net/rectsuly/article/details/79352625