5 分鐘使用 hugo 搭建一個本身的博客

Hugo是由Go語言實現的靜態網站生成器。相比hexo更簡單、易用、高效、易擴展、快速部署。git

安裝Hugo

下載二進制

進入github下載地址,選擇對應系統的二進制文件,好比個人電腦windows 64位就下載 hugo_0.55.5_Windows-64bit.zip image.pnggithub

解壓出來就是一個EXE文件,加入到環境變量便可windows

源碼安裝

先安裝go,git,設置GOPATH 命令行執行 go get -u -v github.com/gohugoio/hugo,成功後會生成二進制文件瀏覽器

生成站點

打開命令行,我使用的是cmder,固然自帶的cmd也行。hexo

mkdir blog
cd blog
hugo new site .

目錄結構爲 image.png網站

編寫正文

使用md語法編輯文件ui

hugo new hello.md
vi hello.md

下載主題

cd themes
git clone https://github.com/spf13/hyde.git

運行Hugo

hugo server --theme=hyde --buildDrafts
Building sites …
                   | EN
+------------------+----+
  Pages            | 11
  Paginator pages  |  0
  Non-page files   |  0
  Static files     |  6
  Processed images |  0
  Aliases          |  0
  Sitemaps         |  1
  Cleaned          |  0

Total in 335 ms
Watching for changes in d:\blog\{content,data,layouts,static,themes}
Watching for config changes in d:\blog\config.toml
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop

瀏覽器裏打開: http://localhost:1313 image.png命令行

部署到github

在github創建一個repo,好比username.github.io,注意username爲本身的用戶名,不能爲其餘的。 hugo --theme=hyde --baseUrl="http://xxx.github.io/" 這樣靜態頁面都會生成到 public 目錄,將pubilc目錄裏全部文件 push 到剛建立的Repo的 master 分支就能夠了。code

cd public
 git init
git remote add origin https://github.com/xxx/xxx.github.io.git
 git add .
 git commit -m "hugo"
 git push -u origin master

打開瀏覽器訪問:http://xxx.github.io/server

好了,你的博客搭建成功了,開始你的博客之旅吧。 公衆號:蘇生不惑 掃描二維碼關注

相關文章
相關標籤/搜索