第一步:安装hugo

  • 安装包如下

https://github.com/gohugoio/hugo/releasesgithub.com

  • Mac安装方式

    1. brew install hugo
    2. hugo version
  • Windows安装方式

  1. 去hugo releases 页面下载安装包
  2. 解压把hugo.exe放到D\software\hugo\hugo.exe
  3. D\software\hugo\加到path
  4. 重启终端,运行hugo version查看版本

    第二步:快速搭建博客

  • 安装hugo之后进入Hugo官网(地址如下),点击 Quick Start 快速开始

Hugo官网gohugo.io

  • 从Step2开始到Step7

Step 2: Create a New Site 建立新网站(xxx为GitHub用户名)

  1. hugo new site quickstart 最后quickstart改为仓库名加个尾缀xxx.gitgub.io-generator或-creator

Step 3:Add a Theme 添加主题

  1. cd xxx.gitgub.io-creator
  2. git init
  3. git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
  4. echo 'theme = "ananke"' >> config.toml (将主题添加到站点配置中)

Step 4: Add Some Content 添加一些内容

  1. hugo new posts/my-first-post.md

code . 即进入VSCode
文件在content里

  1. title: "开博大吉"
  2. date: 2020-06-04T13:07:17+08:00
  3. draft: true

将ture改为false即不是草稿,另外注意不要删除文件里原本这三段文字,内容直接后面加即可
Step 5:Start the Hugo server 启动Hugo服务器

  1. hugo server -D

Step 6:Customize the Theme 自定义主题
在VSCode里ctrl+p 搜索 config.toml

  1. baseURL = "http://example.org/" (地址改成GitHub Pages显示的网址)
  2. languageCode = "en-us" (改成zh-Hanss是简体的意思,即中文简体
  3. title = "My New Hugo Site" (标题,比如xx的博客)
  4. theme = "ananke"

Step 7: Build static pages 建立静态页面

  1. hugo -D

第三步:public文件自成一个仓库

  • 新建文件.gitignore将/public/添加

    1. cd public
    2. git init
    3. git add .
    4. git commit -v

    新建github repo 名字为http://alertguo.github.io
    将public上传(记住用ssh)
    进入github的http://alertguo.github.io仓库settings
    GitHub Pages 里有地址

    补充:在博客里插入图片

    方法1
    1. 打开 sm.ms 网站,将图片上传上去,得到图片的 url。
    2. 在文章里使用 如何用 hugo 搭建个人博客 - 图1 语法即可显示图片
    方法2
    1. 将图片文件 1.png 存放到 static 目录里,得到 static/1.png
    2. 在博客 Markdown 里写 如何用 hugo 搭建个人博客 - 图2 就能看到 static/1.png 对应的图片了
    3. 如果你想在 static 里创建 images 目录,直接创建就好,对应的图片前面加上 /images 即可,比如
    1. 将图片文件 2.png 放到 static/images 目录里,得到 static/images/2.png
    2. 在博客里写 如何用 hugo 搭建个人博客 - 图3即可

  • 最关键的,一定要备份文件

四连操作

  1. git add .
  2. git commit -v
  3. git remote add origin git@xxxxxx
  4. git push -u origin master

hugo如何创建第二篇博客

  1. 在 xxx.github.io-creator 目录(注意确保自己不在 public 目录)里运行 hugo new posts/第二篇博客.md
  2. 运行 code posts/第二篇博客.md 对文件进行编辑,注意不要把文件原本的内容给删了,直接在后面另起一行写新内容。
  3. 运行 hugo -D,得到新的 public 目录
  4. 进入 public 目录,执行一下操作
    1. git add . 注意有一个点
    2. git commit -m update
    3. git push -f 其中 -f 是强制上传的意思
  5. 等待几分钟后,你的博客就会出现第二篇文章了!

不忘初心 方得始终