零基础搭建个人博客(保姆级)

说明(必看)

本教程以64位Windows系统为例,进行演示和说明,提供的安装包也是基于64位Windows的,其他系统除安装步骤不同外,基本相同。如需其他系统方式,需自行搜索。

一、准备阶段-环境的搭建

二、安装

  1. 解压下载下来的hugo_0.72.0_Windows-64bit.zip文件,将其中的hugo.exe文件放到你想要放的地方,比如C:\Hugo\bin。
  2. 将hugo.exe所在路径添加到Windows的环境变量PATH中。具体添加方法可参考Windows 10 如何添加环境变量。
  3. 打开Git Bash或者Cmd或者Power Shell(推荐) 输入 hugo version 回车出现hugo static site generator相关信息表示安装完成。如下:
input > hugo version
output > Hugo Static Site Generator v0.72.0-8A7EF3CF windows/amd64 BuildDate: 2020-05-31T12:08:42Z

三、编写博客

  1. 选择一个心仪的目录,在Git Bash 输入hugo new site “你的文件名字” ,回车便可以生成一个用于存放博客的文件夹,如:myblog。
input > hugo new site myblog
output > Congratulations! Your new Hugo site is created in ......
  1. hugo没有自带主题,所以建立完文件夹后要导入主题文件。可以用git clone 的方式,也可以到相应主题的github中下载zip文件然后解压到自己博客的themes文件夹中。推荐git clone方式
input > git clone https://github.com/xiaoheiAh/hugo-theme-pure themes/pure
output > ......
  1. Hugo配置文件放置在源文件下,并且支持三种格式:toml,yaml,yml。这个配置文件可以直接从主题文件中的exampleSite 里copy到博客文件夹下,然后进行修改。进入themes文件夹,拷贝exampleSite/config.yml文件到myblog目录下,并删除myblog目录下config.toml文件。

  2. 在 Git Bash 中输入 hugo new posts/xxxx.md,这时候就会在文件夹 content/posts形成你要的markdown文件,打开进行编辑即可。

input > hugo new posts/first_blog.md
output > ......
  1. 在Git Bash输入hugo server -D启动,然后打开网址http://localhost:1313/ 查看
input > hugo server -D
output > ......

三、总结

  • 至此,你的博客雏形基本完成,但距离发布还有一段路要走
  • 第一次写教程还是有些摸不清重点,但基本上无坑,所以按照我的说法捋一遍没问题