⭐️ 我的博客的建立之路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 文件删除
相关文章
相关标签/搜索