⭐️ 我的博客的建立之路1:hugo 搭建我的博客

第一篇正式博文,我想給你們分享下個人博客的建立過程吧!⭐️git

Hugo 是由 Go 語言實現的靜態網站生成器。簡單、易用、高效、易擴展、快速部署。程序員

安裝 Hugo

  • 官方教程 英文github

  • Mac 安裝方式post

    • brew install hugo網站

    • hugo versionui

  • Windows 安裝方式spa

    • Hugo releases 頁面 下載 hugo_xxx_Windows- 64bit.zip
    • 解壓,把 hugo.exe 放到 D:\Software\hugo\hugo.exe
    • 把 D:\Software\hugo\ 加到 PATH
    • 重啓終端,運行 hugo version 查看版本

快速搭建博客

官方文檔教程,必看!code

準備、提交

  1. 新建 blog 目錄,運行 hugo new site xxx.github.io-generator , xxx 爲 github 用戶名 。會在當前目錄中建立 xxx.github.io-generator 文件夾(博客生成器)server

  2. 進入博客生成器目錄,git initblog

  3. 選擇並下載主題 ,放到 themes 目錄下 git clone https://github.com/dillonzq/LoveIt.git themes/LoveIt

    • 遇到報錯 ↘

      fatal: unable to access 'https://github.com/dillonzq/LoveIt.git/': error setting certificate verify locations:
        CAfile: D:/Software/Git/mingw64/ssl/certs/ca-bundle.crt
        CApath: none
      複製代碼
    • 解決辦法:使用 git clone 出現 fatal: unable to access 'https://github.com/...' ,執行代碼 ​↓

      git config --system http.sslverify false   // 把證書校驗禁用 
      複製代碼
  4. 而後,將主題添加到站點配置中:echo 'theme = "LoveIt"' >> config.toml // 主題目錄的名稱

  5. 建立新文章:hugo new posts/first_post.md

    D:\blog\xxx.github.io-generator\content\posts\first_post.md created

  6. 編輯文章後,修改 draft: false。draft : true 表示處於草稿狀態,此時Hugo不會真正發佈它

  7. 初次建立博客或修改主題,需將主題文檔中給出的配置,粘貼到 config.toml 文件中。

    baseURL 配置成 http://[用戶名].github.io/

  8. hugo server -D 創建本地訪問 https://localhost:1313 預覽博客

  9. hugo 建立一個新的目錄 public/,這就是須要提交到 github,最終生成線上博客的目錄

  10. 根目錄下,新建 .gitignore 文件,添加 /public/。使得 /public 能夠自成一個倉庫

  11. 進入public cd publicgit init git add . git commit

第一次部署

  1. 登陸 github,建立博客專用倉庫,倉庫名必須爲 : [用戶名].github.io
  2. 進入 public 目錄,git remote add origin xxx
  3. git push -u origin master
  4. 進入 github 博客倉庫的 Settings,找到 GitHub Pages ,選擇 master ,保存
  5. 經過 http://[用戶名].github.io 就能訪問博客

之後的部署

  1. 在 xxx.github.io-creator 目錄(注意確保本身不在 public 目錄)裏運行 hugo new posts/第二篇博客.md
  2. 運行 code posts/第二篇博客.md 對文件進行編輯,注意不要把文件本來的內容 front matter 給刪了,直接在後面另起一行寫新內容。
  3. hugo server -D 創建本地訪問 https://localhost:1313 預覽博客
  4. 運行 hugo -D,獲得新的 public 目錄
  5. 進入 public 目錄 cd public,執行一下操做
    1. git add . 注意有一個點
    2. git commit -m update
    3. git push -f 其中 -f 是強制上傳的意思
  6. 等待幾分鐘後,你的博客就會出現第二篇文章了!

備份博客生成器 generator

程序員永遠都會留備份

  • 新建倉庫 xxx.github.io-generator

  • 將本地 xxx.github.io-generator 目錄,git initgit add .git commit -m backupgit remote add origin xxxgit push -u origin master 便可

    • 若是在執行 add 時,提示咱們須要執行 rm 操做,多是由於主題目錄下已經存在 .git 文件,主題目錄自己就是一個本地倉庫了,那和 generator 目錄會造成一個嵌套子目錄的關係,that's not good . 咱們須要把主題目錄下的 .git 文件刪除
相關文章
相關標籤/搜索