第一步:安装hugo
- 安装包如下
https://github.com/gohugoio/hugo/releasesgithub.com
Mac安装方式
brew install hugohugo version
Windows安装方式
- 去hugo releases 页面下载安装包
- 解压把hugo.exe放到D\software\hugo\hugo.exe
- D\software\hugo\加到path
- 重启终端,运行hugo version查看版本
第二步:快速搭建博客
- 安装hugo之后进入Hugo官网(地址如下),点击 Quick Start 快速开始
- 从Step2开始到Step7
Step 2: Create a New Site 建立新网站(xxx为GitHub用户名)
hugo new site quickstart 最后quickstart改为仓库名加个尾缀xxx.gitgub.io-generator或-creator
Step 3:Add a Theme 添加主题
cd xxx.gitgub.io-creatorgit initgit submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/anankeecho 'theme = "ananke"' >> config.toml (将主题添加到站点配置中)
Step 4: Add Some Content 添加一些内容
hugo new posts/my-first-post.md
code . 即进入VSCode
文件在content里
title: "开博大吉"date: 2020-06-04T13:07:17+08:00draft: true
将ture改为false即不是草稿,另外注意不要删除文件里原本这三段文字,内容直接后面加即可
Step 5:Start the Hugo server 启动Hugo服务器
hugo server -D
Step 6:Customize the Theme 自定义主题
在VSCode里ctrl+p 搜索 config.toml
baseURL = "http://example.org/" (地址改成GitHub Pages显示的网址)languageCode = "en-us" (改成zh-Hans)s是简体的意思,即中文简体title = "My New Hugo Site" (标题,比如xx的博客)theme = "ananke"
Step 7: Build static pages 建立静态页面
hugo -D
第三步:public文件自成一个仓库
新建文件.gitignore将/public/添加
cd publicgit initgit add .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. 在文章里使用语法即可显示图片
方法2
1. 将图片文件 1.png 存放到 static 目录里,得到 static/1.png
2. 在博客 Markdown 里写
就能看到 static/1.png 对应的图片了
3. 如果你想在 static 里创建 images 目录,直接创建就好,对应的图片前面加上 /images 即可,比如
1. 将图片文件 2.png 放到 static/images 目录里,得到 static/images/2.png
2. 在博客里写
即可最关键的,一定要备份文件
四连操作
git add .git commit -vgit remote add origin git@xxxxxxgit push -u origin master
hugo如何创建第二篇博客
- 在 xxx.github.io-creator 目录(注意确保自己不在 public 目录)里运行 hugo new posts/第二篇博客.md
- 运行 code posts/第二篇博客.md 对文件进行编辑,注意不要把文件原本的内容给删了,直接在后面另起一行写新内容。
- 运行 hugo -D,得到新的 public 目录
- 进入 public 目录,执行一下操作
- git add . 注意有一个点
- git commit -m update
- git push -f 其中 -f 是强制上传的意思
- 等待几分钟后,你的博客就会出现第二篇文章了!
不忘初心 方得始终
