Hugo & Github Pages Blog搭建 PART2

运行localhost

Posted by     "" on Monday, June 4, 2018

新建文章

在 Blog 文件夹下:

hugo new post/hello.md

这时候你的 content 文件夹下会多一个名叫 post 的文件夹,里面有你的 Markdown 文件:

vim content/post/hello.md

输入你的内容,比如 Hello world!, 然后 Hugo server -w 就能预览到你的第一篇文章。

关联 GitHub Pages

在 Blog 文件夹的上一级目录下:

git clone username.github.io链接

如果你在 username.github.io 下初始化过 README.txt, 则

cd username.github.io
git pull origin master

之后进入 Blog 目录:

hugo -d ../username.github.io/

这一步是生成静态网站,然后回到 username.github.io 目录:

git add --all
git commit -m "first commit"
git push origin master

然后可以在浏览器输入你的 username.github.io 访问你的博客了。

绑定域名

Custom domain

进入 username.github.io 的 Setting,找到 Github Pages 下的 Custom domain,输入你的域名,如果是 HTTPS 则需要将下面的 Enforce HTTPS 选项勾上。

服务器配置

然后需要重定向你的域名,配置解析记录:

type host points to
CNAME Your domain or sub domain username.github.io

等待一段时间后生效,浏览器输入你的域名就可访问你的博客。

注意,以上步骤会在仓库下新增一个 CNAME 文件,所以在下一次 push 的时候别忘了先 pull~

更新

当编辑完所有更改之后需要同步到 GitHub,具体步骤如下:

# 先在 Blog 目录下 push
git add .
git commit -m "..."
git push origin master
# 然后更新静态页面
hugo -d ../username.github.io/
# 进入到 username.github.io 目录下
cd ../username/github.io
git add .
git commit -m "..."
# 如果配置了域名别忘了先 git pull
git push origin master

「真诚赞赏,手留余香」

EagleYing's Blog

真诚赞赏,手留余香

使用微信扫描二维码完成支付