使用hugo搭建博客
從https://github.com/gohugoio/hugo/releases 下載
推薦選擇 帶有extend擴展包的安裝包
因爲第一次我沒選擇帶有extend的這個,花了一下午時間找原因
然後解壓後,將文件夾內hugo.exe 的路徑 配置到環境變量
在cmd中 hugo new site E:\GitMyblogRepository 建立自己的博客文件夾
目錄如下
然後cmd中cd到博客的根目錄 hugo new about.md 會在content文件夾中生成一個markdown格式的文件,非必須步驟,只是用來測試
將about.md 中 draft : true 改爲false
配置你的 config.toml 這是我的配置,只是剛開始最簡單的幾個重要的配置
挑選主題
cd themes
git clone https://github.com/alex-shpak/hugo-book.git
完成後,將其文件夾名字改爲 book
本地調試
在項目根目錄下,通過 hugo server 命令可以使用 hugo 內置服務器調試預覽博客。
hugo sever –theme=book –-buildDrafts
如果config.toml 中進行了配置,則 只需要hugo –-buildDrafts
在瀏覽器裏打開: http://localhost:1313 即可訪問到你的博客
部署到Giuhub上
首先在github上建立一個倉庫
如果你需要部署在 GitHub Pages 上,首先在GitHub上創建一個Repository,命名爲:wgwg.github.io (wgwg替換爲你的github用戶名的小寫)
在站點根目錄執行 Hugo 命令生成最終頁面:
hugo --theme=book --buildDrafts --baseUrl=“https://wgwg.github.io
這裏的 --baseUrl 一定是https://(Hugo中文文檔裏爲http://),不然你部署後的博客會沒有樣式!
可看到根目錄下多出 /public文件夾出來,該文件夾的內容即Hugo生成的整個靜態網站
Public就是需要提交到github的網站
在public中 右鍵GUI 選擇當前目錄爲倉庫
在彈出界面中,選擇help-à show SSH key -à 什麼也不點 直接生成SSH key
複製這堆東西
在github中 如下操作 將github與自己的本地的SSHket綁定,以後提交更新時就不需要輸入賬號密碼了
然後再public目錄中,右鍵Git Bash here
使用命令來進行提交
cd public
$ git remote add origin [email protected]:Ohohhh/wgwg.github.io.git
$ git add -A
$ git commit -m “first commit”
$ git push -u origin master
完成!!
然後瀏覽器裏訪問:https://wgwg.github.io/ 即可看到剛剛搭建的博客。
發佈博客:
–新建博客markdown文件,並編輯博客內容(文件名爲 **.md )
hugo new post/newBlog.md
–生成靜態頁面 public
hugo --theme=book --buildDrafts --baseUrl=“https://wgwg.github.io/”
—發佈
cd public
git add .
git commit -m “new blog added”
git push origin master