Hugo & GitHub Pages Blog搭建 PART 1

基础配置

Posted by     "EagleYing" on Wednesday, September 30, 2020

系统

本机:MacOS Catania 10.15.6,以及已经安装Git;

服务器:Ubuntu 16.04.6

安装Hugo

MacOS 安装 Homebrew

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

官网详情:Homebrew

安装Hugo

% brew install hugo

其他安装方法见官网:Hugo

查看 Hugo 版本(顺便检查是否安装成功)

% hugo version
Hugo Static Site Generator v0.75.1/extended darwin/amd64 BuildDate: unknown

GitHub 初始化

需要两个仓库:

Repository Attribute Usage README.txt
Username.github.io Public Github Pages, xxx.xml, xxx.html 可以放
Your blog repository Private xxx.md 不要放!!!

Github Pages可以参考这里 Github Pages,是可以设置为私有的但是感觉反正内容都公开可见也没有必要😂,Username 是你的GitHub名;第二个比如 MyHugoBlog 主要用来放你的 markdown 文件。注意第二个仓库不要初始化README.txt

新建页面

进入你的文件夹,新建一个 Hugo site:

hugo new site Blog

这时候你的文件夹下会多一个名叫 Blog 的文件夹,里面文件的目录如下:

-- Blog
|-- archetypes
|-- data
|-- resources
|-- config.toml
|-- layouts
|-- static
|-- content
|-- themes

git init

在 Blog 文件夹下:

git init
git remote add origin 你的blog仓库链接

在这里需要编辑 .gitignore 文件夹,忽略 public 文件夹:

vim .gitignore

.gitignore 文件内容为:

public/

然后常规 git 操作:

git add .
git commit -m "ignore public"
git push origin master

自选主题

可以去 Hogo主题网站 git clone 你喜欢的主题到theme文件夹下:

git clone 你喜欢的主题git链接 theme/主题名

进入你的主题文件夹,复制文件夹下的 config.toml 文件内容到你自己的 config.toml文件中,这个时候就可以在本机运行查看自己的博客界面了:

hugo server -w

编辑主题

可以在基础主题的背景下自定义背景图、友情链接等,详细可以去看自己喜欢主题下的 example site 和 config,注意在 Blog 下的 config.tmol 文件下的 aseURL 要改为自己的 username.github.io:

aseURL = "http://username.github.io/"

接下来的步骤请看 PART 2

「真诚赞赏,手留余香」

EagleYing's Blog

真诚赞赏,手留余香

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