基于hugo的个人博客
1.安装hugo
-
直接在hugo官方GitHub下载相应版本然后解压
-
Windows需添加软件所在路径到path
-
Mac可直接使用
Homewbrew
下载brew install hugo
Windows使用注意: 之后执行的命令在cmd
或Git bash
均可,git
相关命令只能在Git bash
里执行
2.生成站点
快速生成站点,比如希望生成到当前路径下的myblog
路径
hugo new site myblog
3.创建文章
创建一个about
页面
hugo new about.md
一般都放到post
目录下,方便之后生成聚合页面
hugo new post/about.md
在站点根目录(即myblog
目录)下执行,将生成到myblog/content/
目录下
生成的文件由开头为如下
---
title: "about"
date: 2019-08-14T20:34:19+08:00
draft: true
---
draft
为草稿的意思,将其值改为"false
"
4.安装皮肤
到皮肤列表挑选一个心仪的皮肤,如:polymer ,找到相关的GitHub
地址,到myblog/themes/
目录里把皮肤git clone
下来
cd myblog/themes/
git clone https://github.com/pdevty/polymer.git
polymer的配置:https://themes.gohugo.io/polymer/
5.运行hugo
在站点根目录(即myblog
目录)下执行
hugo server --theme=polymer --buildDrafts
可在https://localhost:1313
访问
6.部署
假设你需要部署在GitHub Pages
上,首先在GitHub上创建一个Repository,命名为:tricenull.github.io
(tricenull替换为你的github用户名)
在站点根目录执行Hugo
命令生成最终页面:
hugo --theme=polymer --baseUrl="https://tricenull.github.io/" --buildDrafts
将会在站点根目录(即myblog
目录)下生成public
目录,将pubilc
目录里所有文件push
到刚创建的Repository
的master
分支
cd public
git init
git remote add origin https://github.com/TRiceNull/tricenull.github.io.git
git add -A
git commit -m "first commit"
git push -u origin master
7.更新博客
在站点根目录myblog
打开Git bash
hugo new new.md
hugo server --theme=polymer --buildDrafts
hugo --theme=polymer --baseUrl="https://tricenull.github.io/" --buildDrafts
cd public
git add -A
git commit -m "first commit"
git push -u origin master
注意: 将new.md
文件中draft
的值改为"false
"