4.【Git】搭建个人博客

272 阅读1分钟

安装Hugo(Go语言实现的一个博客生成器)

  1. 下载Hugo安装包(hugo_0.69.0_Windows-64bit.zip),下载地址
  2. 解压缩之后,将hugo.exe放入C:\Software\hugo中
  3. 将C:\Software\hugo路径加入环境变量PATH中
  4. 使用命令行hugo version查看是否安装成功

搭建博客,使用Github创建一个个人博客

  1. 进入hugo博客搭建指南
  2. 新建一个目录(HugoBlog),在此目录中运行hugo博客搭建指南中的step2-step7,代码如下
hugo new site unizhoulu.github.io-creator #step2,新建一个博客生成器#

cd unizhoulu.github.io-creator #step3,进入这个生成器目录#
git init 
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke 
echo 'theme = "ananke"' >> config.toml 

hugo new posts/my-first-post.md #step4,创建一篇新文章,打开此md文件,写博文,将draft的值改为false#

hugo server -D #step5#

code config.toml #step6,进入文件(或Ctrl+P搜索“config.toml”),配置主题:en-us改为zh-Hans#

hugo #创建一个新目录“public”#
  1. 在目录“unizhoulu.github.io-creator”下,新建文件.gitignore,将“public”写入其中
  2. 进入public,执行以下命令行
git init
git add .
git commit -v
  1. 在Github上新建一个repo,名字必须为“unizhoulu.github.io”
  2. 在public目录中运行以下命令行
git remote add origin git@github.com:unizhoulu/unizhoulu.github.io.git
git push -u origin master
  1. 个人博客创建成功,地址是:unizhoulu.github.io/
  2. 可以购买域名并配置个性化的博客地址