前言
hugo和hexo一样,是静态网站生成器,特点是基于Go语言编写,部署高效快速。
安装
-
下载对应操作系统版本的Hugo安装包: https://github.com/gohugoio/hugo/releases
-
解压缩或者安装后,将hugo.exe所在文件夹的目录添加到系统环境变量Path下
-
验证Hugo版本
hugo version
生成站点
创建静态站点
# YourSiteName为你新建的站点文件夹名称
$ hugo new site your-site-name
添加Themes
到 https://themes.gohugo.io/ 下载主题并进行安装到themes根目录下
$ cd your-site-name/themes
$ git clone https://github.com/spf13/hyde.git
用下载主题里的your-site-name\themes\your-theme-name\exampleSite\config.toml
配置文件替换根目录下your-site-name\config.toml
文件
设置config.toml里属性theme: "your-theme-name"
生成博客
使用hugo new your-file-name.md
命令生成页面,默认放置在content目录下。因为除了博客的正文外还需要一些about页面,此处采用hugo new post/your-file-name.md
生成博客正文页面,在content目录下生成二级目录/post
---
title: "bolg name" #此篇blog的标题
date: "2017-12-05"
draft: true #false对外可见,true仅对自己可见
tags: ["one"] #tags文档的标签或关键字
categories: ["one"] #categories文档所属分类
---
这个头部配置的信息是和archetypes
里default.md
的格式一样,是可以改成自己想要的格式的
启动服务
$ hugo server
浏览器访问: http://localhost:1313
托管到github
-
这个时候我们可以部署到 Github Pages,只需要在你自己的 github 里面创建一个命名为your-github-name.github.io的仓库。
-
将根目录下config.toml文件中baseURL改为
https://your-github-name.github.io/
-
在站点根目录执行
hugo
命令生成/public
文件夹。public下存放的就是所有静态页面,只需要把public目录里面的文件push
到你的仓库就好
cd public
$ git init
$ git remote add origin https://github.com/your-github-name/your-github-name.github.io.git
$ git add .
$ git commit -m "first commit"
$ git push -u origin master
接下来就可以在浏览器访问: http://your-github-name.github.io/