用hugo建立個人博客


### 1. 安裝hugo

*先要配置好go開發(fā)環(huán)境*

```

go get -v github.com/spf13/hugo

go install github.com/spf13/hugo

```

### 2. 生成站點

使用hugo new site 命令生成站點, 如生成到$HOME/workspace/blog目錄:

```

hugo new site $HOME/workspace/blog

```

這樣就在$HOME/workspace/blog目錄下生成啦初始站點, 進入目錄:

```

cd $HOME/workspace/blog

```

站點目錄結(jié)構:

```

# blog文章目錄

content/

layouts/

static/

# hugo站點配置文件

config.toml

```

### 3. 安裝主題

去[themes.gohugo.io](http://themes.gohugo.io/)選一個喜歡的主題,并下載下來

exampleSite 是主題的一個示例站點,里面有配置文件、關于頁面的一些示例。

```

#創(chuàng)建themes目錄

mkdir themes

#下載主題cactus-plus

cd themes

git clone https://github.com/nodejh/hugo-theme-cactus-plus.git

#移除.git, 避免和站點項目的.git沖突,

#當然也可以使用submodule形式組織

rm -rf .git

#將示例模板放到站點根目錄

mv exampleSite/* ../

# 回到站點根目錄

cd ..

```

### 4. 主題配置

替換$HOME/workspace/blog/themes/cactus-plus/static/images目錄下的圖片.

修改站點標題:

> 打開 config.toml 文件

> 修改 baseURL 字段為https://YourUsername.github.io形式, 或者你的域名, 用于生成CNAME

> 修改 title="xxx" 字段

> 修改 [params] 的 name,description,bio(像是個性簽名) 等字段

### 5. 使用git來管理文章

Git是一款免費、開源的分布式版本控制系統(tǒng),用于敏捷高效地處理任何或小或大的項目。

#### 5.1 初始化本地倉庫

```

#hugo默認生成站點到public目錄, 我們不需要保留它

echo "public" >> .gitignore

echo "User-agent: *\nDisallow:" > static/robots.txt

git init

git commit -a -m "Initial commit"

```

#### 5.2 關聯(lián)遠程倉庫(github)

注冊并登錄github, create repository

```

git remote add origin git@github.com:YourUsername/yourblog.git

git push -u origin master

```

### 6. 添加文章

```

#添加文章到content/post目錄下

hugo new post/first.md

#編輯文章, 添加到倉庫并提交

git add content

git commit -m "added first.md"

git push

```

### 7. 運行本地站點

hugo會監(jiān)測文件的變動, 我們可以用瀏覽器訪問 http://localhost:1313 ,實時查看文章變動.

``` shell

hugo server --theme=cactus-plus --buildDrafts

```

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容